Assetic + YUI Compressor in symfony 2: is this a bug? Assetic + YUI Compressor in symfony 2: is this a bug? symfony symfony

Assetic + YUI Compressor in symfony 2: is this a bug?


I have the same problem... (the problem seems present only on windows)The only way I found, is really dirty :

1 - Specify the java executable path in config file (at the same place of the yui jar declaration path)

yui_css:    jar: "%kernel.root_dir%\\Resources\\java\\yuicompressor.jar"    java: "C:\\Program Files\\Java\\jre6\\bin\\java.exe"

2 - Open the Assetic\Util\Process.php fileChange the "proc_open" line (line 123 my version) in "run" methodOriginal line :

$process = proc_open($this->commandline, $descriptors, $pipes, $this->cwd, $this->env, $this->options);

Modified line :

$process = proc_open('"'.$this->commandline.'"', $descriptors, $pipes, $this->cwd, $this->env, $this->options);

And it's works... but is not a real solution...

If someone has more info... thanks :)


If you're using the latest stable version (1.0.2), then it has a bug that prevents it from correctly using YUI compressor on Windows.As @Pierre has pointed out, the problem lies in the way the proc_open function is called, but the fix should be applied elsewhere.

If you have a look at Assetic\Util\ProcessBuilder class you'll find the culprit on line 95:

#95 if (defined('PHP_WINDOWS_MAJOR_VERSION')) {

There's no such constant in PHP as PHP_WINDOWS_MAJOR_VERSION ( http://php.net/manual/en/info.constants.php ), which makes the if statement test evaluate to false. What should be used instead is PHP_WINDOWS_VERSION_MAJOR.

The second issue I found in this class is a couple of lines below:

#102 if ($args) {#103   $script .= ' '.implode(' ', array_map('escapeshellarg', $parts));#104 }

$parts is not defined in this scope and should be replaced with $args.

As I found out later, both issues have been fixed on 16.09 in this commit: https://github.com/kriswallsmith/assetic/commit/cc2e9adb744df0704a5357adc1cf9287c427420fbut the code hasn't been tagged yet.

Hope this helps.


YUI compressor needs to be define in your app/config/config.yml like that :

assetic:    debug:          %kernel.debug%    use_controller: false    filters:        cssrewrite: ~        yui_css:            jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar

Of course, you need to download the YUI compressor and copy it in your /app/Resources/java/ directory.

Warning, the assetic bundle doesn't publish your compress CSS automaticly, you need to publish them manually with the following command:

php app/console assetic:dump