[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
This commit is contained in:
parent
15551f2e85
commit
c11535bd6b
@ -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 = <<<EOF
|
||||
|
||||
@ -783,7 +785,9 @@ EOF;
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct($arguments);
|
||||
\$this->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 = <<<EOF
|
||||
|
||||
/**
|
||||
@ -818,17 +824,10 @@ EOF;
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
EOF;
|
||||
|
||||
if ($this->container->getParameterBag()->all()) {
|
||||
$code .= "\n \$this->parameters = \$this->getDefaultParameters();\n";
|
||||
}
|
||||
|
||||
$code .= <<<EOF
|
||||
|
||||
\$this->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 .= <<<EOF
|
||||
@ -962,22 +959,9 @@ EOF;
|
||||
|
||||
return \$this->parameterBag;
|
||||
}
|
||||
EOF;
|
||||
}
|
||||
|
||||
$code .= <<<EOF
|
||||
|
||||
/**
|
||||
* Gets the default parameters.
|
||||
*
|
||||
* @return array An array of the default parameters
|
||||
*/
|
||||
protected function getDefaultParameters()
|
||||
{
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
@ -37,21 +37,6 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
|
||||
new PhpDumper($container);
|
||||
}
|
||||
|
||||
public function testDumpFrozenContainerWithNoParameter()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->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();
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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' => '-',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
|
||||
|
||||
/**
|
||||
* ProjectServiceContainer
|
||||
*
|
||||
* This class has been auto-generated
|
||||
* by the Symfony Dependency Injection Component.
|
||||
*/
|
||||
class ProjectServiceContainer extends Container
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
@ -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'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user