src/Knp/Snappy/AbstractGenerator.php
protected function buildCommand($binary, $input, $output, array $options = [])
    {
        $command = $binary;
        $escapedBinary = escapeshellarg($binary);
        if (is_executable($escapedBinary)) {
            $command = $escapedBinary;
        }

        foreach ($options as $key => $option) {
            if (null !== $option && false !== $option) {
                if (true === $option) {
                    // Dont't put '--' if option is 'toc'.
                    if ($key == 'toc') {
                        $command .= ' ' . $key;
                    } else {
                        $command .= ' --' . $key;
                    }
                } elseif (is_array($option)) {
                    if ($this->isAssociativeArray($option)) {
                        foreach ($option as $k => $v) {
                            $command .= ' --' . $key . ' ' . escapeshellarg($k) . ' ' . escapeshellarg($v);
                        }
                    } else {
                        foreach ($option as $v) {
                            $command .= ' --' . $key . ' ' . escapeshellarg($v);
                        }
                    }
                } else {
                    // Dont't add '--' if option is "cover"  or "toc".
                    if (in_array($key, ['toc', 'cover'])) {
                        $command .= ' ' . $key . ' ' . escapeshellarg($option);
                    } elseif (in_array($key, ['image-dpi', 'image-quality'])) {
                        $command .= ' --' . $key . ' ' . (int) $option;
                    } else {
                        $command .= ' --' . $key . ' ' . escapeshellarg($option);
                    }
                }
            }
        }

        if (is_array($input)) {
            foreach ($input as $i) {
                $command .= ' ' . escapeshellarg($i) . ' ';
            }
            $command .= escapeshellarg($output);
        } else {
            $command .= ' ' . escapeshellarg($input) . ' ' . escapeshellarg($output);
        }

        return $command;
    }
protected function buildCommand($binary, $input, $output, array $options = [])
    {
        $command = $binary;
        $escapedBinary = escapeshellarg($binary);
        if (is_executable($escapedBinary)) {
            $command = $escapedBinary;
        }

        foreach ($options as $key => $option) {
            if (null !== $option && false !== $option) {
                if (true === $option) {
                    // Dont't put '--' if option is 'toc'.
                    if ($key == 'toc') {
                        $command .= ' ' . $key;
                    } else {
                        $command .= ' --' . $key;
                    }
                } elseif (is_array($option)) {
                    if ($this->isAssociativeArray($option)) {
                        foreach ($option as $k => $v) {
                            $command .= ' --' . $key . ' ' . escapeshellarg($k) . ' ' . escapeshellarg($v);
                        }
                    } else {
                        foreach ($option as $v) {
                            $command .= ' --' . $key . ' ' . escapeshellarg($v);
                        }
                    }
                } else {
                    // Dont't add '--' if option is "cover"  or "toc".
                    if (in_array($key, ['toc', 'cover'])) {
                        $command .= ' ' . $key . ' ' . escapeshellarg($option);
                    } elseif (in_array($key, ['image-dpi', 'image-quality'])) {
                        $command .= ' --' . $key . ' ' . (int) $option;
                    } else {
                        $command .= ' --' . $key . ' ' . escapeshellarg($option);
                    }
                }
            }
        }

        if (is_array($input)) {
            foreach ($input as $i) {
                $command .= ' ' . escapeshellarg($i) . ' ';
            }
            $command .= escapeshellarg($output);
        } else {
            $command .= ' ' . escapeshellarg($input) . ' ' . escapeshellarg($output);
        }

        return $command;
    }
protected function buildCommand ( $ binary , $ input , $ output , array $ options = [ ] ) { $ command = $ binary ; $ escapedBinary = escapeshellarg ( $ binary ) ; if ( is_executable ( $ escapedBinary ) ) { $ command = $ escapedBinary ; } foreach ( $ options as $ key => $ option ) { if ( null !== $ option && false !== $ option ) { if ( true === $ option ) { // Dont't put '--' if option is 'toc'. if ( $ key == 'toc' ) { $ command .= ' ' . $ key ; } else { $ command .= ' --' . $ key ; } } elseif ( is_array ( $ option ) ) { if ( $ this -> isAssociativeArray ( $ option ) ) { foreach ( $ option as $ k => $ v ) { $ command .= ' --' . $ key . ' ' . escapeshellarg ( $ k ) . ' ' . escapeshellarg ( $ v ) ; } } else { foreach ( $ option as $ v ) { $ command .= ' --' . $ key . ' ' . escapeshellarg ( $ v ) ; } } } else { // Dont't add '--' if option is "cover"  or "toc". if ( in_array ( $ key , [ 'toc' , 'cover' ] ) ) { $ command .= ' ' . $ key . ' ' . escapeshellarg ( $ option ) ; } elseif ( in_array ( $ key , [ 'image-dpi' , 'image-quality' ] ) ) { $ command .= ' --' . $ key . ' ' . ( int ) $ option ; } else { $ command .= ' --' . $ key . ' ' . escapeshellarg ( $ option ) ; } } } } if ( is_array ( $ input ) ) { foreach ( $ input as $ i ) { $ command .= ' ' . escapeshellarg ( $ i ) . ' ' ; } $ command .= escapeshellarg ( $ output ) ; } else { $ command .= ' ' . escapeshellarg ( $ input ) . ' ' . escapeshellarg ( $ output ) ; } return $ command ; }
Builds the command string.

@param string       $binary  The binary path/name
@param string/array $input   Url(s) or file location(s) of the page(s) to process
@param string       $output  File location to the image-to-be
@param array        $options An array of options

@return string
Builds the command string .