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; }
/** * Compile Less_Tree_Mixin_Call objects * * @param Less_Tree_Ruleset $ruleset * @param integer $rsRuleCnt */ private function EvalMixinCalls($ruleset, $env, &$rsRuleCnt) { for ($i = 0; $i < $rsRuleCnt; $i++) { $rule = $ruleset->rules[$i]; if ($rule instanceof Less_Tree_Mixin_Call) { $rule = $rule->compile($env); $temp = array(); foreach ($rule as $r) { if ($r instanceof Less_Tree_Rule && $r->variable) { // do not pollute the scope if the variable is // already there. consider returning false here // but we need a way to "return" variable from mixins if (!$ruleset->variable($r->name)) { $temp[] = $r; } } else { $temp[] = $r; } } $temp_count = count($temp) - 1; array_splice($ruleset->rules, $i, 1, $temp); $rsRuleCnt += $temp_count; $i += $temp_count; $ruleset->resetCache(); } elseif ($rule instanceof Less_Tree_RulesetCall) { $rule = $rule->compile($env); $rules = array(); foreach ($rule->rules as $r) { if ($r instanceof Less_Tree_Rule && $r->variable) { continue; } $rules[] = $r; } array_splice($ruleset->rules, $i, 1, $rules); $temp_count = count($rules); $rsRuleCnt += $temp_count - 1; $i += $temp_count - 1; $ruleset->resetCache(); } } }