8000 Revert "[DependencyInjection] backport perf optim" · symfony/symfony@375f83e · GitHub
[go: up one dir, main page]

Skip to content

Commit 375f83e

Browse files
Revert "[DependencyInjection] backport perf optim"
This reverts commit c11535b. Conflicts: src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php src/Symfony/Component/D 8000 ependencyInjection/Tests/Fixtures/php/services10.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php
1 parent fcd8ff9 commit 375f83e

File tree

10 files changed

+179
-54
lines changed

10 files changed

+179
-54
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ private function startClass($class, $baseClass)
767767
class $class extends $baseClass
768768
{
769769
private \$parameters;
770-
private \$targetDirs;
770+
private \$targetDirs = array();
771771
772772
EOF;
773773
}
@@ -779,8 +779,8 @@ class $class extends $baseClass
779779
*/
780780
private function addConstructor()
781781
{
782-
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
783782
$targetDirs = $this->exportTargetDirs();
783+
$arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null;
784784

785785
$code = <<<EOF
786786
@@ -789,9 +789,7 @@ private function addConstructor()
789789
*/
790790
public function __construct()
791791
{{$targetDirs}
792-
\$this->parameters = $parameters;
793-
794-
parent::__construct(new ParameterBag(\$this->parameters));
792+
parent::__construct($arguments);
795793
796794
EOF;
797795

@@ -819,7 +817,6 @@ public function __construct()
819817
*/
820818
private function addFrozenConstructor()
821819
{
822-
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
823820
$targetDirs = $this->exportTargetDirs();
824821

825822
$code = <<<EOF
@@ -829,10 +826,17 @@ private function addFrozenConstructor()
829826
*/
830827
public function __construct()
831828
{{$targetDirs}
829+
EOF;
830+
831+
if ($this->container->getParameterBag()->all()) {
832+
$code .= "\n \$this->parameters = \$this->getDefaultParameters();\n";
833+
}
834+
835+
$code .= <<<EOF
836+
832837
\$this->services =
833838
\$this->scopedServices =
834839
\$this->scopeStacks = array();
835-
\$this->parameters = $parameters;
836840
837841
\$this->set('service_container', \$this);
838842
@@ -917,6 +921,8 @@ private function addDefaultParametersMethod()
917921
return '';
918922
}
919923

924+
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
925+
920926
$code = '';
921927
if ($this->container->isFrozen()) {
922928
$code .= <<<EOF
@@ -964,10 +970,23 @@ public function getParameterBag()
964970
965971
return \$this->parameterBag;
966972
}
967-
968973
EOF;
969974
}
970975

976+
$code .= <<<EOF
977+
978+
/**
979+
* Gets the default parameters.
980+
*
981+
* @return array An array of the default parameters
982+
*/
983+
protected function getDefaultParameters()
984+
{
985+
return $parameters;
986+
}
987+
988+
EOF;
989+
971990
return $code;
972991
}
973992

@@ -1357,11 +1376,10 @@ private function export($value)
13571376
$prefix = $matches[0][1] ? var_export(substr($value, 0, $matches[0][1]), true).'.' : '';
13581377
$suffix = $matches[0][1] + strlen($matches[0][0]);
13591378
$suffix = isset($value[$suffix]) ? '.'.var_export(substr($value, $suffix), true) : '';
1379+
$dirname = '__DIR__';
13601380

1361-
if (0 < $dirname = 1 + $this->targetDirMaxMatches - count($matches)) {
1362-
$dirname = sprintf('$this->targetDirs[%d]', $dirname);
1363-
} else {
1364-
$dirname = '__DIR__';
1381+
if (0 < $offset = 1 + $this->targetDirMaxMatches - count($matches)) {
1382+
$dirname = sprintf('$this->targetDirs[%d]', $offset);
13651383
}
13661384

13671385
if ($prefix || $suffix) {

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ public function testDump()
3737
new PhpDumper($container);
3838
}
3939

40+
public function testDumpFrozenContainerWithNoParameter()
41+
{
42+
$container = new ContainerBuilder();
43+
$container->setResourceTracking(false);
44+
$container->register('foo', 'stdClass');
45+
46+
$container->compile();
47+
48+
$dumper = new PhpDumper($container);
49+
50+
$dumpedString = $dumper->dump();
51+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services11.php', $dumpedString, '->dump() does not add getDefaultParameters() method call if container have no parameters.');
52+
$this->assertNotRegexp("/function getDefaultParameters\(/", $dumpedString, '->dump() does not add getDefaultParameters() method definition.');
53+
}
54+
4055
public function testDumpOptimizationString()
4156
{
4257
$definition = new Definition();

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@
1717
class Container extends AbstractContainer
1818
{
1919
private $parameters;
20-
private $targetDirs;
20+
private $targetDirs = array();
2121

2222
/**
2323
* Constructor.
2424
*/
2525
public function __construct()
2626
{
27-
$this->parameters = array(
28-
29-
);
30-
31-
parent::__construct(new ParameterBag($this->parameters));
27+
parent::__construct();
3228
}
3329
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@
1717
class ProjectServiceContainer extends Container
1818
{
1919
private $parameters;
20-
private $targetDirs;
20+
private $targetDirs = array();
2121

2222
/**
2323
* Constructor.
2424
*/
2525
public function __construct()
2626
{
27-
$this->parameters = array(
28-
29-
);
30-
31-
parent::__construct(new ParameterBag($this->parameters));
27+
parent::__construct();
3228
}
3329
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@
1717
class ProjectServiceContainer extends Container
1818
{
1919
private $parameters;
20-
private $targetDirs;
20+
private $targetDirs = array();
2121

2222
/**
2323
* Constructor.
2424
*/
2525
public function __construct()
2626
{
27+
$this->parameters = $this->getDefaultParameters();
28+
2729
$this->services =
2830
$this->scopedServices =
2931
$this->scopeStacks = array();
30-
$this->parameters = array(
31-
'empty_value' => '',
32-
'some_string' => '-',
33-
);
3432

3533
$this->set('service_container', $this);
3634

@@ -99,4 +97,16 @@ public function getParameterBag()
9997

10098
return $this->parameterBag;
10199
}
100+
/**
101+
* Gets the default parameters.
102+
*
103+
* @return array An array of the default parameters
104+
*/
105+
protected function getDefaultParameters()
106+
{
107+
return array(
108+
'empty_value' => '',
109+
'some_string' => '-',
110+
);
111+
}
102112
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\ContainerInterface;
4+
use Symfony\Component\DependencyInjection\Container;
5+
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
6+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
7+
use Symfony\Component\DependencyInjection\Exception\LogicException;
8+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
11+
/**
12+
* ProjectServiceContainer
13+
*
14+
* This class has been auto-generated
15+
* by the Symfony Dependency Injection Component.
16+
*/
17+
class ProjectServiceContainer extends Container
18+
{
19+
private $parameters;
20+
private $targetDirs = array();
21+
22+
/**
23+
* Constructor.
24+
*/
25+
public function __construct()
26+
{
27+
$this->services =
28+
$this->scopedServices =
29+
$this->scopeStacks = array();
30+
31+
$this->set('service_container', $this);
32+
33+
$this->scopes = array();
34+
$this->scopeChildren = array();
35+
$this->methodMap = array(
36+
'foo' => 'getFooService',
37+
);
38+
39+
$this->aliases = array();
40+
}
41+
42+
/**
43+
* Gets the 'foo' service.
44+
*
45+
* This service is shared.
46+
* This method always returns the same instance of the service.
47+
*
48+
* @return \stdClass A stdClass instance.
49+
*/
50+
protected function getFooService()
51+
{
52+
return $this->services['foo'] = new \stdClass();
53+
}
54+
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php

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

2222
/**
2323
* Constructor.
@@ -28,15 +28,11 @@ public function __construct()
2828
for ($i = 1; $i <= 5; ++$i) {
2929
$this->targetDirs[$i] = $dir = dirname($dir);
3030
}
31+
$this->parameters = $this->getDefaultParameters();
32+
3133
$this->services =
3234
$this->scopedServices =
3335
$this->scopeStacks = array();
34-
$this->parameters = array(
35-
'foo' => ('wiz'.$this->targetDirs[1]),
36-
'bar' => __DIR__,
37-
'baz' => (__DIR__.'/PhpDumperTest.php'),
38-
'buz' => $this->targetDirs[2],
39-
);
4036

4137
$this->set('service_container', $this);
4238

@@ -105,4 +101,18 @@ public function getParameterBag()
105101

106102
return $this->parameterBag;
107103
}
104+
/**
105+
* Gets the default parameters.
106+
*
107+
* @return array An array of the default parameters
108+
*/
109+
protected function getDefaultParameters()
110+
{
111+
return array(
112+
'foo' => ('wiz'.$this->targetDirs[1]),
113+
'bar' => __DIR__,
114+
'baz' => (__DIR__.'/PhpDumperTest.php'),
115+
'buz' => $this->targetDirs[2],
116+
);
117+
}
108118
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,24 @@
1717
class ProjectServiceContainer extends Container
1818
{
1919
private $parameters;
20-
private $targetDirs;
20+
private $targetDirs = array();
2121

2222
/**
2323
* Constructor.
2424
*/
2525
public function __construct()
2626
{
27-
$this->parameters = array(
27+
parent::__construct(new ParameterBag($this->getDefaultParameters()));
28+
}
29+
30+
/**
31+
* Gets the default parameters.
32+
*
33+
* @return array An array of the default parameters
34+
*/
35+
protected function getDefaultParameters()
36+
{
37+
return array(
2838
'foo' => '%baz%',
2939
'baz' => 'bar',
3040
'bar' => 'foo is %%foo bar',
@@ -40,7 +50,5 @@ public function __construct()
4050
7 => 'null',
4151
),
4252
);
43-
44-
parent::__construct(new ParameterBag($this->parameters));
4553
}
4654
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,14 @@
1717
class ProjectServiceContainer extends Container
1818
{
1919
private $parameters;
20-
private $targetDirs;
20+
private $targetDirs = array();
2121

2222
/**
2323
* Constructor.
2424
*/
2525
public function __construct()
2626
{
27-
$this->parameters = array(
28-
'baz_class' => 'BazClass',
29-
'foo_class' => 'FooClass',
30-
'foo' => 'bar',
31-
);
32-
33-
parent::__construct(new ParameterBag($this->parameters));
27+
parent::__construct(new ParameterBag($this->getDefaultParameters()));
3428
$this->methodMap = array(
3529
'bar' => 'getBarService',
3630
'baz' => 'getBazService',
@@ -254,4 +248,18 @@ protected function getInlinedService()
254248

255249
return $instance;
256250
}
251+
252+
/**
253+
* Gets the default parameters.
254+
*
255+
* @return array An array of the default parameters
256+
*/
257+
protected function getDefaultParameters()
258+
{
259+
return array(
260+
'baz_class' => 'BazClass',
261+
'foo_class' => 'FooClass',
262+
'foo' => 'bar',
263+
);
264+
}
257265
}

0 commit comments

Comments
 (0)
0