[DependencyInjection] keep some of the reverted perf optim
This commit is contained in:
parent
2f0b3551b5
commit
7887a46ff9
@ -823,6 +823,8 @@ $bagClass
|
||||
*/
|
||||
class $class extends $baseClass
|
||||
{
|
||||
private \$parameters;
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
@ -833,7 +835,7 @@ EOF;
|
||||
*/
|
||||
private function addConstructor()
|
||||
{
|
||||
$arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null;
|
||||
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
|
||||
|
||||
$code = <<<EOF
|
||||
|
||||
@ -842,7 +844,9 @@ EOF;
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct($arguments);
|
||||
\$this->parameters = $parameters;
|
||||
|
||||
parent::__construct(new ParameterBag(\$this->parameters));
|
||||
|
||||
EOF;
|
||||
|
||||
@ -870,26 +874,19 @@ EOF;
|
||||
*/
|
||||
private function addFrozenConstructor()
|
||||
{
|
||||
$code = <<<EOF
|
||||
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
|
||||
|
||||
private \$parameters;
|
||||
$code = <<<EOF
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
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);
|
||||
|
||||
@ -994,8 +991,6 @@ EOF;
|
||||
return '';
|
||||
}
|
||||
|
||||
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
|
||||
|
||||
$code = '';
|
||||
if ($this->container->isFrozen()) {
|
||||
$code .= <<<EOF
|
||||
@ -1043,23 +1038,10 @@ 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();
|
||||
|
@ -17,11 +17,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));
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,13 @@ class ProjectServiceContainer extends Container
|
||||
*/
|
||||
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);
|
||||
|
||||
@ -104,16 +106,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,61 +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
|
||||
{
|
||||
private $parameters;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function compile()
|
||||
{
|
||||
throw new LogicException('You cannot compile a dumped frozen container.');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
@ -38,6 +43,14 @@ class ProjectServiceContainer extends Container
|
||||
$this->aliases = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function compile()
|
||||
{
|
||||
throw new LogicException('You cannot compile a dumped frozen container.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 'test' service.
|
||||
*
|
||||
@ -94,17 +107,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,16 +16,18 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
*/
|
||||
class ProjectServiceContainer extends Container
|
||||
{
|
||||
private static $parameters = array(
|
||||
|
||||
);
|
||||
private $parameters;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(new ParameterBag(self::$parameters));
|
||||
$this->parameters = array(
|
||||
|
||||
);
|
||||
|
||||
parent::__construct(new ParameterBag($this->parameters));
|
||||
$this->methodMap = array(
|
||||
'service_from_anonymous_factory' => 'getServiceFromAnonymousFactoryService',
|
||||
'service_with_method_call_and_factory' => 'getServiceWithMethodCallAndFactoryService',
|
||||
|
@ -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' => 'Bar\\FooClass',
|
||||
'foo' => 'bar',
|
||||
);
|
||||
|
||||
parent::__construct(new ParameterBag($this->parameters));
|
||||
$this->methodMap = array(
|
||||
'bar' => 'getBarService',
|
||||
'baz' => 'getBazService',
|
||||
@ -384,18 +392,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' => 'Bar\\FooClass',
|
||||
'foo' => 'bar',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,14 @@ class ProjectServiceContainer extends Container
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->parameters = $this->getDefaultParameters();
|
||||
|
||||
$this->services =
|
||||
$this->scopedServices =
|
||||
$this->scopeStacks = array();
|
||||
$this->parameters = array(
|
||||
'baz_class' => 'BazClass',
|
||||
'foo_class' => 'Bar\\FooClass',
|
||||
'foo' => 'bar',
|
||||
);
|
||||
|
||||
$this->set('service_container', $this);
|
||||
|
||||
@ -370,17 +373,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' => 'Bar\\FooClass',
|
||||
'foo' => 'bar',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user