Description
Symfony version(s) affected: 4.4.x and 5.x
The issue was detected on Platform.sh using PHP 7.4 trying to enable the Preloading support.
Description
On Platform.sh the file var/cache/prod/srcApp_KernelProdContainer.preload.php
is NOT generated when it is working locally.
How to reproduce
Just deploy an empty app on Platform.sh.
OR (and the following explanation will explain why)
- Install Symfony locally in your root directory
/
- run
bin/console
- check the cache directory,
- you will see that the preload file is NOT generated
Reasons
This is happening for 3 combined reasons:
- first on Platform.sh (and I guess Symfony Cloud) application is installed in
/app
- https://github.com/symfony/symfony/pull/33529/files/2eae30053766181acd502a11bcf8689a335d26bf#diff-f7b23d463cba27ac5e4cb677f2be7623
- https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L203
The return of getAutoloadFile
is always null is this context.
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L306
And that is even explained in the code:
// Build a regexp where the first root dirs are mandatory,
// but every other sub-dir is optional up to the full path in $dir
// Mandate at least 2 root dirs and not more that 5 optional dirs.
Traces that explain the bug better
preg_match
: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L2055
When it works:
string(54) "ComposerAutoloaderInit7a88e581ff3256a1c9451ad0a87173b8"
string(65) "/Users/plopix/DOCKFILES/NOVACTIVE/INTERNAL/XXX/application/vendor"
string(78) "/Users/plopix/DOCKFILES/NOVACTIVE/INTERNAL/XXX/application/vendor/autoload.php"
string(90) "#/Users/plopix/DOCKFILES/NOVACTIVE/INTERNAL(/XXX(/application(/var(/cache(/dev)?)?)?)?)?#A"
here the preg_match
works
When it DOES NOT work (on Platform.sh):
string(54) "ComposerAutoloaderInitb7e173ef0544858adc8ec39ee3ef34c1"
string(11) "/app/vendor"
string(24) "/app/vendor/autoload.php"
string(28) "#/app/var(/cache(/pro_)?)?#A"
here the preg_match
DOES NOT work
Solutions
That is a bit deep in the stack and I don't know enough to propose something. But if you tell me I could do it ;)
ping @nicolas-grekas