From c11535bd6bff6d00ac5a0206e1c8d3f508bba8f3 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 3 Dec 2014 10:22:11 +0100 Subject: [PATCH] [DependencyInjection] backport perf optim Conflicts: src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services19.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php --- .../DependencyInjection/Dumper/PhpDumper.php | 36 ++++--------- .../Tests/Dumper/PhpDumperTest.php | 15 ------ .../Tests/Fixtures/php/services1-1.php | 8 ++- .../Tests/Fixtures/php/services1.php | 8 ++- .../Tests/Fixtures/php/services10.php | 20 +++----- .../Tests/Fixtures/php/services11.php | 51 ------------------- .../Tests/Fixtures/php/services12.php | 22 +++----- .../Tests/Fixtures/php/services8.php | 16 ++---- .../Tests/Fixtures/php/services9.php | 24 ++++----- .../Tests/Fixtures/php/services9_compiled.php | 22 +++----- 10 files changed, 58 insertions(+), 164 deletions(-) delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index 5e9208e5cf..58b34e39e9 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -764,6 +764,8 @@ $bagClass */ class $class extends $baseClass { + private \$parameters; + EOF; } @@ -774,7 +776,7 @@ EOF; */ private function addConstructor() { - $arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null; + $parameters = $this->exportParameters($this->container->getParameterBag()->all()); $code = <<parameters = $parameters; + + parent::__construct(new ParameterBag(\$this->parameters)); EOF; @@ -811,6 +815,8 @@ EOF; */ private function addFrozenConstructor() { + $parameters = $this->exportParameters($this->container->getParameterBag()->all()); + $code = <<container->getParameterBag()->all()) { - $code .= "\n \$this->parameters = \$this->getDefaultParameters();\n"; - } - - $code .= <<services = \$this->scopedServices = \$this->scopeStacks = array(); + \$this->parameters = $parameters; \$this->set('service_container', \$this); @@ -913,8 +912,6 @@ EOF; return ''; } - $parameters = $this->exportParameters($this->container->getParameterBag()->all()); - $code = ''; if ($this->container->isFrozen()) { $code .= <<parameterBag; } + EOF; } - $code .= <<setResourceTracking(false); - $container->register('foo', 'stdClass'); - - $container->compile(); - - $dumper = new PhpDumper($container); - - $dumpedString = $dumper->dump(); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/services11.php', $dumpedString, '->dump() does not add getDefaultParameters() method call if container have no parameters.'); - $this->assertNotRegexp("/function getDefaultParameters\(/", $dumpedString, '->dump() does not add getDefaultParameters() method definition.'); - } - public function testDumpOptimizationString() { $definition = new Definition(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php index 547941eb95..560da91642 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php @@ -16,11 +16,17 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ class Container extends AbstractContainer { + private $parameters; + /** * Constructor. */ public function __construct() { - parent::__construct(); + $this->parameters = array( + + ); + + parent::__construct(new ParameterBag($this->parameters)); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php index 084e7891af..23d367f1f9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1.php @@ -16,11 +16,17 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ class ProjectServiceContainer extends Container { + private $parameters; + /** * Constructor. */ public function __construct() { - parent::__construct(); + $this->parameters = array( + + ); + + parent::__construct(new ParameterBag($this->parameters)); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php index 37927a6e70..bf64894f58 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php @@ -16,16 +16,20 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; */ class ProjectServiceContainer extends Container { + private $parameters; + /** * Constructor. */ public function __construct() { - $this->parameters = $this->getDefaultParameters(); - $this->services = $this->scopedServices = $this->scopeStacks = array(); + $this->parameters = array( + 'empty_value' => '', + 'some_string' => '-', + ); $this->set('service_container', $this); @@ -94,16 +98,4 @@ class ProjectServiceContainer extends Container return $this->parameterBag; } - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( - 'empty_value' => '', - 'some_string' => '-', - ); - } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php deleted file mode 100644 index 0dcd83845a..0000000000 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php +++ /dev/null @@ -1,51 +0,0 @@ -services = - $this->scopedServices = - $this->scopeStacks = array(); - - $this->set('service_container', $this); - - $this->scopes = array(); - $this->scopeChildren = array(); - $this->methodMap = array( - 'foo' => 'getFooService', - ); - - $this->aliases = array(); - } - - /** - * Gets the 'foo' service. - * - * This service is shared. - * This method always returns the same instance of the service. - * - * @return \stdClass A stdClass instance. - */ - protected function getFooService() - { - return $this->services['foo'] = new \stdClass(); - } -} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php index 52d2702afd..1829818dbc 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services12.php @@ -16,16 +16,21 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; */ class ProjectServiceContainer extends Container { + private $parameters; + /** * Constructor. */ public function __construct() { - $this->parameters = $this->getDefaultParameters(); - $this->services = $this->scopedServices = $this->scopeStacks = array(); + $this->parameters = array( + 'foo' => ('wiz'.dirname(__DIR__)), + 'bar' => __DIR__, + 'baz' => (__DIR__.'/PhpDumperTest.php'), + ); $this->set('service_container', $this); @@ -94,17 +99,4 @@ class ProjectServiceContainer extends Container return $this->parameterBag; } - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( - 'foo' => ('wiz'.dirname(__DIR__)), - 'bar' => __DIR__, - 'baz' => (__DIR__.'/PhpDumperTest.php'), - ); - } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php index f922d2000c..a6de38e381 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services8.php @@ -16,22 +16,14 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ class ProjectServiceContainer extends Container { + private $parameters; + /** * Constructor. */ public function __construct() { - parent::__construct(new ParameterBag($this->getDefaultParameters())); - } - - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( + $this->parameters = array( 'foo' => '%baz%', 'baz' => 'bar', 'bar' => 'foo is %%foo bar', @@ -47,5 +39,7 @@ class ProjectServiceContainer extends Container 7 => 'null', ), ); + + parent::__construct(new ParameterBag($this->parameters)); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php index a4b42d78ad..90b5476776 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php @@ -16,12 +16,20 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ class ProjectServiceContainer extends Container { + private $parameters; + /** * Constructor. */ public function __construct() { - parent::__construct(new ParameterBag($this->getDefaultParameters())); + $this->parameters = array( + 'baz_class' => 'BazClass', + 'foo_class' => 'FooClass', + 'foo' => 'bar', + ); + + parent::__construct(new ParameterBag($this->parameters)); $this->methodMap = array( 'bar' => 'getBarService', 'baz' => 'getBazService', @@ -245,18 +253,4 @@ class ProjectServiceContainer extends Container return $instance; } - - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( - 'baz_class' => 'BazClass', - 'foo_class' => 'FooClass', - 'foo' => 'bar', - ); - } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index b881b5e300..97fe3ad8a0 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -16,16 +16,21 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; */ class ProjectServiceContainer extends Container { + private $parameters; + /** * Constructor. */ public function __construct() { - $this->parameters = $this->getDefaultParameters(); - $this->services = $this->scopedServices = $this->scopeStacks = array(); + $this->parameters = array( + 'baz_class' => 'BazClass', + 'foo_class' => 'FooClass', + 'foo' => 'bar', + ); $this->set('service_container', $this); @@ -272,17 +277,4 @@ class ProjectServiceContainer extends Container return $this->parameterBag; } - /** - * Gets the default parameters. - * - * @return array An array of the default parameters - */ - protected function getDefaultParameters() - { - return array( - 'baz_class' => 'BazClass', - 'foo_class' => 'FooClass', - 'foo' => 'bar', - ); - } }