PhpAnalyzer
class PhpAnalyzer (View source)
This utility class can be used to extract information about PHP files without having to instantiate/reflect classes.
Usage:
// extract the FQN e.g. "Some\Namespace\SomeClassName" $fullyQualifiedClassName = (new PhpAnalyzer($fileContents))->extractFullyQualifiedClassName();
// extract the namespace "Some\Namespace" $namespace = (new PhpAnalyzer($fileContents))->extractNamespace();
// extract just the class name "SomeClassName" $className = (new PhpAnalyzer($fileContents))->extractClassName();
Properties
protected string | $phpCode |
Methods
No description
Extracts the Fully Qualified Class name from the given PHP code
Extracts the PHP namespace from the given PHP code
Extracts the className of the given PHP code Note: This only returns the class name without namespace, extractFullyQualifiedClassName()
Details
__construct(string $phpCode)
No description
string|null
extractFullyQualifiedClassName()
Extracts the Fully Qualified Class name from the given PHP code
string|null
extractNamespace()
Extracts the PHP namespace from the given PHP code
string|null
extractClassName()
Extracts the className of the given PHP code Note: This only returns the class name without namespace, extractFullyQualifiedClassName()