예제 #1
0
 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);
 }
예제 #3
0
 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;
 }
예제 #4
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;
 }
예제 #5
0
 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;
 }
예제 #8
0
 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);
 }