8000 [DependencyInjection] make paths relative to __DIR__ in the generated container by nicolas-grekas · Pull Request #12784 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] make paths relative to __DIR__ in the generated container #12784

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
Dec 2, 2014

Conversation

nicolas-grekas
Copy link
Member
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #6484, #3079, partially #9238, #10894, #10999
License MIT
Doc PR n/a

This is an alternative approach to #10999 for removing absolute paths from the generated container:
instead of trying to fix the container file after it has been dumped, telling to the PhpDumper where its output will be written allows it to replace parts of strings by an equivalent value based on __DIR__.
This should be safe, thus the PR is on 2.3.

@nicolas-grekas nicolas-grekas force-pushed the relative-kernel-dir branch 2 times, most recently from c528404 to e53b716 Compare December 1, 2014 08:16
@nicolas-grekas
Copy link
Member Author

Tests added, this PR is ready for review/merge

@nicolas-grekas nicolas-grekas force-pushed the relative-kernel-dir branch 2 times, most recently from 61ec8b1 to bfff3b7 Compare December 1, 2014 09:11
@nicolas-grekas nicolas-grekas changed the title [HttpKernel] make paths relative to __DIR__ in the generated container [DependencyInjection] make paths relative to __DIR__ in the generated container Dec 1, 2014
$suffix = $matches[0][1] + strlen($matches[0][0]);
$suffix = isset($value[$suffix]) ? '.'.var_export(substr($value, $suffix), true) : '';
$dirname = '__DIR__';
for ($i = $this->targetDirMaxMatches - count($matches); 0 <= $i; --$i) {
Copy link
Member

Choose a reason for hiding this comment

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

Minor comment: don't you think that a new line above this could improve code legibility?

@nicolas-grekas nicolas-grekas force-pushed the relative-kernel-dir branch 2 times, most recently from 4a3d116 to b6d8881 Compare December 1, 2014 12:50
@nicolas-grekas
Copy link
Member Author

Comments addressed, Windows support should be OK

@@ -101,13 +113,13 @@ public function testAddService()
// without compilation
$container = include self::$fixturesPath.'/containers/container9.php';
$dumper = new PhpDumper($container);
$this->assertEquals(str_replace('%path%', str_replace('\\','\\\\',self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9.php')), $dumper->dump(), '->dump() dumps services');
$this->assertEquals(str_replace('%path%', str_replace('\\', '\\\\', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9.php')), $dumper->dump(), '->dump() dumps services');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this str_replace still necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it is: __DIR__ relative paths is an opt-in feature, that is not used here, but only in the new test (see 'file' option when calling dump())

@fabpot
Copy link
Member
fabpot commented Dec 1, 2014

👍

I've just tested on Heroku and indeed, that fixes the problem we have currently. ping @dzuelke

@fabpot
Copy link
Member
fabpot commented Dec 1, 2014

Failing tests do not seem to be related to these changes.

@fabpot
Copy link
Member
fabpot commented Dec 1, 2014

As I will have to release 2.6.1 soon, I'd really like to include this PR. ping @symfony/deciders

@stof
Copy link
Member
stof commented Dec 1, 2014

Does this work properly for people symlinking their cache folder to a different place ?

@nicolas-grekas
Copy link
Member Author

It will work properly but without __DIR__ relative paths, because the search-and-replaced pattern, being realpath'ed, won't match values in strings (that are not realpath'ed)

@stof
Copy link
Member
stof commented Dec 1, 2014

this seems an acceptable option.

@stof
Copy link
Member
stof commented Dec 1, 2014

Your new test does not rely on any path dumped in service arguments (inlined parameter values). Could you add some to avoid regressions ?

@nicolas-grekas
Copy link
Member Author

Test updated

do {
$rx = preg_quote(DIRECTORY_SEPARATOR.$dir[$i], '#').$rx;
} while (0 < --$i);
$this->targetDirRegex = '#'.preg_quote($dir[0], '#').$rx.'#';
Copy link
Member

Choose a reason for hiding this comment

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

will this logic work for the Symfony 3.0 directory structure where the cache is in var/cache/dev/.... rather 8000 than app/cache/dev ?

and I think this deserves a comment explaining the goal of this logic

Copy link
Member Author

Choose a reason for hiding this comment

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

comments added, the logic is not specific to any dir scheme, so yes, it will

@kbond kbond mentioned this pull request Dec 8, 2014
fabpot added a commit that referenced this pull request Dec 11, 2014
This PR was merged into the 2.3 branch.

Discussion
----------

[DependencyInjection] Perf php dumper

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This PR came up after this comment to reduce the number of calls to dirname():
#12784 (comment)

Commits
-------

375f83e Revert "[DependencyInjection] backport perf optim"
fcd8ff9 [DependencyInjection] perf optim: call dirname() at most 5x
c11535b [DependencyInjection] backport perf optim
desyncr pushed a commit to desyncr/heroku-buildpack-php that referenced this pull request Dec 18, 2014
[hack] Hacking jms serialization for heroku
[hack] Hacking symfony cache due to symfony/symfony#12893 / see symfony/symfony#12784
desyncr pushed a commit to desyncr/heroku-buildpack-php that referenced this pull request Dec 19, 2014
[hack] Hacking jms serialization for heroku
[hack] Hacking symfony cache due to symfony/symfony#12893 / see symfony/symfony#12784
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0