/** * Evaluates the function. * Look for a user defined function first - this allows users to override * pre-defined functions, then try the pre-defined functions. * @return Function the value of this Function */ public function perform() { self::$context = new SassContext(SassScriptParser::$context); $name = preg_replace('/[^a-z0-9_]/', '_', strtolower($this->name)); $args = $this->process_arguments($this->args); foreach ($this->args as $k => $v) { if (!is_numeric($k)) { self::$context->setVariable($k, $v); } } try { if (SassScriptParser::$context->hasFunction($this->name)) { $return = SassScriptParser::$context->getFunction($this->name)->execute(SassScriptParser::$context, $this->args); return $return; } else { if (SassScriptParser::$context->hasFunction($name)) { $return = SassScriptParser::$context->getFunction($name)->execute(SassScriptParser::$context, $this->args); return $return; } } } catch (Exception $e) { throw $e; } if (isset(SassParser::$functions) && count(SassParser::$functions)) { foreach (SassParser::$functions as $fn => $callback) { if (($fn == $name || $fn == $this->name) && is_callable($callback)) { $result = call_user_func_array($callback, $args); if (!is_object($result)) { $lexed = SassScriptLexer::$instance->lex($result, self::$context); if (count($lexed) === 1) { return $lexed[0]; } return new SassString(implode('', $this->process_arguments($lexed))); } return $result; } } } if (method_exists('SassScriptFunctions', $name) || method_exists('SassScriptFunctions', $name = '_' . $name)) { $sig = self::get_reflection(array('SassScriptFunctions', $name)); list($args) = self::fill_parameters($sig, $this->args, SassScriptParser::$context, $this); return call_user_func_array(array('SassScriptFunctions', $name), $args); } foreach ($this->args as $i => $arg) { if (is_object($arg) && isset($arg->quote)) { $args[$i] = $arg->toString(); } if (!is_numeric($i) && SassScriptParser::$context->hasVariable($i)) { $args[$i] = SassScriptParser::$context->getVariable($i); } } // CSS function: create a SassString that will emit the function into the CSS return new SassString($this->name . '(' . join(', ', $args) . ')'); }