Skip to content

[DI][Preload] Remove preload primitive types #36866

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
May 19, 2020
Merged

[DI][Preload] Remove preload primitive types #36866

merged 1 commit into from
May 19, 2020

Conversation

michaljusiega
Copy link
Contributor

@michaljusiega michaljusiega commented May 19, 2020

Q A
Branch? 5.1
Bug fix? no, but it could be for the future
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

After bump my project to 5.1.x-dev I saw the generated file of *.preload.php contains classes that are primitive types like int, string, bool.

composer create-project symfony/website-skeleton preload "5.1.x-dev"
cat preload/var/cache/dev/App_KernelDevDebugContainer.preload.php | grep "bool\|string\|int"
$ cat test/var/cache/dev/App_KernelDevDebugContainer.preload.php | grep "bool\|string\|int"
$classes[] = 'int';
$classes[] = 'string';
$classes[] = 'Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator';
$classes[] = 'Symfony\Component\Security\Http\EntryPoint\RetryAuthenticationEntryPoint';
$classes[] = 'Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator';
$classes[] = 'Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer';
$classes[] = 'bool';
$classes[] = 'Symfony\Component\Validator\ContainerConstraintValidatorFactory';
$classes[] = 'Symfony\Component\Validator\Constraints\EmailValidator';
$classes[] = 'Symfony\Component\Validator\Constraints\ExpressionValidator';
$classes[] = 'Symfony\Component\Validator\Constraints\NotCompromisedPasswordValidator';
$classes[] = 'Symfony\\Component\\Form\\Extension\\Validator\\Constraints\\Form';

I don't know if it is expected behaviour, but if not - then PR fix it.

In addition, classes are sorted for better reading.

@nicolas-grekas nicolas-grekas added this to the 5.1 milestone May 19, 2020
@nicolas-grekas
Copy link
Member

Thank you @michaljusiega.

@nicolas-grekas nicolas-grekas merged commit 754bba4 into symfony:5.1 May 19, 2020
@michaljusiega michaljusiega deleted the preloading branch May 19, 2020 17:09
nicolas-grekas added a commit that referenced this pull request Feb 10, 2025
This PR was squashed before being merged into the 6.4 branch.

Discussion
----------

[DependencyInjection] Do not preload functions

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| License       | MIT

Ensure `preload.php` does not have functions in preloaded class names:
```
$ grep "current" var/cache/prod/App_KernelProdContainer.preload.php
$classes[] = 'current';
```

Happens because the DI declares a factory, which uses built-in `\current`: https://github.com/symfony/symfony/blob/v6.4.18/src/Symfony/Bundle/FrameworkBundle/Resources/config/http_client.php#L39
And then the "class" is added by https://github.com/symfony/symfony/blob/v6.4.18/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L2317

Similar to the #36866

Commits
-------

b52b760 [DependencyInjection] Do not preload functions
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