Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[DI][DX] Allow exclude to be an array of patterns#27075
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
a879aad to029b553Comparelinaori commentedApr 27, 2018
Ah nice, this will make life a lot easier for complex exclusion rules in existing codebases! |
nicolas-grekas left a comment
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.
looks great, thanks for taking over!
| if (null !==$definition =$this->parseDefinition($service,$file,$defaults)) { | ||
| if ('prototype' ===$service->tagName) { | ||
| $this->registerClasses($definition, (string)$service->getAttribute('namespace'), (string)$service->getAttribute('resource'), (string)$service->getAttribute('exclude')); | ||
| $excludes =array_map(function ($node) {return$node->nodeValue; },$this->getChildren($service,'exclude')); |
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.
would array_column work here instead of array_map?
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.
nope. We need a property access, not an array access
| if ($service->hasAttribute('exclude')) { | ||
| $excludes[] = (string)$service->getAttribute('exclude'); | ||
| } | ||
| $this->registerClasses( |
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.
should be kept on one line - it would better fit our CS IMHO
| $definition, | ||
| (string)$service->getAttribute('namespace'), | ||
| (string)$service->getAttribute('resource'), | ||
| (array)$excludes |
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.
it's already an array, no need to cast I suppose
| if ('prototype' ===$service->tagName) { | ||
| $this->registerClasses($definition, (string)$service->getAttribute('namespace'), (string)$service->getAttribute('resource'), (string)$service->getAttribute('exclude')); | ||
| $excludes =array_map(function ($node) {return$node->nodeValue; },$this->getChildren($service,'exclude')); | ||
| if ($service->hasAttribute('exclude')) { |
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.
I would allow only tags XOR attribute (like done in similar cases in the loader AFAIK
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.
So in cas both are present, should I throw an exception?
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.
I would say yes
TomasVotruba commentedMay 1, 2018
This is awesome, great job! |
3a287e2 to246640fComparemagnetik commentedMay 2, 2018
I've updated the PR according to the changes. I'll do a PR for symfony doc too if needed. |
| $excludes =array_column($this->getChildren($service,'exclude'),'nodeValue'); | ||
| if ($service->hasAttribute('exclude')) { | ||
| if (count($excludes) >0) { | ||
| thrownewInvalidArgumentException('You cannot use both attribute "exclude" and <exclude> tags at the same time.'); |
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.
both the "exclude" attribute and ...
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.
done
nicolas-grekas left a comment
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.
(would be OK on 4.1 on my side, the topic has been on the table for a few months already).
ogizanagi left a comment
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.
Same, would be great to have this in 4.1. We already missed the opportunity to have it in 3.4/4.0.
Thanks for taking over@magnetik .
chalasr left a comment
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.
👍 for 4.1
| * @param Definition$prototype A definition to use as template | ||
| * @param string$namespace The namespace prefix of classes in the scanned directory | ||
| * @param string$resource The directory to look for classes, glob-patterns allowed | ||
| * @param string|string[]|null $excludeA globed path of files toexcludeor an array ofglobedpaths of files to exclude |
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.
globbed? (not sure but I think so)
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.
done (both occurrences)
fabpot commentedMay 9, 2018
Thank you@magnetik. |
…netik)This PR was merged into the 4.2-dev branch.Discussion----------[DI][DX] Allow exclude to be an array of patterns| Q | A| ------------- | ---| Branch? | 4.2| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#23956| License | MITThis is basically continuing#24428.In YAML before:```yamlAppBundle\: resource: '../../src/AppBundle/*' exclude: '../../src/AppBundle/{Entity,Payload,Repository}'```in YAML after:```yamlAppBundle\: resource: '../../src/AppBundle/*' exclude: - '../../src/AppBundle/{Entity,Payload,Repository}' - '../../src/AppBundle/Event/*Event.php'```In XML before:```xml<prototype namespace="App\" resource="../src/*" exclude="../src/{Entity,Migrations,Tests}" />```in XML after:```xml<prototype namespace="App\" resource="../src/*"> <exclude>../src/{Entity,Migrations,Tests}</exclude> <exclude>../src/Yolo</exclude></prototype>```In PHP before:```php$di->load(Prototype::class.'\\', '../Prototype') ->autoconfigure() ->exclude('../Prototype/{OtherDir,BadClasses}')```In PHP after:```php $di->load(Prototype::class.'\\', '../Prototype') ->autoconfigure() ->exclude(['../Prototype/OtherDir', '../Prototype/BadClasses'])```Everything is backward compatible.Maybe a decision about handling both attribute exclude and element exclude in XML should be taken.Commits-------3ae3a03 [DI][DX] Allow exclude to be an array of patterns (taking#24428 over)
Uh oh!
There was an error while loading.Please reload this page.
This is basically continuing#24428.
In YAML before:
in YAML after:
In XML before:
in XML after:
In PHP before:
In PHP after:
Everything is backward compatible.
Maybe a decision about handling both attribute exclude and element exclude in XML should be taken.