protected function render() { $this->presets = []; /** @var Metadata $where */ foreach ($this->props->where as $where) { $whereSubtags = $where->getChildren(); if (!$whereSubtags) { continue; } $where->databind(); $rule = $where->props->match; if (!$rule) { continue; } $preset = new Preset($rule); $append = []; $prepend = []; $replace = []; $unset = []; foreach ($whereSubtags as $subTag) { switch ($subTag->getTagName()) { case 'Set': $subTag->databind(); $newProps = $subTag->props->getAll(); $preset->props = isset($preset->props) ? array_merge($preset->props, $newProps) : $newProps; break; case 'Unset': if (isset($preset->props)) { $subTag->databind(); $newProps = array_keys($subTag->props->getAll()); array_mergeInto($unset, $newProps); } break; case 'Prepend': array_mergeInto($prepend, $subTag->getChildren()); break; case 'Append': array_mergeInto($append, $subTag->getChildren()); break; default: //overwrite $replace[] = $subTag; } } $preset->prepend = $prepend; $preset->append = $append; $preset->content = $replace; $preset->unset = $unset; $this->presets[] = $preset; } $stack = $this->context->presets; // Save a copy of the current presets stack. $this->context->presets[] = $this; $this->runChildren(); $this->context->presets = $stack; // Note: it is not safe to just do an array_pop() here. }
/** * @param string[] $classes List of class names providing component presets. * @return $this */ function registerPresets(array $classes) { array_mergeInto($this->presets, $classes); return $this; }
/** * @param Component[]|null $children */ public function addChildren(array $children = null) { if ($children) { array_mergeInto($this->children, $children); $this->attach($children); } }
function endAssetsContext() { $from = $this->assets; $to = $this->mainAssets; if ($from->prepend) { $to->inlineCssStyles = array_merge($from->inlineCssStyles, $to->inlineCssStyles); $to->inlineScripts = array_merge($from->inlineScripts, $to->inlineScripts); $unique = array_diff($from->scripts, $to->scripts); $to->scripts = array_merge($unique, $to->scripts); $unique = array_diff($from->stylesheets, $to->stylesheets); $to->stylesheets = array_merge($unique, $to->stylesheets); } else { array_mergeInto($to->inlineCssStyles, $from->inlineCssStyles); array_mergeInto($to->inlineScripts, $from->inlineScripts); $unique = array_diff($from->scripts, $to->scripts); array_mergeInto($to->scripts, $unique); $unique = array_diff($from->stylesheets, $to->stylesheets); array_mergeInto($to->stylesheets, $unique); } $this->assets = $to; }
/** * Merges another array or instance of this class with this one. * * @param array|PowerArray $v */ function merge($v) { if (is_array($v)) { array_mergeInto($this->A, $v); } else { if ($v instanceof static) { array_mergeInto($this->A, $v->A); } else { throw new InvalidArgumentException(); } } }