bug #34757 [DI] Fix making the container path-independent when the app is in /app (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Fix making the container path-independent when the app is in /app

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34750, Fix #34611
| License       | MIT
| Doc PR        | -

Right now, we mandate the app to be nested in a directory of level 2 minimum. This means apps cannot be made path-independent if they are built in e.g. `/app`.

Commits
-------

b33b9a6ad9 [DI] Fix making the container path-independent when the app is in /app
This commit is contained in:
Fabien Potencier 2019-12-02 16:27:49 +01:00
commit 30294c477d

View File

@ -173,14 +173,14 @@ class PhpDumper extends Dumper
if (!empty($options['file']) && is_dir($dir = \dirname($options['file']))) {
// 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.
// Mandate at least 1 root dir and not more than 5 optional dirs.
$dir = explode(\DIRECTORY_SEPARATOR, realpath($dir));
$i = \count($dir);
if (3 <= $i) {
if (2 + (int) ('\\' === \DIRECTORY_SEPARATOR) <= $i) {
$regex = '';
$lastOptionalDir = $i > 8 ? $i - 5 : 3;
$lastOptionalDir = $i > 8 ? $i - 5 : (2 + (int) ('\\' === \DIRECTORY_SEPARATOR));
$this->targetDirMaxMatches = $i - $lastOptionalDir;
while (--$i >= $lastOptionalDir) {