function __construct(parent $parent, $exception_callback)
 {
     parent::__construct($parent);
     $this->exceptionCallback .= ltrim($exception_callback, '\\');
     if ($this->targetPhpVersionId < 50300) {
         $this->exceptionCallback = substr($this->exceptionCallback, 1);
     }
 }
 function __construct(parent $parent, &$openToken, $curly, $open, $close)
 {
     $this->openToken =& $openToken;
     $this->curly = $curly;
     $this->open = $open;
     $this->close = $close;
     parent::__construct($parent);
 }
 protected function getTokens($code, $is_fragment)
 {
     if ($this->targetPhpVersionId < 50400 && stripos($code, '0b') && preg_match("'0[bB][01]'", $code)) {
         $this->unregister(array('catch0b' => T_LNUMBER));
         $this->register(array('catch0b' => T_LNUMBER));
     }
     return parent::getTokens($code, $is_fragment);
 }
 protected function getTokens($code, $is_fragment)
 {
     if ($this->targetPhpVersionId < 50400 && stripos($code, '0b') && preg_match("'0[bB][01]'", $code)) {
         $c = array('catch0b' => PHP_VERSION_ID >= 50400 ? array(T_LNUMBER, T_DNUMBER) : T_LNUMBER);
         $this->unregister($c);
         $this->register($c);
     }
     return parent::getTokens($code, $is_fragment);
 }
 function __construct(parent $parent, $error_handler)
 {
     parent::__construct($parent);
     if ($error_handler) {
         if (is_array($error_handler)) {
             $error_handler = implode('::', $error_handler);
         }
         $this->errorHandler = self::export($error_handler);
     }
 }
 function __construct(parent $parent = null, $prepended_code)
 {
     if ($prepended_code) {
         $this->prependedCode = $prepended_code;
     }
     if ($this->prependedCode) {
         $this->prependedCode .= '(';
     } else {
         unset($this->callbacks['~tagRequire']);
     }
     parent::__construct($parent);
 }
Beispiel #7
0
 function __construct(Parser $parent, $inlineClass, $mark_require, $file)
 {
     foreach ($inlineClass as $inlineClass) {
         $this->inlineClass[strtolower(strtr($inlineClass, '\\', '_'))] = 1;
     }
     Parser::__construct($parent);
     $mark_require or $this->unregister(array('tagAutoloader' => array(T_REQUIRE_ONCE, T_INCLUDE_ONCE, T_REQUIRE, T_INCLUDE)));
     $s = stat($file);
     $s = array($file, $s['dev'], $s['ino'], $s['size'], $s['mtime'], $s['ctime']);
     $s = base64_encode(md5(implode('-', $s), true));
     $this->seed = substr($s, 0, 8);
 }
 protected function getTokens($code, $is_fragment)
 {
     $tokens = parent::getTokens($code, $is_fragment);
     if ($this->targetPhpVersionId < 50500 && preg_match('/(?:parent|self)(?-i)(?<!parent|self)/i', $code)) {
         $i = 0;
         while (isset($tokens[++$i])) {
             if (T_STRING === $tokens[$i][0] && ('parent' === ($k = strtolower($tokens[$i][1])) or 'self' === $k)) {
                 $tokens[$i][1] = $k;
             }
         }
     }
     return $tokens;
 }
 function __construct(parent $parent, $file, &$new_consts = array(), $compiler_halt_offset = 0)
 {
     if ($file) {
         $this->file = $file;
     } else {
         unset($this->callbacks['tagFileC'], $this->callbacks['tagLineC']);
     }
     $file = self::$staticConsts;
     self::loadConsts($new_consts);
     $this->constants = self::$staticConsts;
     self::$staticConsts = $file;
     $this->newConsts =& $new_consts;
     if (0 < $compiler_halt_offset) {
         $this->constants['__COMPILER_HALT_OFFSET__'] = (int) $compiler_halt_offset;
     }
     parent::__construct($parent);
 }
Beispiel #10
0
 function __construct(parent $parent, $autoglobals)
 {
     foreach ((array) $autoglobals as $autoglobals) {
         switch ($autoglobals) {
             case '$_GET':
             case '$_ENV':
             case '$_POST':
             case '$_COOKIE':
             case '$_SERVER':
             case '$_REQUEST':
             case '$GLOBALS':
                 continue 2;
         }
         $this->autoglobals[$autoglobals] = 1;
     }
     parent::__construct($parent);
 }
Beispiel #11
0
 protected function getTokens($code, $is_fragment)
 {
     if ($is_fragment) {
         return parent::getTokens($code, $is_fragment);
     }
     if ($this->checkUtf8 && !preg_match('//u', $code)) {
         $line = strtr($code, '?', '-');
         $line = utf8_decode($line);
         $line = 1 + substr_count($line, "\n", 0, strpos($line, '?'));
         $this->setError("File encoding is not valid UTF-8", E_USER_WARNING, $line);
     }
     if ($this->stripUtf8Bom && 0 === strncmp($code, "", 3)) {
         // substr_replace() is for mbstring overloading resistance
         $code = substr_replace($code, '', 0, 3);
         $this->setError("Stripping UTF-8 Byte Order Mark", E_USER_NOTICE);
     }
     if ('' === $code) {
         return array();
     }
     $code = parent::getTokens($code, $is_fragment);
     // Ensure that the first token is always a T_OPEN_TAG
     if (T_INLINE_HTML === $code[0][0]) {
         $a = $code[0][1][0];
         if ("\r" === $a || "\n" === $a) {
             if ("\r" === $a) {
                 $a .= "\n";
             }
             $code[0][1] = (string) substr($code[0][1], strlen($a));
             array_unshift($code, array(T_OPEN_TAG, '<?php '), array(T_ECHO, 'echo'), array(T_ENCAPSED_AND_WHITESPACE, "\n" === $a ? '"\\n"' : '"\\r\\n"'), array(T_CLOSE_TAG, '?>' . $a));
         } else {
             array_unshift($code, array(T_OPEN_TAG, '<?php '), array(T_CLOSE_TAG, '?>'));
         }
     }
     // Ensure that the last valid PHP code position is tagged with a T_ENDPHP
     $a = array_pop($code);
     if (T_COMMENT === $a[0] && strcspn($a[1], "\r\n") === strlen($a[1])) {
         $a[1] .= $this->targetEol;
     }
     $code[] = T_CLOSE_TAG === $a[0] ? ';' : $a;
     T_INLINE_HTML === $a[0] && ($code[] = array(T_OPEN_TAG, '<?php '));
     $code[] = array(T_ENDPHP, '');
     return $code;
 }
 protected function getTokens($code, $is_fragment)
 {
     $b = $this->backports;
     foreach ($b as $k => $i) {
         if (false === stripos($code, $k)) {
             unset($b[$k]);
         }
     }
     $code = parent::getTokens($code, $is_fragment);
     $i = 0;
     if ($b) {
         while (isset($code[++$i])) {
             if (T_STRING === $code[$i][0] && isset($b[$k = strtolower($code[$i][1])]) && T_OBJECT_OPERATOR !== $code[$i - 1][0]) {
                 $code[$i][0] = $b[$k];
             }
         }
     }
     return $code;
 }
 protected function getTokens($code, $is_fragment)
 {
     $b = $this->backports;
     foreach ($b as $k => $i) {
         if (false === stripos($code, $k)) {
             unset($b[$k]);
         }
     }
     $code = parent::getTokens($code, $is_fragment);
     $i = 0;
     if ($b) {
         while (isset($code[++$i])) {
             if (T_STRING === $code[$i][0] && isset($b[$k = strtolower($code[$i][1])]) && T_OBJECT_OPERATOR !== $code[$i - 1][0]) {
                 $code[$i][0] = $b[$k];
             } else {
                 if ('.' === $code[$i] && isset($code[$i + 1], $code[$i + 2]) && '.' === $code[$i + 1] && '.' === $code[$i + 2]) {
                     $code[$i] = array(T_ELLIPSIS, '...');
                     $code[$i + 1] = array(T_WHITESPACE, '');
                     $code[$i + 2] = array(T_WHITESPACE, '');
                 } else {
                     if ('*' === $code[$i] && isset($code[$i + 1])) {
                         if ('*' === $code[$i + 1]) {
                             $code[$i] = array(T_POW, '**');
                             $code[$i + 1] = array(T_WHITESPACE, '');
                         } else {
                             if (T_MUL_EQUAL === $code[$i + 1][0]) {
                                 $code[$i] = array(T_POW_EQUAL, '**=');
                                 $code[$i + 1] = array(T_WHITESPACE, '');
                             }
                         }
                     } else {
                         if ('?' === $code[$i] && isset($code[$i + 1]) && '?' === $code[$i + 1]) {
                             $code[$i] = array(T_COALESCE, '??');
                             $code[$i + 1] = array(T_WHITESPACE, '');
                         }
                     }
                 }
             }
         }
     }
     return $code;
 }
 function removeHaltCompiler($code, &$compiler_halt_offset)
 {
     if (false === stripos($code, '__halt_compiler')) {
         $compiler_halt_offset = 0;
         return $code;
     }
     $data_offset = 0;
     foreach (parent::getTokens($code, false) as $t) {
         if (isset($t[1])) {
             $data_offset += strlen($t[1]);
         } else {
             ++$data_offset;
         }
         if (isset($tail)) {
             if (isset($t[1])) {
                 switch ($t[0]) {
                     case T_WHITESPACE:
                     case T_COMMENT:
                     case T_DOC_COMMENT:
                     case T_BAD_CHARACTER:
                         continue 2;
                 }
             }
             if (0 === --$tail) {
                 break;
             }
         } else {
             if (T_HALT_COMPILER === $t[0]) {
                 $code_len = $data_offset - strlen($t[1]);
                 $tail = 3;
             }
         }
     }
     if (isset($code_len)) {
         $compiler_halt_offset += $data_offset;
         $code = substr($code, 0, $code_len);
     } else {
         $compiler_halt_offset = 0;
     }
     return $code;
 }
 protected function getTokens($code, $is_fragment)
 {
     if ($this->targetPhpVersionId < 50400 && false !== strpos($code, '<?=')) {
         if (isset($this->tag)) {
             if (false !== $this->tag) {
                 $code = str_replace('<?=', $this->tag, $code);
             }
         } else {
             $c = token_get_all('<?=');
             if (T_INLINE_HTML === $c[0][0]) {
                 $this->tag = '<?php __echo_soe_' . mt_rand() . ' ';
                 $code = str_replace('<?=', $this->tag, $code);
                 $this->register(array('echoTag' => T_OPEN_TAG, 'removeTag' => array(T_CONSTANT_ENCAPSED_STRING, T_ENCAPSED_AND_WHITESPACE, T_COMMENT, T_DOC_COMMENT, T_INLINE_HTML)));
             } else {
                 $this->tag = false;
                 $this->register(array('tagOpenEcho' => T_OPEN_TAG_WITH_ECHO));
             }
         }
     }
     return parent::getTokens($code, $is_fragment);
 }
<?php

// vi: set fenc=utf-8 ts=4 sw=4 et:
/*
 * Copyright (C) 2012 Nicolas Grekas - p@tchwork.com
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the (at your option):
 * Apache License v2.0 (http://apache.org/licenses/LICENSE-2.0.txt), or
 * GNU General Public License v2.0 (http://gnu.org/licenses/gpl-2.0.txt).
 */
namespace Patchwork\PHP\Parser;

use Patchwork\PHP\Parser;
Parser::createToken('T_BRACKET_CLOSE');
/**
 * The BracketWatcher parser counts opening brackets and triggers callbacks on corresponding closing brackets.
 */
class BracketWatcher extends Parser
{
    protected $brackets = array(), $bracketsCount = 0, $callbacks = array('~pushBracket' => array('{', '[', '('), 'closeBracket' => array('}', ']', ')'), '~popBracket' => array('}', ']', ')'));
    protected function pushBracket(&$token)
    {
        ++$this->bracketsCount;
        $b =& $this->brackets[];
        switch ($token[0]) {
            case '(':
                $b = ')';
                break;
            case '[':
                $b = ']';
 function __construct(parent $parent, $ns_code_loader = null)
 {
     $this->nsCodeLoader = $ns_code_loader ? $ns_code_loader : array($this, 'nsCodeLoader');
     parent::__construct($parent);
 }
 function __construct(parent $parent, $alias_add = false)
 {
     $this->aliasAdd = $alias_add;
     parent::__construct($parent);
 }
 function __construct(parent $parent = null)
 {
     parent::__construct($parent);
     $this->register($this->stateCallbacks[2]);
     $this->runtimeKey = mt_rand(1, mt_getrandmax());
 }
 function __construct(parent $parent, &$new_shims = array())
 {
     parent::__construct($parent);
     $this->shims = self::$staticShims;
     $this->newShims =& $new_shims;
 }
Beispiel #21
0
<?php

// vi: set fenc=utf-8 ts=4 sw=4 et:
/*
 * Copyright (C) 2012 Nicolas Grekas - p@tchwork.com
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the (at your option):
 * Apache License v2.0 (http://apache.org/licenses/LICENSE-2.0.txt), or
 * GNU General Public License v2.0 (http://gnu.org/licenses/gpl-2.0.txt).
 */
namespace Patchwork\PHP\Parser;

use Patchwork\PHP\Parser;
Parser::createToken('T_NAME_NS', 'T_NAME_CLASS', 'T_NAME_FUNCTION', 'T_NAME_CONST', 'T_USE_NS', 'T_USE_CLASS', 'T_USE_METHOD', 'T_USE_PROPERTY', 'T_USE_FUNCTION', 'T_USE_CONST', 'T_USE_CONSTANT', 'T_GOTO_LABEL', 'T_TYPE_HINT');
/**
 * The StringInfo parser analyses T_STRING tokens and gives them a secondary type to allow more specific semantics.
 *
 * This parser analyses tokens surrounding T_STRING tokens and is able to determine between many different semantics:
 * - T_NAME_NS:       namespace declaration as in namespace FOO\BAR
 * - T_NAME_CLASS:    class, interface or trait declaration as in class FOO {}
 * - T_NAME_FUNCTION: function or method declaration as in function FOO()
 * - T_NAME_CONST:    class or namespaced const declaration as in const FOO
 * - T_USE_NS:        namespace prefix or "use" aliasing as in FOO\bar
 * - T_USE_CLASS:     class usage as in new foo\BAR or FOO::
 * - T_USE_METHOD:    method call as in $a->FOO() or a::BAR()
 * - T_USE_PROPERTY:  property access as in $a->BAR
 * - T_USE_FUNCTION:  function call as in foo\BAR()
 * - T_USE_CONST:     class constant access as in foo::BAR
 * - T_USE_CONSTANT:  global or namespaced constant access as in FOO or foo\BAR
 * - T_GOTO_LABEL:    goto label as in goto FOO or BAR:{}
Beispiel #22
0
<?php

// vi: set fenc=utf-8 ts=4 sw=4 et:
/*
 * Copyright (C) 2012 Nicolas Grekas - p@tchwork.com
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the (at your option):
 * Apache License v2.0 (http://apache.org/licenses/LICENSE-2.0.txt), or
 * GNU General Public License v2.0 (http://gnu.org/licenses/gpl-2.0.txt).
 */
namespace Patchwork\PHP\Parser;

use Patchwork\PHP\Parser;
Parser::createToken('T_SCOPE_OPEN');
/**
 * The ScopeInfo parser exposes scopes to dependend parsers.
 *
 * Scopes are typed as T_OPEN_TAG, T_NAMESPACE, T_FUNCTION, T_CLASS, T_INTERFACE and T_TRAIT, each
 * of these corresponding to the type of the token who opened the scope. For each scope, this
 * parser exposes this type alongside with a reference to its opening token and its parent scope.
 *
 * T_SCOPE_OPEN can be registered by dependend parsers and is emitted on scope opening tokens.
 * When T_BRACKET_CLOSE is registered within a T_SCOPE_OPEN, it matches its corresponding scope closing token.
 *
 * ScopeInfo eventually inherits removeNsPrefix(), namespace, nsResolved, nsPrefix properties from NamespaceInfo.
 */
class ScopeInfo extends Parser
{
    protected $scope = false, $nextScope = T_OPEN_TAG, $callbacks = array('~tagFirstScope' => array(T_OPEN_TAG, ';', '{'), 'tagScopeOpen' => '{', 'tagNamespace' => T_NAMESPACE, 'tagEndScope' => T_ENDPHP, 'tagFunction' => T_FUNCTION, 'tagClass' => array(T_CLASS, T_INTERFACE, T_TRAIT)), $namespace, $nsResolved, $nsPrefix, $dependencies = array('BracketWatcher', 'NamespaceInfo' => array('namespace', 'nsResolved', 'nsPrefix'), 'Normalizer');
    function removeNsPrefix()
Beispiel #23
0
 function __construct(parent $parent)
 {
     $this->callbacks = $parent->targetPhpVersionId < 50400 ? $this->backwardCallbacks : $this->forwardCallbacks;
     parent::__construct($parent);
 }