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

[Messenger] Allow to override only a few of the abstract middleware definition#29034

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

Conversation

@sroze
Copy link
Contributor

QA
Branch?master
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#29006
LicenseMIT
Doc PRø

The recent PR about the traceable middleware introduced an issue. This PR fixes it by enabling us to override only some parameters of the parent service.

@srozesrozeforce-pushed themessenger-partial-parent-middleware-arguments branch fromc9b4d87 toc9ab7baCompareOctober 30, 2018 21:15
@srozesroze requested review fromnicolas-grekas,ogizanagi andstof and removed request forstofOctober 30, 2018 21:15
@nicolas-grekas
Copy link
Member

I think there is a better way, seehttps://github.com/symfony/symfony/pull/29010/files#r229492831

@nicolas-grekasnicolas-grekas added this to the4.2 milestoneOct 30, 2018
ogizanagi
ogizanagi previously approved these changesOct 30, 2018
Copy link
Contributor

@ogizanagiogizanagi left a comment

Choose a reason for hiding this comment

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

Good catch. Just really minor comments.

$container =$this->getContainerBuilder($fooBusId ='messenger.bus.foo');
$container->register('middleware_with_factory', UselessMiddleware::class)->addArgument('some_default')->setAbstract(true);
$container->register('middleware_with_factory_using_default', UselessMiddleware::class)->addArgument('some_default')->setAbstract(true);
$container->register('middleware_with_factory_using_a_lot_of_defaults', UselessMiddleware::class)->setArguments(array('one','two','three'))->setAbstract(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

middleware_with_factory_replacing_defaults_by_index ? 😅 ("Using a lot of defaults" doesn't really convey the intent here)

$this->assertEquals(
array('one','2','three','four'),
$container->getDefinition($factoryWithALotOfDefaultsChildMiddlewareId)->getArguments(),
'parent arguments are not overwritten'
Copy link
Contributor

Choose a reason for hiding this comment

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

parent arguments are overwritten by index, and next ones appended

@nicolas-grekas
Copy link
Member

@ogizanagi see my comment linked above. I don't think we should follow this path.

@ogizanagi
Copy link
Contributor

ogizanagi commentedOct 30, 2018
edited
Loading

@nicolas-grekas : Continuing the discussion here, as it's seems more scoped here.

all this logic should be removed: ChildDefinition already have their merging logic. Overwriting an existing parent argument is done by using index_0 as a key. Let's make things simpler by reusing existing knowledge.

The current logic typically allows this:https://symfony.com/doc/current/messenger.html#using-middleware-factories
Unless I miss something, your suggestion will require writing:

# config/packages/messenger.yamlframework:messenger:buses:command_bus:middleware:                    -doctrine_transaction_middleware:['index_0' => 'custom']

to change the entity manager name.

The idea of such factories was to expose simple config for middlewares. Not leaking Symfony's DIC specificities into it.

@ogizanagi
Copy link
Contributor

But actually, I'm not fan of this PR allowing to replace any argument by index through the config, just for fixing this issue.
The middleware factory args mimic defaults in a PHP function. I.e, given:

function foo($bar ='foo',$baz =3,$qux =null);

either you're satisfied with defaults and usefoo(),
either you need to change a value, i.e$baz and usefoo('foo', 5), notfoo($baz=5). And it's fine to me here.

So about this issue, I'd suggest a more pragmatic approach:#29038

@ogizanagiogizanagi dismissed theirstale reviewOctober 31, 2018 07:13

Cf previous comment

@nicolas-grekas
Copy link
Member

👎 let's kill these workarounds on top of hacks. We need to play by the rules of the definition inheritance, not against.

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedOct 31, 2018
edited
Loading

doctrine_transaction_middleware: ['index_0' => 'custom']

nope: my suggestion is to makedoctrine_transaction_middleware: ['custom'] work.
This can easily be done by playing the rules of definition inheritance: the bus name should be undefined in the parent definition, and be the first next argument in the constructor definition.

@nicolas-grekas
Copy link
Member

Already fixed in#29010 (comment) byremoving special edge cases, instead of adding more ;)

@srozesroze closed thisOct 31, 2018
@srozesroze deleted the messenger-partial-parent-middleware-arguments branchOctober 31, 2018 07:55
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasAwaiting requested review from nicolas-grekas

1 more reviewer

@ogizanagiogizanagiogizanagi left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

4 participants

@sroze@nicolas-grekas@ogizanagi@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp