18 $phpCode=\file_get_contents($filePathName);
19 $ns=self::getClassNamespaceFromPhpCode($phpCode);
23 return $ns.
'\\' . self::getClassNameFromPhpCode($phpCode);
27 return \str_replace(
"\\",
"\\\\", $classname);
37 if(!\is_array($parts)){
40 foreach ($parts as $part){
41 $resultArray=\array_merge($resultArray,\explode(
"\\", $part));
43 $resultArray=\array_diff($resultArray, [
""]);
44 return \implode(
"\\", $resultArray);
55 $classString=self::getClassFullNameFromFile($filePathName);
56 $object=
new $classString();
68 $phpCode=\file_get_contents($filePathName);
69 return self::getClassNamespaceFromPhpCode($phpCode);
73 $tokens=token_get_all($phpCode);
74 $count=\count($tokens);
78 while ( $i < $count ) {
80 if (\is_array($token) && $token[0] === T_NAMESPACE) {
82 while ( ++$i < $count ) {
83 if ($tokens[$i] ===
';') {
85 $namespace=\trim($namespace);
88 $namespace.=\is_array($tokens[$i]) ? $tokens[$i][1] : $tokens[$i];
109 $phpCode=\file_get_contents($filePathName);
110 return self::getClassNameFromPhpCode($phpCode);
115 $tokens=\token_get_all($phpCode);
116 $count=count($tokens);
117 for($i=2; $i < $count; $i++) {
118 if ($tokens[$i - 2][0] == T_CLASS && $tokens[$i - 1][0] == T_WHITESPACE && $tokens[$i][0] == T_STRING) {
119 $class_name=$tokens[$i][1];
120 $classes[]=$class_name;
123 if(isset($classes[0]))
129 if(\strpos($name,
"\\")===
false){
130 $name=$defaultNS.
"\\".$name;
136 return substr($classnameWithNamespace, strrpos($classnameWithNamespace,
'\\')+1);
static getClassNameFromFile($filePathName)
get the class name form file path using token
static getClassNamespaceFromFile($filePathName)
get the class namespace form file path using token
static getNamespaceFromParts($parts)
Returns a cleanly namespace.
static getClassNameWithNS($defaultNS, $name)
static getClassNamespaceFromPhpCode($phpCode)
static cleanClassname($classname)
static getClassObjectFromFile($filePathName)
build and return an object of a class from its file path
static getClassNameFromPhpCode($phpCode)
static getClassSimpleName($classnameWithNamespace)
static getClassFullNameFromFile($filePathName, $backSlash=false)
get the full name (name \ namespace) of a class from its file path result example: (string) "I\Am\The...