Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DependencyInjection] Added a way to define the priority of service decoration#15416

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

Merged
fabpot merged 1 commit intosymfony:2.8fromdosten:dependency-injection/service-decoration-priority
Aug 5, 2015
Merged

[DependencyInjection] Added a way to define the priority of service decoration#15416

fabpot merged 1 commit intosymfony:2.8fromdosten:dependency-injection/service-decoration-priority
Aug 5, 2015

Conversation

dosten
Copy link
Contributor

QA
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#10634
LicenseMIT
Doc PRsymfony/symfony-docs#5600

This PR adds a way to define the priority of service decoration, so, the service with the highest priority will be applied first (the default priority is zero).

services:foo:class:Foobar:class:Bararguments:['@bar.inner']decorates:foopublic:falsefoobar:class:Foobararguments:['@foobar.inner']decorates:foodecoration_priority:1public:false

This will result in this code:

$this->services['foo'] =newBar(newFoobar(newFoo)));

@dupuchba
Copy link
Contributor

@dosten can you give a use case for prioritizing service's decorator ? I fail to understand :-)

@stof
Copy link
Member

@dupuchba controlling the order in which multiple decorators for the same service are applied.new Bar(new Foobar(new Foo))) andnew Foobar(new Bar(new Foo))) can lead to a totally different behavior at runtime. And without that, the order in which decorators are applied is undetermined (deterministic but not controllable)

@stof
Copy link
Member

btw, the issue requesting the change explains it already

*/
class DecoratorServicePass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$definitions = new \SplPriorityQueue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The usage of a priority query is a BC break here. Currently, decorators with the same priority (i.e. all of them for now) are applied in the order in which they appear in$container->getDefinitions(), which is more or less the order in which services have been defined (it is a bit more complex when a service gets overridden actually). but a SplPriorityQueue does not retain the order of insertion for the same priority.

And this is inconsistent with all other places using priorities in Symfony as we preserve the insertion order when the priority is the same.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@stof Thanks for your feedback, I missed up that part of the documentation. Using arrays andkrsort is the way to go?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@stof Can you check again? I've implemented the same solution ofProfilerPass.

@dosten
Copy link
ContributorAuthor

ping

@xabbuh
Copy link
Member

👍 looks good to me

@stof
Copy link
Member

stof commentedAug 5, 2015

👍

Please submit a PR to the documentation repo to document this new feature for the 2.8 branch

@dosten
Copy link
ContributorAuthor

IMO this can be labeled as reviewed, right?

@stof 👍

@dosten
Copy link
ContributorAuthor

The docs PR can be foundhere.

@stofstof added the Ready labelAug 5, 2015
@stof
Copy link
Member

stof commentedAug 5, 2015

@dosten indeed. note that anyone can trigger the status change thanks to@carsonbot (the update of the doc to describe our goals with it is not yet ready unfortunately)

status: reviewed

@dosten
Copy link
ContributorAuthor

@stof Yes, I know, but I feel unconfortable changing the status by myself.

@timglabisch
Copy link

👍

@stof
Copy link
Member

stof commentedAug 5, 2015

@dosten ah yeah, being the PR author, this seems fair to let someone else change. We have plans to implement a restriction about that in the bot itself in the future. I missed the fact you are the author when I commented

@fabpot
Copy link
Member

Thank you@dosten.

@fabpotfabpot merged commit75c98cb intosymfony:2.8Aug 5, 2015
fabpot added a commit that referenced this pull requestAug 5, 2015
…ty of service decoration (dosten)This PR was merged into the 2.8 branch.Discussion----------[DependencyInjection] Added a way to define the priority of service decoration| Q             | A| ------------- | ---| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#10634| License       | MIT| Doc PR        |symfony/symfony-docs#5600This PR adds a way to define the priority of service decoration, so, the service with the highest priority will be applied first (the default priority is zero).```yamlservices:    foo:        class: Foo    bar:        class: Bar        arguments: ['@bar.inner']        decorates: foo        public: false    foobar:        class: Foobar        arguments: ['@foobar.inner']        decorates: foo        decoration_priority: 1        public: false```This will result in this code:```php$this->services['foo'] = new Bar(new Foobar(new Foo)));```Commits-------75c98cb Added a way to define the priority of service decoration
@dostendosten deleted the dependency-injection/service-decoration-priority branchAugust 5, 2015 16:40
@fabpotfabpot mentioned this pull requestNov 16, 2015
xabbuh added a commit to symfony/symfony-docs that referenced this pull requestJan 13, 2016
…the service decoration priority (dosten)This PR was merged into the 2.8 branch.Discussion----------[DependencyInjection] Documented the ability of define the service decoration priority| Q             | A| ------------- | ---| Doc fix?      | no| New docs?     | yes (symfony/symfony#15416)| Applies to    | 2.8+Commits-------5868190 Documented the ability of define service decoration priority
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@dosten@dupuchba@stof@xabbuh@timglabisch@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp