56 $this->
namespace = '';
58 $this->startToken =
null;
71 '#^\t*(?:namespace |(final )?(abstract )?(class|interface|trait) |class_alias\()[^;{]+[;{]\s*\}?#m',
77 $match = trim( $match );
78 if ( substr( $match, -1 ) ===
'{' ) {
85 $code =
'<?php ' . implode(
"\n",
$lines ) .
"\n";
87 foreach ( token_get_all( $code ) as $token ) {
88 if ( $this->startToken ===
null ) {
104 if ( is_string( $token ) ) {
109 switch ( $token[0] ) {
116 $this->startToken = $token;
119 if ( $token[1] ===
'class_alias' ) {
120 $this->startToken = $token;
133 switch ( $this->startToken[0] ) {
137 $this->startToken =
null;
141 if ( !is_array( $token ) || $token[0] !== T_WHITESPACE ) {
142 $this->startToken =
null;
146 if ( $token ===
';' || $token ===
'{' ) {
149 $this->tokens[] = $token;
154 if ( $this->alias !==
null ) {
173 if ( $token ===
'(' ) {
175 $this->alias = [
'target' =>
false,
'name' => false ];
176 } elseif ( $token ===
',' ) {
178 if ( $this->alias[
'target'] ===
false ) {
179 $this->alias[
'target'] =
true;
181 } elseif ( is_array( $token ) && $token[0] === T_CONSTANT_ENCAPSED_STRING ) {
182 if ( $this->alias[
'target'] ===
true ) {
187 } elseif ( $token ===
')' ) {
189 $this->classes[] = $this->alias[
'name'];
191 $this->startToken =
null;
192 } elseif ( !is_array( $token ) || (
193 $token[0] !== T_STRING &&
194 $token[0] !== T_DOUBLE_COLON &&
195 $token[0] !== T_CLASS &&
196 $token[0] !== T_WHITESPACE
200 $this->startToken =
null;
208 $this->tokens[] = $token;
209 if ( is_array( $token ) && $token[0] === T_STRING ) {
210 $this->classes[] = $this->
namespace . $this->
implodeTokens();
225 return str_replace(
'\\\\',
'\\', substr( $str, 1, -1 ) );
236 foreach ( $this->tokens as $token ) {
237 $content[] = is_string( $token ) ? $token : $token[1];
241 $this->startToken =
null;
243 return trim( implode(
'',
$content ),
" \n\t" );
static stripQuotes( $str)
Decode a quoted PHP string, interpreting escape sequences, like eval($str).
implodeTokens()
Returns the string representation of the tokens within the current expect sequence and resets the seq...
Reads PHP code and returns the FQCN of every class defined within it.
string $namespace
Current namespace.
array $classes
List of FQCN detected in this pass.
array null $alias
Class alias with target/name fields.
array null $startToken
Token from token_get_all() that started an expect sequence.
tryEndExpect( $token)
Accepts the next token in an expect sequence.
array[] string[] $tokens
List of tokens that are members of the current expect sequence.
tryBeginExpect( $token)
Determine if $token begins the next expect sequence.
if(!file_exists( $CREDITS)) $lines