SassScriptFunction::fill_parameters PHP Метод

fill_parameters() публичный статический Метод

public static fill_parameters ( $required, $provided, $context, $source )
    public static function fill_parameters($required, $provided, $context, $source)
    {
        $context = new SassContext($context);
        $_required = array_merge(array(), $required);
        // need to array_merge?
        $fill = $_required;
        foreach ($required as $name => $default) {
            // we require that named variables provide a default.
            if (isset($provided[$name]) && $default !== NULL) {
                $_required[$name] = $provided[$name];
                unset($provided[$name]);
                unset($required[$name]);
            }
        }
        // print_r(array($required, $provided, $_required));
        $provided_copy = $provided;
        foreach ($required as $name => $default) {
            if ($default === null && strpos($name, '=') !== FALSE) {
                list($name, $default) = explode('=', $name);
                $name = trim($name);
                $default = trim($default);
            }
            if (count($provided)) {
                $arg = array_shift($provided);
            } elseif ($default !== NULL) {
                $arg = $default;
                // for mixins with default values that refer to other arguments
                // (e.g. border-radius($topright: 0, $bottomright: $topright, $bottomleft: $topright, $topleft: $topright)
                if (is_string($default) && $default[0] == '$') {
                    $referred = trim(trim($default, '$'));
                    $pos = array_search($referred, array_keys($required));
                    if ($pos !== false && array_key_exists($pos, $provided_copy)) {
                        $arg = $provided_copy[$pos];
                    }
                }
            } else {
                throw new SassMixinNodeException("Function::{$name}: Required variable ({$name}) not given.\nFunction defined: " . $source->token->filename . '::' . $source->token->line . "\nFunction used", $source);
            }
            // splats
            if (substr($name, -3, 3) == '...') {
                unset($_required[$name]);
                $name = substr($name, 0, -3);
                $_required[$name] = new SassList('', ',');
                $_required[$name]->value = array_merge(array($arg), $provided);
                continue;
            } else {
                $_required[$name] = $arg;
            }
        }
        $_required = array_merge($_required, $provided);
        // any remaining args get tacked onto the end
        foreach ($_required as $key => $value) {
            if (!is_object($value)) {
                $_required[$key] = SassScriptParser::$instance->evaluate($value, $context);
            }
        }
        return array($_required, $context);
    }

Usage Example

 /**
  * Parse this node.
  * Set passed arguments and any optional arguments not passed to their
  * defaults, then render the children of the mixin definition.
  * @param SassContext the context in which this node is parsed
  * @return array the parsed node
  */
 public function parse($pcontext)
 {
     $mixin = $pcontext->getMixin($this->name);
     $context = new SassContext($pcontext);
     $context->content = $this->children;
     $argc = count($this->args);
     $count = 0;
     list($arguments) = SassScriptFunction::fill_parameters($mixin->args, $this->args, $context, $this);
     $context->setVariables($arguments);
     $children = array();
     foreach ($mixin->children as $child) {
         $child->parent = $this;
         $children = array_merge($children, $child->parse($context));
     }
     // $context->merge();
     return $children;
 }
All Usage Examples Of SassScriptFunction::fill_parameters