engine.less_php.inc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Class \LessEngineLess_php
  4. */
  5. class LessEngineLess_php extends LessEngine {
  6. /**
  7. * @var \Less_Parser
  8. */
  9. private $less_php_parser;
  10. /**
  11. * Instantiates new instances of \Less_Parser.
  12. *
  13. * @param string $input_file_path
  14. *
  15. * @see \Less_Parser
  16. */
  17. public function __construct($input_file_path) {
  18. parent::__construct($input_file_path);
  19. $this->less_php_parser = new Less_Parser();
  20. }
  21. /**
  22. * {@inheritdoc}
  23. * This compiles using engine specific function calls.
  24. */
  25. public function compile() {
  26. $compiled_styles = NULL;
  27. try {
  28. if ($this->source_maps_enabled) {
  29. $this->less_php_parser->SetOption('sourceMap', $this->source_maps_enabled);
  30. $this->less_php_parser->SetOption('sourceMapBasepath', $this->source_maps_base_path);
  31. $this->less_php_parser->SetOption('sourceMapRootpath', $this->source_maps_root_path);
  32. }
  33. // Less.js does not allow path aliasing. Set aliases to blank for consistency.
  34. $this->less_php_parser->SetImportDirs(array_fill_keys($this->import_directories, ''));
  35. $this->less_php_parser->parseFile($this->input_file_path);
  36. $this->less_php_parser->ModifyVars($this->variables);
  37. $compiled_styles = $this->less_php_parser->getCss();
  38. $this->dependencies = $this->less_php_parser->AllParsedFiles();
  39. }
  40. catch (Exception $e) {
  41. throw $e;
  42. }
  43. return $compiled_styles;
  44. }
  45. }