-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored entire Reflector to be more flexible #3
Conversation
```php | ||
<?php | ||
|
||
$reflector = new Reflector(new FilenameSourceLocator('path/to/MyApp/MyClass.php')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per discussion, FilenameSourceLocator
should probably be something like InSingleFileSourceLocator
Reflector
to use a SourceLocator
to load classes/files/codeReflector
to use a SourceLocator
to load classes/files/code
} | ||
|
||
/** | ||
* @param $className |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string?
*/ | ||
public function getAllByIdentifierType(IdentifierType $identifierType) | ||
{ | ||
$identifier = new Identifier('*', $identifierType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored entire Reflector to be more flexible
Initial Changes
new Reflector
now requires something implementingSourceLocator
interfaceSourceLocator
interface has a single method that should return a value objectLocatedSource
LocatedSource
VO is used to load the class requested internally byReflector
Reflector
is now much simpler, and only has:$reflector->reflect($className)
$reflector->getClassesFromFile()
(only works whenFilenameSourceLocator
)SourceLocator
-implementing classes:ComposerSourceLocator
- has a constructor dependency onComposer\Autoload\ClassLoader
FilenameSourceLocator
- constructor dep is the filename as a stringStringSourceLocator
- constructor dep is valid PHP code in a stringREADME.md
is updated to show example usage of creating theReflectionClass
instancesReflector::compileNodeExpression
was moved to own classNodeCompiler::compile
for easier refactoring laterMethodsTest
fixture as PHPUnit was loading the fileRefactored changes
Symbol
VO that identifies a symbol with a name and type (checks types are valid)Reflector
to use theSymbol
to generically identify "symbols" (instead of just classes)Reflector::getClassesFromFile
withReflector::getAllSymbols
to be more generic and also fixes Replace getClassesFromFile with a better API for getAllClasses #4BetterReflection\Reflection\Reflection
interface that identifies symbols that can be reflected (currently onlyReflectionClass
)ClassReflector
which simplfies the API to calling$reflector->reflect(..)
so externally, users don't have to worry about creatingSymbol
s etc.. In future, we can createFunctionReflector
,TraitReflector
and so on.Todo
SourceLocator
somehow to accomodate for other types of symbols: