public function __get($key) { $hint = Helpers::getSuggestion(array_keys((array) $this), $key); trigger_error("Attempt to read missing column '{$key}'" . ($hint ? ", did you mean '{$hint}'?" : '.'), E_USER_NOTICE); }
/** * Expands macro and returns node & code. * @param string * @param string * @param string * @return MacroNode * @internal */ public function expandMacro($name, $args, $modifiers = NULL, $nPrefix = NULL) { $inScript = in_array($this->context[0], array(self::CONTENT_JS, self::CONTENT_CSS), TRUE); if (empty($this->macros[$name])) { $hint = ($t = Helpers::getSuggestion(array_keys($this->macros), $name)) ? ", did you mean {{$t}}?" : ''; throw new CompileException("Unknown macro {{$name}}{$hint}" . ($inScript ? ' (in JavaScript or CSS, try to put a space after bracket.)' : '')); } if (strpbrk($name, '=~%^&_')) { if ($this->context[1] === self::CONTENT_URL) { $modifiers = preg_replace('#\\|nosafeurl\\s?(?=\\||\\z)#i', '', $modifiers, -1, $found); if (!$found && !preg_match('#\\|datastream(?=\\s|\\||\\z)#i', $modifiers)) { $modifiers .= '|safeurl'; } } $modifiers = preg_replace('#\\|noescape\\s?(?=\\||\\z)#i', '', $modifiers, -1, $found); if (!$found) { $modifiers .= '|escape'; } if (!$found && $inScript && $name === '=' && preg_match('#["\'] *\\z#', $this->tokens[$this->position - 1]->text)) { throw new CompileException("Do not place {$this->tokens[$this->position]->text} inside quotes."); } } foreach (array_reverse($this->macros[$name]) as $macro) { $node = new MacroNode($macro, $name, $args, $modifiers, $this->macroNode, $this->htmlNode, $nPrefix); if ($macro->nodeOpened($node) !== FALSE) { return $node; } } throw new CompileException('Unknown ' . ($nPrefix ? 'attribute ' . Parser::N_PREFIX . ($nPrefix === MacroNode::PREFIX_NONE ? '' : "{$nPrefix}-") . $name : 'macro {' . $name . ($args ? " {$args}" : '') . '}')); }
/** * Call a run-time filter. * @param string filter name * @param array arguments * @return mixed */ public function invokeFilter($name, array $args) { $lname = strtolower($name); if (!isset($this->filters[$lname])) { $args2 = $args; array_unshift($args2, $lname); foreach ($this->filters[NULL] as $filter) { $res = call_user_func_array(Helpers::checkCallback($filter), $args2); if ($res !== NULL) { return $res; } elseif (isset($this->filters[$lname])) { return call_user_func_array(Helpers::checkCallback($this->filters[$lname]), $args); } } $hint = ($t = Helpers::getSuggestion(array_keys($this->filters), $name)) ? ", did you mean '{$t}'?" : '.'; throw new \LogicException("Filter '{$name}' is not defined{$hint}"); } return call_user_func_array(Helpers::checkCallback($this->filters[$lname]), $args); }
/** * Expands macro and returns node & code. * @param string * @param string * @param string * @return MacroNode * @internal */ public function expandMacro($name, $args, $modifiers = NULL, $nPrefix = NULL) { $inScript = in_array($this->context, [self::CONTEXT_HTML_JS, self::CONTEXT_HTML_CSS], TRUE); if (empty($this->macros[$name])) { $hint = ($t = Helpers::getSuggestion(array_keys($this->macros), $name)) ? ", did you mean {{$t}}?" : ''; throw new CompileException("Unknown macro {{$name}}{$hint}" . ($inScript ? ' (in JavaScript or CSS, try to put a space after bracket or use n:syntax=off)' : '')); } if (preg_match('#\\|(no)?safeurl(?!\\w)#i', $modifiers, $m)) { $hint = $m[1] ? '|nocheck' : '|checkurl'; $modifiers = str_replace($m[0], $hint, $modifiers); trigger_error("Modifier {$m['0']} is deprecated, please replace it with {$hint}.", E_USER_DEPRECATED); } if (strpbrk($name, '=~%^&_')) { if (in_array($this->context, [self::CONTEXT_HTML_ATTRIBUTE_URL, self::CONTEXT_HTML_ATTRIBUTE_UNQUOTED_URL], TRUE)) { if (!Helpers::removeFilter($modifiers, 'nosafeurl|nocheck') && !preg_match('#\\|datastream(?=\\s|\\||\\z)#i', $modifiers)) { $modifiers .= '|checkurl'; } } if (!Helpers::removeFilter($modifiers, 'noescape')) { $modifiers .= '|escape'; if ($inScript && $name === '=' && preg_match('#["\'] *\\z#', $this->tokens[$this->position - 1]->text)) { throw new CompileException("Do not place {$this->tokens[$this->position]->text} inside quotes."); } } } if ($nPrefix === MacroNode::PREFIX_INNER && !strcasecmp($this->htmlNode->name, 'script')) { $context = [$this->contentType, self::CONTEXT_HTML_JS]; } elseif ($nPrefix === MacroNode::PREFIX_INNER && !strcasecmp($this->htmlNode->name, 'style')) { $context = [$this->contentType, self::CONTEXT_HTML_CSS]; } elseif ($nPrefix) { $context = [$this->contentType, self::CONTEXT_HTML_TEXT]; } else { $context = [$this->contentType, $this->context]; } foreach (array_reverse($this->macros[$name]) as $macro) { $node = new MacroNode($macro, $name, $args, $modifiers, $this->macroNode, $this->htmlNode, $nPrefix); $node->context = $context; $node->startLine = $nPrefix ? $this->htmlNode->startLine : $this->getLine(); if ($macro->nodeOpened($node) !== FALSE) { return $node; } } throw new CompileException('Unknown ' . ($nPrefix ? 'attribute ' . Parser::N_PREFIX . ($nPrefix === MacroNode::PREFIX_NONE ? '' : "{$nPrefix}-") . $name : 'macro {' . $name . ($args ? " {$args}" : '') . '}')); }