[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 4 /** 5 * Call 6 * 7 * @package Less 8 * @subpackage tree 9 */ 10 class Less_Tree_Call extends Less_Tree{ 11 public $value; 12 13 protected $name; 14 protected $args; 15 protected $index; 16 protected $currentFileInfo; 17 public $type = 'Call'; 18 19 public function __construct($name, $args, $index, $currentFileInfo = null ){ 20 $this->name = $name; 21 $this->args = $args; 22 $this->index = $index; 23 $this->currentFileInfo = $currentFileInfo; 24 } 25 26 public function accept( $visitor ){ 27 $this->args = $visitor->visitArray( $this->args ); 28 } 29 30 // 31 // When evaluating a function call, 32 // we either find the function in `tree.functions` [1], 33 // in which case we call it, passing the evaluated arguments, 34 // or we simply print it out as it appeared originally [2]. 35 // 36 // The *functions.js* file contains the built-in functions. 37 // 38 // The reason why we evaluate the arguments, is in the case where 39 // we try to pass a variable to a function, like: `saturate(@color)`. 40 // The function should receive the value, not the variable. 41 // 42 public function compile($env=null){ 43 $args = array(); 44 foreach($this->args as $a){ 45 $args[] = $a->compile($env); 46 } 47 48 $nameLC = strtolower($this->name); 49 switch($nameLC){ 50 case '%': 51 $nameLC = '_percent'; 52 break; 53 54 case 'get-unit': 55 $nameLC = 'getunit'; 56 break; 57 58 case 'data-uri': 59 $nameLC = 'datauri'; 60 break; 61 62 case 'svg-gradient': 63 $nameLC = 'svggradient'; 64 break; 65 } 66 67 $result = null; 68 if( $nameLC === 'default' ){ 69 $result = Less_Tree_DefaultFunc::compile(); 70 71 }else{ 72 73 if( method_exists('Less_Functions',$nameLC) ){ // 1. 74 try { 75 76 $func = new Less_Functions($env, $this->currentFileInfo); 77 $result = call_user_func_array( array($func,$nameLC),$args); 78 79 } catch (Exception $e) { 80 throw new Less_Exception_Compiler('error evaluating function `' . $this->name . '` '.$e->getMessage().' index: '. $this->index); 81 } 82 } elseif( isset( $env->functions[$nameLC] ) && is_callable( $env->functions[$nameLC] ) ) { 83 try { 84 $result = call_user_func_array( $env->functions[$nameLC], $args ); 85 } catch (Exception $e) { 86 throw new Less_Exception_Compiler('error evaluating function `' . $this->name . '` '.$e->getMessage().' index: '. $this->index); 87 } 88 } 89 } 90 91 if( $result !== null ){ 92 return $result; 93 } 94 95 96 return new Less_Tree_Call( $this->name, $args, $this->index, $this->currentFileInfo ); 97 } 98 99 /** 100 * @see Less_Tree::genCSS 101 */ 102 public function genCSS( $output ){ 103 104 $output->add( $this->name . '(', $this->currentFileInfo, $this->index ); 105 $args_len = count($this->args); 106 for($i = 0; $i < $args_len; $i++ ){ 107 $this->args[$i]->genCSS( $output ); 108 if( $i + 1 < $args_len ){ 109 $output->add( ', ' ); 110 } 111 } 112 113 $output->add( ')' ); 114 } 115 116 117 //public function toCSS(){ 118 // return $this->compile()->toCSS(); 119 //} 120 121 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |