You are here

public function SassScriptFunction::perform in Sassy 7

Same name and namespace in other branches
  1. 7.3 phpsass/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 * @throws SassScriptFunctionException if function is undefined

File

phamlp/sass/script/SassScriptFunction.php, line 49

Class

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

Code

public function perform() {
  $name = str_replace('-', '_', $this->name);
  foreach (SassScriptParser::$context->node->parser->function_paths as $path) {
    $_path = explode(DIRECTORY_SEPARATOR, $path);
    $_class = ucfirst($_path[sizeof($_path) - 2]);
    foreach (array_slice(scandir($path), 2) as $file) {
      $filename = $path . DIRECTORY_SEPARATOR . $file;
      if (is_file($filename)) {
        require_once $filename;
        $class = 'SassExtentions' . $_class . 'Functions' . ucfirst(substr($file, 0, -4));
        if (method_exists($class, $name)) {
          return call_user_func_array(array(
            $class,
            $name,
          ), $this->args);
        }
      }
    }

    // foreach
  }

  // foreach
  require_once 'SassScriptFunctions.php';
  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
  $args = array();
  foreach ($this->args as $arg) {
    $args[] = $arg
      ->toString();
  }
  return new SassString($this->name . '(' . join(', ', $args) . ')');
}