Skip to content

[DependencyInjection] Always preload services classes tagged with container.preload #36742

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

Closed
wants to merge 1 commit into from

Conversation

fancyweb
Copy link
Contributor

@fancyweb fancyweb commented May 7, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR -

This PR aims to solve the case where you want to force the preload of a service class even if the service definition has the container.no_preload tag.

For example, in RegisterListenersPass, we add the container.no_preload tag on definitions that listen to some particular events. What if I want to force the preload of those services classes anyway?

Adding the container.preload tag does not work because the "no preload" behavior has the priority. I propose to change that so one can simply add the tag when he wants to override Symfony's default behavior.

Moreover, to not repeat the service class on the container.preload class attribute, let's make this attribute optional. When it's not there, it means I want to preload the service class.

@fancyweb fancyweb changed the title [DependencyInjection] Preload services classes tagged with container.preload [DependencyInjection] Always preload services classes tagged with container.preload May 7, 2020
@fancyweb fancyweb force-pushed the di-preload-priority branch from 8e51723 to 6a65742 Compare May 7, 2020 16:27
if ('\\' === \DIRECTORY_SEPARATOR) {
$dump = str_replace('\\\\Fixtures\\\\includes\\\\foo.php', '/Fixtures/includes/foo.php', $dump);
}
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/services9_as_files.txt', $dump);
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services9_as_files.txt', $dump);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't use a regex anymore because the file to compare to have become too big (preg_match(): Compilation failed: regular expression is too large at offset 35752). I guess this strategy is useful when merging from lower branches? Do someone have a better idea than strict comparison or creating a new file? 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests are failing: I need to recheck the strategy.

@@ -193,4 +193,13 @@
->addTag('container.preload', ['class' => 'Some\Sidekick1'])
->addTag('container.preload', ['class' => 'Some\Sidekick2']);

$container->register('no_preload', 'TestNoPreload')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also added a test with container.no_preload as I think it was not tested.

@nicolas-grekas
Copy link
Member

I feel like we might not need this PR after #36749

At least the case we built this solution for (ConsoleHandler) is fixed by it. And if we don't have a use case anymore, it's better to not do this I realize now.

Agreed?

@fancyweb
Copy link
Contributor Author

fancyweb commented May 9, 2020

I agree, it's better.

@fancyweb fancyweb closed this May 9, 2020
@fancyweb fancyweb deleted the di-preload-priority branch May 11, 2020 13:20
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