PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/demo/protected/extensions/less/lib/lessphp/lib/Less/Node/Call.php

https://bitbucket.org/somethingkindawierd/yii-bootstrap
PHP | 57 lines | 32 code | 10 blank | 15 comment | 3 complexity | dde3987cb09b4ad25bc1ef130c380484 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, Apache-2.0, BSD-3-Clause, GPL-3.0
  1. <?php
  2. namespace Less\Node;
  3. //
  4. // A function call node.
  5. //
  6. class Call
  7. {
  8. private $value;
  9. public function __construct($name, $args, $index)
  10. {
  11. $this->name = $name;
  12. $this->args = $args;
  13. $this->index = $index;
  14. }
  15. //
  16. // When evaluating a function call,
  17. // we either find the function in `tree.functions` [1],
  18. // in which case we call it, passing the evaluated arguments,
  19. // or we simply print it out as it appeared originally [2].
  20. //
  21. // The *functions.js* file contains the built-in functions.
  22. //
  23. // The reason why we evaluate the arguments, is in the case where
  24. // we try to pass a variable to a function, like: `saturate(@color)`.
  25. // The function should receive the value, not the variable.
  26. //
  27. public function compile($env)
  28. {
  29. $args = array_map(function ($a) use($env) {
  30. return $a->compile($env);
  31. }, $this->args);
  32. $name = $this->name == '%' ? '_percent' : $this->name;
  33. if (method_exists($env, $name)) { // 1.
  34. try {
  35. return call_user_func_array(array($env, $name), $args);
  36. } catch (Exception $e) {
  37. throw \Less\FunctionCallError("error evaluating function `" . $this->name . "`", $this->index);
  38. }
  39. } else { // 2.
  40. return new \Less\Node\Anonymous($this->name .
  41. "(" . implode(', ', array_map(function ($a) use ($env) { return $a->toCSS($env); }, $args)) . ")");
  42. }
  43. }
  44. public function toCSS ($env) {
  45. return $this->compile($env)->toCSS();
  46. }
  47. }