-
Notifications
You must be signed in to change notification settings - Fork 23
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
Convert paths into Mapping objects #49
base: 1.x
Are you sure you want to change the base?
Conversation
This function can convert an array of paths into an array of Mapping objects by reflecting on declared classes, just as the AnnotationDriver does.
[ci skip] [skip ci]
|
||
$mappings = []; | ||
$declared = get_declared_classes(); | ||
foreach ($declared as $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.
@patrickbrouwers moved inner loop outside the $paths
loop, so it recursively iterates all paths, then iterates over declared classes once.
foreach ($declared as $className) { | ||
$rc = new ReflectionClass($className); | ||
$sourceFile = $rc->getFileName(); | ||
if ($sourceFile === false || !array_key_exists($sourceFile, $includedFiles)) { |
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.
@patrickbrouwers switched to key check instead of in_array
. Had to use the boolean check to avoid php native classes crashing the array_key_exists
check.
@@ -36,6 +36,7 @@ | |||
"gedmo/doctrine-extensions": "^2.4" | |||
}, | |||
"autoload": { | |||
"files": ["src/helpers.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.
@patrickbrouwers there's no other way to load functions, right? I couldn't find documentation of namespaced functions in composer docs.
Oh, this probably breaks in php 5.5, so we should bump anyway.
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.
Commited bump in here so travis doesn't fail on phpunit run.
{ | ||
$includedFiles = []; | ||
|
||
foreach ($paths as $path) { |
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.
@patrickbrouwers I'm pretty sure we should be able to replace this loop with another iterator, so that we iterate recursively over each path, instead of building the full iterator chain for each path in the array.
@guiwoda Any reason why this wasn't merged? |
This PR adds a function that can convert an array of paths into an array of Mapping objects by reflecting on declared classes, just as the AnnotationDriver does.
The FluentDriver API is almost unchanged. To support receiving already-instanced Mapping objects, the
addMapping
methods had to be relaxed. Took the opportunity to refactor that relaxation to the lowest-level method, but this could be rolled back if BC matters.We are debating between this and #48 😄