How to install lessphp to be used in the assetic framework?

1k views Asked by At

I cannot find a way to add the lessphp files to my project so that assetic finds them. I do not wish to add extra require sentences to the assetic files or modify them in any way so future updates are easily made.

I get this error:

Fatal error: Class 'lessc' not found in ....../kriswallsmith/assetic/src/Assetic/Filter/LessphpFilter.php on line 87

The code on that line is the lessc intantiation:

  $lc = new \lessc();

Note: I cannot use Composer to install it since Composer brings some issues to my project.

1

There are 1 answers

1
joksnet On BEST ANSWER

Assetic will not import lessc.inc.php for you. You have to do it manually.

I assume you are using Assetic standalone in your application, you should be doing something like this:

<?php

use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Filter\LessphpFilter;

require "path/to/lessc.inc.php"; // You should include it yourself

$css = new AssetCollection(array(
    new FileAsset('/path/to/src/styles.less', array(new LessphpFilter())),
));
echo $css->dump();

But for that causalities that you are using Symfony2, you should configure lessphp filter in your app/config/config.yml like this:

assetic:
    debug:          %kernel.debug%
    use_controller: false
    bundles:        []
    filters:
       cssrewrite: ~
       lessphp:
           file: "%kernel.root_dir%/../vendor/leafo/lessphp/lessc.inc.php"
           apply_to: "\.less$"

Let me know.