Skip to content

Update event_dispatcher.rst #14053

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

Merged
merged 1 commit into from
Sep 25, 2020
Merged

Update event_dispatcher.rst #14053

merged 1 commit into from
Sep 25, 2020

Conversation

yivi
Copy link
Contributor

@yivi yivi commented Aug 11, 2020

Update code example to match 5.1 PHP configuration format.

Update code example to match 5.1 PHP configuration format.
@javiereguiluz
Copy link
Member

Thanks for this contribution. However, in the Symfony Docs we use one of these two formats:

// config/services.php

$container->register('...')->...

or

// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container) {
    $container->register('...')->...
};

We should update the docs to only use the first format, but your PR introduces a different format, so that's why I'm closing this without merging. If I missed something, please tell me and I'll reopen. Thanks!

@yivi
Copy link
Contributor Author

yivi commented Sep 9, 2020

I apologize Javier, I must be confused.

But when I see the docs, for example here, neither of the formats you mention is being used

My PR attempted to have this part of the documentation consistent with the main documentation for service configuration.

Check the difference:
https://symfony.com/doc/current/service_container.html#service-parameters
imagen

vs.
https://symfony.com/doc/current/event_dispatcher.html#creating-an-event-listener
imagen

The styles are inconsistent, and a person following the main services configuration and encountering this style on the Event Dispatcher page can be easily confused. I've seen it happening and it happened to me. Since my services.php configuration file follows the format suggested in the main Service Container configuration, the docs on Event Dispatcher simply does not make sense.

@yivi
Copy link
Contributor Author

yivi commented Sep 9, 2020

Also, Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator::register() does not exist.

If in other places of the documentation this is done:

// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container) {
    $container->register('...')->...
};

... that's a fatal error. Because it's calling an undefined method. It does look closer to actually working code, and one that's easier to understand (as the one in the in the main Service Container configuration), but it's critically missing the call to services(), and to set('service') on the result.

(I think that you may mean Symfony\Component\DependencyInjection\ContainerBuilder::register(), but that's called on a different context, not inside the services configuration file)

Thanks, kind regards.

@yivi
Copy link
Contributor Author

yivi commented Sep 11, 2020

@javiereguiluz Please, if you can let me know if my previous comments make sense.

@javiereguiluz
Copy link
Member

Let me reopen this to review it again.

@javiereguiluz javiereguiluz reopened this Sep 11, 2020
@javiereguiluz javiereguiluz merged commit 6afd6a7 into symfony:5.1 Sep 25, 2020
@javiereguiluz
Copy link
Member

Ivan, this is now merged! However, we had to do some tweaks (see 03f119a) to match the style we use in other similar code examples. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants