47 $this->
namespace = '';
49 $this->startToken =
null;
62 '#^\t*(?:namespace |(final )?(abstract )?(class|interface|trait|enum) |class_alias\()[^;{]+[;{]\s*\}?#m',
68 $match = trim( $match );
69 if ( str_ends_with( $match,
'{' ) ) {
76 $code =
'<?php ' . implode(
"\n", $lines ) .
"\n";
78 foreach ( token_get_all( $code ) as $token ) {
79 if ( $this->startToken ===
null ) {
95 if ( is_string( $token ) ) {
100 switch ( $token[0] ) {
108 $this->startToken = $token;
111 if ( $token[1] ===
'class_alias' ) {
112 $this->startToken = $token;
125 switch ( $this->startToken[0] ) {
130 $this->startToken =
null;
134 if ( !is_array( $token ) || $token[0] !== T_WHITESPACE ) {
135 $this->startToken =
null;
139 if ( $token ===
';' || $token ===
'{' ) {
142 $this->tokens[] = $token;
147 if ( $this->alias !==
null ) {
166 if ( $token ===
'(' ) {
168 $this->alias = [
'target' =>
false,
'name' => false ];
169 } elseif ( $token ===
',' ) {
171 if ( $this->alias[
'target'] ===
false ) {
172 $this->alias[
'target'] =
true;
174 } elseif ( is_array( $token ) && $token[0] === T_CONSTANT_ENCAPSED_STRING ) {
175 if ( $this->alias[
'target'] ===
true ) {
178 $this->alias[
'name'] = self::stripQuotes( $token[1] );
180 } elseif ( $token ===
')' ) {
182 $this->classes[] = $this->alias[
'name'];
184 $this->startToken =
null;
185 } elseif ( !is_array( $token ) || (
186 $token[0] !== T_STRING &&
187 $token[0] !== T_DOUBLE_COLON &&
188 $token[0] !== T_CLASS &&
189 $token[0] !== T_WHITESPACE
193 $this->startToken =
null;
202 $this->tokens[] = $token;
203 if ( is_array( $token ) && $token[0] === T_STRING ) {
204 $this->classes[] = $this->
namespace . $this->
implodeTokens();
219 return str_replace(
'\\\\',
'\\', substr( $str, 1, -1 ) );