/** * @param Tokenizer $tokens * @throws \LogicException * @throws \RuntimeException * @return string */ public function parseStatic(Tokenizer $tokens) { if ($this->_options & Fenom::DENY_STATICS) { throw new \LogicException("Static methods are disabled"); } $tokens->skipIf(T_NS_SEPARATOR); $name = ""; if ($tokens->is(T_STRING)) { $name .= $tokens->getAndNext(); while ($tokens->is(T_NS_SEPARATOR)) { $name .= '\\' . $tokens->next()->get(T_STRING); $tokens->next(); } } $tokens->need(T_DOUBLE_COLON)->next()->need(T_STRING); $static = $name . "::" . $tokens->getAndNext(); if (!is_callable($static)) { throw new \RuntimeException("Method {$static} doesn't exist"); } return $static; }
/** * Parse accessor */ public function parseAccessor(Tokenizer $tokens, &$is_var) { $is_var = false; $vars = array('get' => '$_GET', 'post' => '$_POST', 'session' => '$_SESSION', 'cookie' => '$_COOKIE', 'request' => '$_REQUEST', 'files' => '$_FILES', 'globals' => '$GLOBALS', 'server' => '$_SERVER', 'env' => '$_ENV', 'tpl' => '$tpl->info'); if ($this->_options & Fenom::DENY_ACCESSOR) { throw new \LogicException("Accessor are disabled"); } $key = $tokens->need('$')->next()->need('.')->next()->current(); $tokens->next(); if (isset($vars[$key])) { $is_var = true; return $this->parseVariable($tokens, $vars[$key]); } switch ($key) { case 'const': $tokens->need('.')->next(); $var = $this->parseName($tokens); if (!defined($var)) { $var = 'constant(' . var_export($var, true) . ')'; } break; case 'version': $var = '\\Fenom::VERSION'; break; default: throw new UnexpectedTokenException($tokens); } return $var; }