LessphpFilter.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2011 OpenSky Project Inc
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Assetic\Filter;
  11. use Assetic\Asset\AssetInterface;
  12. /**
  13. * Loads LESS files using the PHP implementation of less, lessphp.
  14. *
  15. * Less files are mostly compatible, but there are slight differences.
  16. *
  17. * To use this, you need to clone https://github.com/leafo/lessphp and make
  18. * sure to either include lessphp.inc.php or tell your autoloader that's where
  19. * lessc is located.
  20. *
  21. * @link http://leafo.net/lessphp/
  22. *
  23. * @author David Buchmann <david@liip.ch>
  24. * @author Kris Wallsmith <kris.wallsmith@gmail.com>
  25. */
  26. class LessphpFilter implements FilterInterface
  27. {
  28. public function filterLoad(AssetInterface $asset)
  29. {
  30. $root = $asset->getSourceRoot();
  31. $path = $asset->getSourcePath();
  32. $lc = new \lessc();
  33. if ($root && $path) {
  34. $lc->importDir = dirname($root.'/'.$path);
  35. }
  36. $asset->setContent($lc->parse($asset->getContent()));
  37. }
  38. public function filterDump(AssetInterface $asset)
  39. {
  40. }
  41. }