Skip to content

Commit b0fee57

Browse files
committed
Merge branch '2.3' into 2.5
* 2.3: Revert "[DependencyInjection] backport perf optim" [WebProfilerBundle] replaced pattern to path attribute in routes definitions. [FrameworkBundle][Template name] avoid error message for the shortcut notation. [DependencyInjection] perf optim: call dirname() at most 5x [DependencyInjection] backport perf optim [2.3] Remove possible call_user_func() Conflicts: src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php
2 parents a2080f5 + 34f3fe6 commit b0fee57

File tree

10 files changed

+53
-10
lines changed

10 files changed

+53
-10
lines changed

Dumper/PhpDumper.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,19 @@ public function dump(array $options = array())
109109
), $options);
110110

111111
if (!empty($options['file']) && is_dir($dir = dirname($options['file']))) {
112-
// Build a regexp where the first two root dirs are mandatory,
112+
// Build a regexp where the first root dirs are mandatory,
113113
// but every other sub-dir is optional up to the full path in $dir
114+
// Mandate at least 2 root dirs and not more that 5 optional dirs.
114115

115116
$dir = explode(DIRECTORY_SEPARATOR, realpath($dir));
116117
$i = count($dir);
117118

118119
if (3 <= $i) {
119120
$regex = '';
120-
$this->targetDirMaxMatches = $i - 3;
121+
$lastOptionalDir = $i > 8 ? $i - 5 : 3;
122+
$this->targetDirMaxMatches = $i - $lastOptionalDir;
121123

122-
while (2 < --$i) {
124+
while (--$i >= $lastOptionalDir) {
123125
$regex = sprintf('(%s%s)?', preg_quote(DIRECTORY_SEPARATOR.$dir[$i], '#'), $regex);
124126
}
125127

@@ -786,6 +788,9 @@ private function startClass($class, $baseClass, $namespace)
786788
*/
787789
class $class extends $baseClass
788790
{
791+
private \$parameters;
792+
private \$targetDirs = array();
793+
789794
EOF;
790795
}
791796

@@ -796,6 +801,7 @@ class $class extends $baseClass
796801
*/
797802
private function addConstructor()
798803
{
804+
$targetDirs = $this->exportTargetDirs();
799805
$arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null;
800806

801807
$code = <<<EOF
@@ -804,7 +810,7 @@ private function addConstructor()
804810
* Constructor.
805811
*/
806812
public function __construct()
807-
{
813+
{{$targetDirs}
808814
parent::__construct($arguments);
809815
810816
EOF;
@@ -833,6 +839,8 @@ public function __construct()
833839
*/
834840
private function addFrozenConstructor()
835841
{
842+
$targetDirs = $this->exportTargetDirs();
843+
836844
$code = <<<EOF
837845
838846
private \$parameters;
@@ -841,7 +849,7 @@ private function addFrozenConstructor()
841849
* Constructor.
842850
*/
843851
public function __construct()
844-
{
852+
{{$targetDirs}
845853
EOF;
846854

847855
if ($this->container->getParameterBag()->all()) {
@@ -1405,6 +1413,17 @@ private function getExpressionLanguage()
14051413
return $this->expressionLanguage;
14061414
}
14071415

1416+
private function exportTargetDirs()
1417+
{
1418+
return null === $this->targetDirRegex ? '' : <<<EOF
1419+
1420+
\$dir = __DIR__;
1421+
for (\$i = 1; \$i <= {$this->targetDirMaxMatches}; ++\$i) {
1422+
\$this->targetDirs[\$i] = \$dir = dirname(\$dir);
1423+
}
1424+
EOF;
1425+
}
1426+
14081427
private function export($value)
14091428
{
14101429
if (null !== $this->targetDirRegex && is_string($value) && preg_match($this->targetDirRegex, $value, $matches, PREG_OFFSET_CAPTURE)) {
@@ -1413,8 +1432,8 @@ private function export($value)
14131432
$suffix = isset($value[$suffix]) ? '.'.var_export(substr($value, $suffix), true) : '';
14141433
$dirname = '__DIR__';
14151434

1416-
for ($i = $this->targetDirMaxMatches - count($matches); 0 <= $i; --$i) {
1417-
$dirname = sprintf('dirname(%s)', $dirname);
1435+
if (0 < $offset = 1 + $this->targetDirMaxMatches - count($matches)) {
1436+
$dirname = sprintf('$this->targetDirs[%d]', $offset);
14181437
}
14191438

14201439
if ($prefix || $suffix) {

Tests/Dumper/PhpDumperTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ public function testDumpRelativeDir()
8585
$definition = new Definition();
8686
$definition->setClass('stdClass');
8787
$definition->addArgument('%foo%');
88-
$definition->addArgument(array('%foo%' => '%foo%'));
88+
$definition->addArgument(array('%foo%' => '%buz%/'));
8989

9090
$container = new ContainerBuilder();
9191
$container->setDefinition('test', $definition);
9292
$container->setParameter('foo', 'wiz'.dirname(dirname(__FILE__)));
9393
$container->setParameter('bar', dirname(__FILE__));
9494
$container->setParameter('baz', '%bar%/PhpDumperTest.php');
95+
$container->setParameter('buz', dirname(dirname(__DIR__)));
9596
$container->compile();
9697

9798
$dumper = new PhpDumper($container);

Tests/Fixtures/php/services1-1.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*/
1818
class Container extends AbstractContainer
1919
{
20+
private $parameters;
21+
private $targetDirs = array();
22+
2023
/**
2124
* Constructor.
2225
*/

Tests/Fixtures/php/services1.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717
class ProjectServiceContainer extends Container
1818
{
19+
private $parameters;
20+
private $targetDirs = array();
21+
1922
/**
2023
* Constructor.
2124
*/

Tests/Fixtures/php/services10.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
class ProjectServiceContainer extends Container
1818
{
1919
private $parameters;
20+
private $targetDirs = array();
2021

2122
/**
2223
* Constructor.

Tests/Fixtures/php/services11.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
class ProjectServiceContainer extends Container
1818
{
1919
private $parameters;
20+
private $targetDirs = array();
2021

2122
/**
2223
* Constructor.

Tests/Fixtures/php/services12.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@
1616
*/
1717
class ProjectServiceContainer extends Container
1818
{
19+
private $parameters;
20+
private $targetDirs = array();
21+
1922
/**
2023
* Constructor.
2124
*/
2225
public function __construct()
2326
{
27+
$dir = __DIR__;
28+
for ($i = 1; $i <= 5; ++$i) {
29+
$this->targetDirs[$i] = $dir = dirname($dir);
30+
}
2431
$this->parameters = $this->getDefaultParameters();
2532

2633
$this->services =
@@ -48,7 +55,7 @@ public function __construct()
4855
*/
4956
protected function getTestService()
5057
{
51-
return $this->services['test'] = new \stdClass(('wiz'.dirname(__DIR__)), array(('wiz'.dirname(__DIR__)) => ('wiz'.dirname(__DIR__))));
58+
return $this->services['test'] = new \stdClass(('wiz'.$this->targetDirs[1]), array(('wiz'.$this->targetDirs[1]) => ($this->targetDirs[2].'/')));
5259
}
5360

5461
/**
@@ -102,9 +109,10 @@ public function getParameterBag()
102109
protected function getDefaultParameters()
103110
{
104111
return array(
105-
'foo' => ('wiz'.dirname(__DIR__)),
112+
'foo' => ('wiz'.$this->targetDirs[1]),
106113
'bar' => __DIR__,
107114
'baz' => (__DIR__.'/PhpDumperTest.php'),
115+
'buz' => $this->targetDirs[2],
108116
);
109117
}
110118
}

Tests/Fixtures/php/services8.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717
class ProjectServiceContainer extends Container
1818
{
19+
private $parameters;
20+
private $targetDirs = array();
21+
1922
/**
2023
* Constructor.
2124
*/

Tests/Fixtures/php/services9.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717
class ProjectServiceContainer extends Container
1818
{
19+
private $parameters;
20+
private $targetDirs = array();
21+
1922
/**
2023
* Constructor.
2124
*/

Tests/Fixtures/php/services9_compiled.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
class ProjectServiceContainer extends Container
1818
{
1919
private $parameters;
20+
private $targetDirs = array();
2021

2122
/**
2223
* Constructor.

0 commit comments

Comments
 (0)