public function compileParams($env, $mixinFrames, $args = array(), &$evaldArguments = array())
 {
     $frame = new Less_Tree_Ruleset(null, array());
     $params = $this->params;
     $mixinEnv = null;
     $argsLength = 0;
     if ($args) {
         $argsLength = count($args);
         for ($i = 0; $i < $argsLength; $i++) {
             $arg = $args[$i];
             if ($arg && $arg['name']) {
                 $isNamedFound = false;
                 foreach ($params as $j => $param) {
                     if (!isset($evaldArguments[$j]) && $arg['name'] === $params[$j]['name']) {
                         $evaldArguments[$j] = $arg['value']->compile($env);
                         array_unshift($frame->rules, new Less_Tree_Rule($arg['name'], $arg['value']->compile($env)));
                         $isNamedFound = true;
                         break;
                     }
                 }
                 if ($isNamedFound) {
                     array_splice($args, $i, 1);
                     $i--;
                     $argsLength--;
                     continue;
                 } else {
                     throw new Less_Exception_Compiler("Named argument for " . $this->name . ' ' . $args[$i]['name'] . ' not found');
                 }
             }
         }
     }
     $argIndex = 0;
     foreach ($params as $i => $param) {
         if (isset($evaldArguments[$i])) {
             continue;
         }
         $arg = null;
         if (isset($args[$argIndex])) {
             $arg = $args[$argIndex];
         }
         if (isset($param['name']) && $param['name']) {
             if (isset($param['variadic'])) {
                 $varargs = array();
                 for ($j = $argIndex; $j < $argsLength; $j++) {
                     $varargs[] = $args[$j]['value']->compile($env);
                 }
                 $expression = new Less_Tree_Expression($varargs);
                 array_unshift($frame->rules, new Less_Tree_Rule($param['name'], $expression->compile($env)));
             } else {
                 $val = $arg && $arg['value'] ? $arg['value'] : false;
                 if ($val) {
                     $val = $val->compile($env);
                 } else {
                     if (isset($param['value'])) {
                         if (!$mixinEnv) {
                             $mixinEnv = new Less_Environment();
                             $mixinEnv->frames = array_merge(array($frame), $mixinFrames);
                         }
                         $val = $param['value']->compile($mixinEnv);
                         $frame->resetCache();
                     } else {
                         throw new Less_Exception_Compiler("Wrong number of arguments for " . $this->name . " (" . $argsLength . ' for ' . $this->arity . ")");
                     }
                 }
                 array_unshift($frame->rules, new Less_Tree_Rule($param['name'], $val));
                 $evaldArguments[$i] = $val;
             }
         }
         if (isset($param['variadic']) && $args) {
             for ($j = $argIndex; $j < $argsLength; $j++) {
                 $evaldArguments[$j] = $args[$j]['value']->compile($env);
             }
         }
         $argIndex++;
     }
     ksort($evaldArguments);
     $evaldArguments = array_values($evaldArguments);
     return $frame;
 }
 public function evalCall($env, $args = NULL, $important = NULL)
 {
     Less_Environment::$mixin_stack++;
     $_arguments = array();
     if ($this->frames) {
         $mixinFrames = array_merge($this->frames, $env->frames);
     } else {
         $mixinFrames = $env->frames;
     }
     $frame = $this->compileParams($env, $mixinFrames, $args, $_arguments);
     $ex = new Less_Tree_Expression($_arguments);
     array_unshift($frame->rules, new Less_Tree_Rule('@arguments', $ex->compile($env)));
     $ruleset = new Less_Tree_Ruleset(null, $this->rules);
     $ruleset->originalRuleset = $this->ruleset_id;
     $ruleSetEnv = new Less_Environment();
     $ruleSetEnv->frames = array_merge(array($this, $frame), $mixinFrames);
     $ruleset = $ruleset->compile($ruleSetEnv);
     if ($important) {
         $ruleset = $ruleset->makeImportant();
     }
     Less_Environment::$mixin_stack--;
     return $ruleset;
 }
Esempio n. 3
0
 public function compile($env, $args = NULL, $important = NULL)
 {
     $_arguments = array();
     $mixinFrames = array_merge($this->frames, $env->frames);
     $mixinEnv = new Less_Environment();
     $mixinEnv->addFrames($mixinFrames);
     $frame = $this->compileParams($env, $mixinEnv, $args, $_arguments);
     $ex = new Less_Tree_Expression($_arguments);
     array_unshift($frame->rules, new Less_Tree_Rule('@arguments', $ex->compile($env)));
     $rules = $important ? Less_Tree_Ruleset::makeImportant($this->selectors, $this->rules)->rules : array_slice($this->rules, 0);
     $ruleset = new Less_Tree_Ruleset(null, $rules);
     // duplicate the environment, adding new frames.
     $ruleSetEnv = new Less_Environment();
     $ruleSetEnv->addFrame($this);
     $ruleSetEnv->addFrame($frame);
     $ruleSetEnv->addFrames($mixinFrames);
     $ruleSetEnv->compress = $env->compress;
     $ruleset = $ruleset->compile($ruleSetEnv);
     $ruleset->originalRuleset = $this;
     return $ruleset;
 }