Assetic\Filter\Yui\BaseCompressorFilter::compress PHP Method

compress() protected method

Compresses a string.
protected compress ( string $content, string $type, array $options = [] ) : string
$content string The content to compress
$type string The type of content, either "js" or "css"
$options array An indexed array of additional options
return string The compressed content
    protected function compress($content, $type, $options = array())
    {
        $pb = new ProcessBuilder();
        $pb
            ->inheritEnvironmentVariables()
            ->add($this->javaPath)
            ->add('-jar')
            ->add($this->jarPath)
            ->add('--type')
            ->add($type)
        ;

        foreach ($options as $option) {
            $pb->add($option);
        }

        if (null !== $this->charset) {
            $pb->add('--charset')->add($this->charset);
        }

        if (null !== $this->lineBreak) {
            $pb->add('--line-break')->add($this->lineBreak);
        }

        $input = tempnam(sys_get_temp_dir(), 'assetic_yui_compressor');
        file_put_contents($input, $content);
        $pb->add($input);

        $proc = $pb->getProcess();
        $code = $proc->run();
        unlink($input);

        if (0 < $code) {
            throw new \RuntimeException($proc->getErrorOutput());
        }

        return $proc->getOutput();
    }