19 $tokens = token_get_all ( $phpCode );
20 $count = \count ( $tokens );
23 $namespace_ok =
false;
24 while ( $i < $count ) {
25 $token = $tokens [$i];
26 if (\is_array ( $token ) && $token [0] === T_NAMESPACE) {
28 while ( ++ $i < $count ) {
29 if ($tokens [$i] ===
';') {
31 $namespace = \trim ( $namespace );
34 $namespace .= \is_array ( $tokens [$i] ) ? $tokens [$i] [1] : $tokens [$i];
40 if (! $namespace_ok) {
49 $tokens = \token_get_all ( $phpCode );
50 $count = count ( $tokens );
51 for($i = 2; $i < $count; $i ++) {
52 if (($tokens [$i - 2] [0] == T_TRAIT || $tokens [$i - 2] [0] == T_CLASS )&& $tokens [$i - 1] [0] == T_WHITESPACE && $tokens [$i] [0] == T_STRING) {
53 $class_name = $tokens [$i] [1];
54 $classes [] = $class_name;
57 if (isset ( $classes [0] ))
71 $phpCode = \file_get_contents ( $filePathName );
73 if ($backSlash && UString::isNotNull ( $ns )) {
84 return \str_replace (
"\\",
"\\\\", $classname );
95 if (! \is_array ( $parts )) {
98 foreach ( $parts as $part ) {
99 $resultArray = \array_merge ( $resultArray, \explode (
"\\", $part ) );
101 $resultArray = \array_diff ( $resultArray, [
"" ] );
102 return \implode (
"\\", $resultArray );
112 $position = \strrpos ( $completeClassname,
'\\' );
113 return \substr ( $completeClassname, 0, $position );
125 $object =
new $classString ();
137 $phpCode = \file_get_contents ( $filePathName );
149 $phpCode = \file_get_contents ( $filePathName );
161 if (\strpos ( $name,
"\\" ) ===
false) {
162 $name = $defaultNS .
"\\" . $name;
174 if (($pos = \strrpos ( $classnameWithNamespace,
'\\' )) !==
false) {
175 return \substr ( $classnameWithNamespace, $pos + 1 );
177 return $classnameWithNamespace;
Manipulates class and namespace names Ubiquity\cache$ClassUtils This class is part of Ubiquity.
static getClassObjectFromFile($filePathName)
build and return an object of a class from its file path
static getClassFullNameFromFile($filePathName, $backSlash=false)
get the full name (name \ namespace) of a class from its file path result example: (string) "I\Am\The...
static getClassNameFromPhpCode($phpCode)
static getNamespaceFromCompleteClassname($completeClassname)
Returns the namespace from a complete classname.
static getClassNamespaceFromFile($filePathName)
get the class namespace form file path using token
static cleanClassname($classname)
static getNamespaceFromParts($parts)
Returns a cleanly namespace.
static getClassNameFromFile($filePathName)
get the class name from file path using token
static getClassNamespaceFromPhpCode($phpCode)
static getClassNameWithNS($defaultNS, $name)
Returns the complete name of a class.
static getClassSimpleName($classnameWithNamespace)
Returns the simple class name of a class, without namespace.