Skip to content

Commit 7887a46

Browse files
[DependencyInjection] keep some of the reverted perf optim
1 parent 2f0b355 commit 7887a46

File tree

11 files changed

+68
-180
lines changed

11 files changed

+68
-180
lines changed

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

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,8 @@ private function startClass($class, $baseClass, $namespace)
823823
*/
824824
class $class extends $baseClass
825825
{
826+
private \$parameters;
827+
826828
EOF;
827829
}
828830

@@ -833,7 +835,7 @@ class $class extends $baseClass
833835
*/
834836
private function addConstructor()
835837
{
836-
$arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null;
838+
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
837839

838840
$code = <<<EOF
839841
@@ -842,7 +844,9 @@ private function addConstructor()
842844
*/
843845
public function __construct()
844846
{
845-
parent::__construct($arguments);
847+
\$this->parameters = $parameters;
848+
849+
parent::__construct(new ParameterBag(\$this->parameters));
846850
847851
EOF;
848852

@@ -870,26 +874,19 @@ public function __construct()
870874
*/
871875
private function addFrozenConstructor()
872876
{
873-
$code = <<<EOF
877+
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
874878

875-
private \$parameters;
879+
$code = <<<EOF
876880
877881
/**
878882
* Constructor.
879883
*/
880884
public function __construct()
881885
{
882-
EOF;
883-
884-
if ($this->container->getParameterBag()->all()) {
885-
$code .= "\n \$this->parameters = \$this->getDefaultParameters();\n";
886-
}
887-
888-
$code .= <<<EOF
889-
890886
\$this->services =
891887
\$this->scopedServices =
892888
\$this->scopeStacks = array();
889+
\$this->parameters = $parameters;
893890
894891
\$this->set('service_container', \$this);
895892
@@ -994,8 +991,6 @@ private function addDefaultParametersMethod()
994991
return '';
995992
}
996993

997-
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
998-
999994
$code = '';
1000995
if ($this->container->isFrozen()) {
1001996
$code .= <<<EOF
@@ -1043,22 +1038,9 @@ public function getParameterBag()
10431038
10441039
return \$this->parameterBag;
10451040
}
1046-
EOF;
1047-
}
1048-
1049-
$code .= <<<EOF
1050-
1051-
/**
1052-
* Gets the default parameters.
1053-
*
1054-
* @return array An array of the default parameters
1055-
*/
1056-
protected function getDefaultParameters()
1057-
{
1058-
return $parameters;
1059-
}
10601041
10611042
EOF;
1043+
}
10621044

10631045
return $code;
10641046
}

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,6 @@ 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-
5540
public function testDumpOptimizationString()
5641
{
5742
$definition = new Definition();

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@
1717
*/
1818
class Container extends AbstractContainer
1919
{
20+
private $parameters;
21+
2022
/**
2123
* Constructor.
2224
*/
2325
public function __construct()
2426
{
25-
parent::__construct();
27+
$this->parameters = array(
28+
29+
);
30+
31+
parent::__construct(new ParameterBag($this->parameters));
2632
}
2733
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@
1616
*/
1717
class ProjectServiceContainer extends Container
1818
{
19+
private $parameters;
20+
1921
/**
2022
* Constructor.
2123
*/
2224
public function __construct()
2325
{
24-
parent::__construct();
26+
$this->parameters = array(
27+
28+
);
29+
30+
parent::__construct(new ParameterBag($this->parameters));
2531
}
2632
}

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ class ProjectServiceContainer extends Container
2323
*/
2424
public function __construct()
2525
{
26-
$this->parameters = $this->getDefaultParameters();
27-
2826
$this->services =
2927
$this->scopedServices =
3028
$this->scopeStacks = array();
29+
$this->parameters = array(
30+
'empty_value' => '',
31+
'some_string' => '-',
32+
);
3133

3234
$this->set('service_container', $this);
3335

@@ -104,16 +106,4 @@ public function getParameterBag()
104106

105107
return $this->parameterBag;
106108
}
107-
/**
108-
* Gets the default parameters.
109-
*
110-
* @return array An array of the default parameters
111-
*/
112-
protected function getDefaultParameters()
113-
{
114-
return array(
115-
'empty_value' => '',
116-
'some_string' => '-',
117-
);
118-
}
119109
}

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

Lines changed: 0 additions & 61 deletions
This file was deleted.

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@
1616
*/
1717
class ProjectServiceContainer extends Container
1818
{
19+
private $parameters;
20+
1921
/**
2022
* Constructor.
2123
*/
2224
public function __construct()
2325
{
24-
$this->parameters = $this->getDefaultParameters();
25-
2626
$this->services =
2727
$this->scopedServices =
2828
$this->scopeStacks = array();
29+
$this->parameters = array(
30+
'foo' => ('wiz'.dirname(__DIR__)),
31+
'bar' => __DIR__,
32+
'baz' => (__DIR__.'/PhpDumperTest.php'),
33+
);
2934

3035
$this->set('service_container', $this);
3136

@@ -38,6 +43,14 @@ public function __construct()
3843
$this->aliases = array();
3944
}
4045

46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function compile()
50+
{
51+
throw new LogicException('You cannot compile a dumped frozen container.');
52+
}
53+
4154
/**
4255
* Gets the 'test' service.
4356
*
@@ -94,17 +107,4 @@ public function getParameterBag()
94107

95108
return $this->parameterBag;
96109
}
97-
/**
98-
* Gets the default parameters.
99-
*
100-
* @return array An array of the default parameters
101-
*/
102-
protected function getDefaultParameters()
103-
{
104-
return array(
105-
'foo' => ('wiz'.dirname(__DIR__)),
106-
'bar' => __DIR__,
107-
'baz' => (__DIR__.'/PhpDumperTest.php'),
108-
);
109-
}
110110
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@
1616
*/
1717
class ProjectServiceContainer extends Container
1818
{
19-
private static $parameters = array(
20-
21-
);
19+
private $parameters;
2220

2321
/**
2422
* Constructor.
2523
*/
2624
public function __construct()
2725
{
28-
parent::__construct(new ParameterBag(self::$parameters));
26+
$this->parameters = array(
27+
28+
);
29+
30+
parent::__construct(new ParameterBag($this->parameters));
2931
$this->methodMap = array(
3032
'service_from_anonymous_factory' => 'getServiceFromAnonymousFactoryService',
3133
'service_with_method_call_and_factory' => 'getServiceWithMethodCallAndFactoryService',

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,14 @@
1616
*/
1717
class ProjectServiceContainer extends Container
1818
{
19+
private $parameters;
20+
1921
/**
2022
* Constructor.
2123
*/
2224
public function __construct()
2325
{
24-
parent::__construct(new ParameterBag($this->getDefaultParameters()));
25-
}
26-
27-
/**
28-
* Gets the default parameters.
29-
*
30-
* @return array An array of the default parameters
31-
*/
32-
protected function getDefaultParameters()
33-
{
34-
return array(
26+
$this->parameters = array(
3527
'foo' => '%baz%',
3628
'baz' => 'bar',
3729
'bar' => 'foo is %%foo bar',
@@ -47,5 +39,7 @@ protected function getDefaultParameters()
4739
7 => 'null',
4840
),
4941
);
42+
43+
parent::__construct(new ParameterBag($this->parameters));
5044
}
5145
}

0 commit comments

Comments
 (0)