Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have tested the YUI compressor in the command line (on windows) and it seems to work just fine.

But the .css created by assetic is not compressed, and comes with this message on the top (inside the .css!):

/*
[exception] 500 | Internal Server Error | RuntimeException
[message] 
[1] RuntimeException: 
            at n/a
                in E:\websites\symfony2\public_html\Symfony\vendor\assetic\src\Assetic\Filter\Yui\BaseCompressorFilter.php line 81

            at Assetic\Filter\Yui\BaseCompressorFilter->compress('

Is this a configuration problem? Or a bug in assetic?

Here's the code I used inside my twig template:

{% stylesheets '@CompanyBundlenameBundle/Resources/public/css/style.css' filter='yui_css' %}
<link rel="stylesheet" type="text/css" media="screen" href="{{ asset_url }}" />
{% endstylesheets %}
like image 603
HappyDeveloper Avatar asked Jul 01 '11 23:07

HappyDeveloper


4 Answers

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 file Change the "proc_open" line (line 123 my version) in "run" method Original 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 :)

like image 136
Pierre Avatar answered Nov 19 '22 03:11

Pierre


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/cc2e9adb744df0704a5357adc1cf9287c427420f but the code hasn't been tagged yet.

Hope this helps.

like image 39
Jan Molak Avatar answered Nov 19 '22 02:11

Jan Molak


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 
like image 36
egeloen Avatar answered Nov 19 '22 03:11

egeloen


I just got this same problem.

What i did to solve:

  • Open the "deps" file.
  • Remove the line "version=v1.0.0RC1" in "[AsseticBundle]" section.
  • Run "bin/vendors update" command to get the latest version of AsseticBundle.

Hope this helps.

like image 3
fernanDOTdo Avatar answered Nov 19 '22 03:11

fernanDOTdo