-
-
Notifications
You must be signed in to change notification settings - Fork 165
Correctly support the default callback on tagged services #8361
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 8000 to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
The default
field does not work the same way as the callback fields. It only supports a value or an instance of Closure
:
contao/core-bundle/contao/drivers/DC_Table.php
Lines 738 to 745 in e55f40a
$default = $v['default']; | |
if ($default instanceof \Closure) | |
{ | |
$default = $default($this); | |
} | |
$this->set[$k] = \is_array($default) ? serialize($default) : $default; |
And an array with object and method does not match this requirement: https://3v4l.org/QKX9q It would simply be serialized to a string.
Should we fix this to support an array like any other callback in the DCA then? |
That would be a new feature then, wouldn't it? |
Yes and it would conflict with currently allowed values. 680120c should fix this by wrapping in a closure. |
I'm not sure about his. Why do we have to handle arrays at all costs? Value or closure has worked fine so far. @contao/developers /cc |
I think for consistency all DCA callbacks should work the same. But the current state of this PR doesn't change this anyway, does it? For |
No, the PR adds support for arrays by wrapping them into a closure (see line 73). |
Yes - what I mean is: even if this PR is merged, you still cannot do this: 'default' => [MyService::class, '__invoke'], i.e. the PR does not add inherent support for arrays for the |
It does not? But there is a unit test for exactly this case 🤔 |
The unit test only tests the compiler pass for the The implementation in |
yes, it does not change DC_Table. But service callbacks are always arrays, which are not supported here. So we must wrap them to actually support them. |
4af806c
to
82b6ef8
Compare
I have added three more options in 82b6ef8. Currently, the callback registering tries to be clever to automatically detect stuff. However, that is sometimes problematic. Here are the tree options:
We could argue these are new features, let me know what you think. I can rebase the whole PR or just these options. But imho the current state is kinda broken because you cannot register all cases through the service container, which I just ran into with MultiColumnWizards |
Thank you @aschempp. |
see #8340