You are here

public function SassScriptFunction::perform in Sassy 7.3

Same name and namespace in other branches
  1. 7 phamlp/sass/script/SassScriptFunction.php \SassScriptFunction::perform()

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 value

Function the value of this Function

File

phpsass/script/SassScriptFunction.php, line 80

Class

SassScriptFunction
SassScriptFunction class. Preforms a SassScript function. @package PHamlP @subpackage Sass.script

Code

public function perform() {
  $name = preg_replace('/[^a-z0-9_]/', '_', strtolower($this->name));
  $args = $this
    ->process_arguments($this->args);
  self::$context = SassScriptParser::$context;
  try {
    if ($fn = SassScriptParser::$context
      ->hasFunction($this->name)) {
      $return = SassScriptParser::$context
        ->getFunction($this->name)
        ->execute(SassScriptParser::$context, $this->args);
      return $return;
    }
    else {
      if ($fn = 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) && function_exists($callback)) {
        $result = call_user_func_array($callback, $args);
        if (is_string($result)) {
          $lexed = SassScriptLexer::$instance
            ->lex($result, new SassContext());

          // $parsed = SassScriptParser::$instance->parse($result, new SassContext());
          return new SassString(implode('', $this
            ->process_arguments($lexed)));
        }
        return $result;
      }
    }
  }
  if (method_exists('SassScriptFunctions', $name)) {
    return call_user_func_array(array(
      'SassScriptFunctions',
      $name,
    ), $this->args);
  }

  // CSS function: create a SassString that will emit the function into the CSS
  return new SassString($this->name . '(' . join(', ', $args) . ')');
}