Revert "[DependencyInjection] backport perf optim"
This reverts commit c11535bd6b
.
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/DependencyInjection/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
This commit is contained in:
parent
fcd8ff9b67
commit
375f83ece4
@ -767,7 +767,7 @@ $bagClass
|
|||||||
class $class extends $baseClass
|
class $class extends $baseClass
|
||||||
{
|
{
|
||||||
private \$parameters;
|
private \$parameters;
|
||||||
private \$targetDirs;
|
private \$targetDirs = array();
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
}
|
}
|
||||||
@ -779,8 +779,8 @@ EOF;
|
|||||||
*/
|
*/
|
||||||
private function addConstructor()
|
private function addConstructor()
|
||||||
{
|
{
|
||||||
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
|
|
||||||
$targetDirs = $this->exportTargetDirs();
|
$targetDirs = $this->exportTargetDirs();
|
||||||
|
$arguments = $this->container->getParameterBag()->all() ? 'new ParameterBag($this->getDefaultParameters())' : null;
|
||||||
|
|
||||||
$code = <<<EOF
|
$code = <<<EOF
|
||||||
|
|
||||||
@ -789,9 +789,7 @@ EOF;
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{{$targetDirs}
|
{{$targetDirs}
|
||||||
\$this->parameters = $parameters;
|
parent::__construct($arguments);
|
||||||
|
|
||||||
parent::__construct(new ParameterBag(\$this->parameters));
|
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
|
|
||||||
@ -819,7 +817,6 @@ EOF;
|
|||||||
*/
|
*/
|
||||||
private function addFrozenConstructor()
|
private function addFrozenConstructor()
|
||||||
{
|
{
|
||||||
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
|
|
||||||
$targetDirs = $this->exportTargetDirs();
|
$targetDirs = $this->exportTargetDirs();
|
||||||
|
|
||||||
$code = <<<EOF
|
$code = <<<EOF
|
||||||
@ -829,10 +826,17 @@ EOF;
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{{$targetDirs}
|
{{$targetDirs}
|
||||||
|
EOF;
|
||||||
|
|
||||||
|
if ($this->container->getParameterBag()->all()) {
|
||||||
|
$code .= "\n \$this->parameters = \$this->getDefaultParameters();\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$code .= <<<EOF
|
||||||
|
|
||||||
\$this->services =
|
\$this->services =
|
||||||
\$this->scopedServices =
|
\$this->scopedServices =
|
||||||
\$this->scopeStacks = array();
|
\$this->scopeStacks = array();
|
||||||
\$this->parameters = $parameters;
|
|
||||||
|
|
||||||
\$this->set('service_container', \$this);
|
\$this->set('service_container', \$this);
|
||||||
|
|
||||||
@ -917,6 +921,8 @@ EOF;
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$parameters = $this->exportParameters($this->container->getParameterBag()->all());
|
||||||
|
|
||||||
$code = '';
|
$code = '';
|
||||||
if ($this->container->isFrozen()) {
|
if ($this->container->isFrozen()) {
|
||||||
$code .= <<<EOF
|
$code .= <<<EOF
|
||||||
@ -964,10 +970,23 @@ EOF;
|
|||||||
|
|
||||||
return \$this->parameterBag;
|
return \$this->parameterBag;
|
||||||
}
|
}
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$code .= <<<EOF
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the default parameters.
|
||||||
|
*
|
||||||
|
* @return array An array of the default parameters
|
||||||
|
*/
|
||||||
|
protected function getDefaultParameters()
|
||||||
|
{
|
||||||
|
return $parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
EOF;
|
||||||
|
|
||||||
return $code;
|
return $code;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1357,11 +1376,10 @@ EOF;
|
|||||||
$prefix = $matches[0][1] ? var_export(substr($value, 0, $matches[0][1]), true).'.' : '';
|
$prefix = $matches[0][1] ? var_export(substr($value, 0, $matches[0][1]), true).'.' : '';
|
||||||
$suffix = $matches[0][1] + strlen($matches[0][0]);
|
$suffix = $matches[0][1] + strlen($matches[0][0]);
|
||||||
$suffix = isset($value[$suffix]) ? '.'.var_export(substr($value, $suffix), true) : '';
|
$suffix = isset($value[$suffix]) ? '.'.var_export(substr($value, $suffix), true) : '';
|
||||||
|
|
||||||
if (0 < $dirname = 1 + $this->targetDirMaxMatches - count($matches)) {
|
|
||||||
$dirname = sprintf('$this->targetDirs[%d]', $dirname);
|
|
||||||
} else {
|
|
||||||
$dirname = '__DIR__';
|
$dirname = '__DIR__';
|
||||||
|
|
||||||
|
if (0 < $offset = 1 + $this->targetDirMaxMatches - count($matches)) {
|
||||||
|
$dirname = sprintf('$this->targetDirs[%d]', $offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($prefix || $suffix) {
|
if ($prefix || $suffix) {
|
||||||
|
@ -37,6 +37,21 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
new PhpDumper($container);
|
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()
|
public function testDumpOptimizationString()
|
||||||
{
|
{
|
||||||
$definition = new Definition();
|
$definition = new Definition();
|
||||||
|
@ -17,17 +17,13 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
|||||||
class Container extends AbstractContainer
|
class Container extends AbstractContainer
|
||||||
{
|
{
|
||||||
private $parameters;
|
private $parameters;
|
||||||
private $targetDirs;
|
private $targetDirs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->parameters = array(
|
parent::__construct();
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
parent::__construct(new ParameterBag($this->parameters));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,17 +17,13 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
|||||||
class ProjectServiceContainer extends Container
|
class ProjectServiceContainer extends Container
|
||||||
{
|
{
|
||||||
private $parameters;
|
private $parameters;
|
||||||
private $targetDirs;
|
private $targetDirs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->parameters = array(
|
parent::__construct();
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
parent::__construct(new ParameterBag($this->parameters));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,20 +17,18 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
|
|||||||
class ProjectServiceContainer extends Container
|
class ProjectServiceContainer extends Container
|
||||||
{
|
{
|
||||||
private $parameters;
|
private $parameters;
|
||||||
private $targetDirs;
|
private $targetDirs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$this->parameters = $this->getDefaultParameters();
|
||||||
|
|
||||||
$this->services =
|
$this->services =
|
||||||
$this->scopedServices =
|
$this->scopedServices =
|
||||||
$this->scopeStacks = array();
|
$this->scopeStacks = array();
|
||||||
$this->parameters = array(
|
|
||||||
'empty_value' => '',
|
|
||||||
'some_string' => '-',
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->set('service_container', $this);
|
$this->set('service_container', $this);
|
||||||
|
|
||||||
@ -99,4 +97,16 @@ class ProjectServiceContainer extends Container
|
|||||||
|
|
||||||
return $this->parameterBag;
|
return $this->parameterBag;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Gets the default parameters.
|
||||||
|
*
|
||||||
|
* @return array An array of the default parameters
|
||||||
|
*/
|
||||||
|
protected function getDefaultParameters()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'empty_value' => '',
|
||||||
|
'some_string' => '-',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
<?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;
|
||||||
|
private $targetDirs = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
}
|
||||||
|
}
|
@ -17,7 +17,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
|
|||||||
class ProjectServiceContainer extends Container
|
class ProjectServiceContainer extends Container
|
||||||
{
|
{
|
||||||
private $parameters;
|
private $parameters;
|
||||||
private $targetDirs;
|
private $targetDirs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -28,15 +28,11 @@ class ProjectServiceContainer extends Container
|
|||||||
for ($i = 1; $i <= 5; ++$i) {
|
for ($i = 1; $i <= 5; ++$i) {
|
||||||
$this->targetDirs[$i] = $dir = dirname($dir);
|
$this->targetDirs[$i] = $dir = dirname($dir);
|
||||||
}
|
}
|
||||||
|
$this->parameters = $this->getDefaultParameters();
|
||||||
|
|
||||||
$this->services =
|
$this->services =
|
||||||
$this->scopedServices =
|
$this->scopedServices =
|
||||||
$this->scopeStacks = array();
|
$this->scopeStacks = array();
|
||||||
$this->parameters = array(
|
|
||||||
'foo' => ('wiz'.$this->targetDirs[1]),
|
|
||||||
'bar' => __DIR__,
|
|
||||||
'baz' => (__DIR__.'/PhpDumperTest.php'),
|
|
||||||
'buz' => $this->targetDirs[2],
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->set('service_container', $this);
|
$this->set('service_container', $this);
|
||||||
|
|
||||||
@ -105,4 +101,18 @@ class ProjectServiceContainer extends Container
|
|||||||
|
|
||||||
return $this->parameterBag;
|
return $this->parameterBag;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Gets the default parameters.
|
||||||
|
*
|
||||||
|
* @return array An array of the default parameters
|
||||||
|
*/
|
||||||
|
protected function getDefaultParameters()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
'foo' => ('wiz'.$this->targetDirs[1]),
|
||||||
|
'bar' => __DIR__,
|
||||||
|
'baz' => (__DIR__.'/PhpDumperTest.php'),
|
||||||
|
'buz' => $this->targetDirs[2],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,24 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
|||||||
class ProjectServiceContainer extends Container
|
class ProjectServiceContainer extends Container
|
||||||
{
|
{
|
||||||
private $parameters;
|
private $parameters;
|
||||||
private $targetDirs;
|
private $targetDirs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->parameters = array(
|
parent::__construct(new ParameterBag($this->getDefaultParameters()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the default parameters.
|
||||||
|
*
|
||||||
|
* @return array An array of the default parameters
|
||||||
|
*/
|
||||||
|
protected function getDefaultParameters()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
'foo' => '%baz%',
|
'foo' => '%baz%',
|
||||||
'baz' => 'bar',
|
'baz' => 'bar',
|
||||||
'bar' => 'foo is %%foo bar',
|
'bar' => 'foo is %%foo bar',
|
||||||
@ -40,7 +50,5 @@ class ProjectServiceContainer extends Container
|
|||||||
7 => 'null',
|
7 => 'null',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
parent::__construct(new ParameterBag($this->parameters));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,20 +17,14 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
|||||||
class ProjectServiceContainer extends Container
|
class ProjectServiceContainer extends Container
|
||||||
{
|
{
|
||||||
private $parameters;
|
private $parameters;
|
||||||
private $targetDirs;
|
private $targetDirs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->parameters = array(
|
parent::__construct(new ParameterBag($this->getDefaultParameters()));
|
||||||
'baz_class' => 'BazClass',
|
|
||||||
'foo_class' => 'FooClass',
|
|
||||||
'foo' => 'bar',
|
|
||||||
);
|
|
||||||
|
|
||||||
parent::__construct(new ParameterBag($this->parameters));
|
|
||||||
$this->methodMap = array(
|
$this->methodMap = array(
|
||||||
'bar' => 'getBarService',
|
'bar' => 'getBarService',
|
||||||
'baz' => 'getBazService',
|
'baz' => 'getBazService',
|
||||||
@ -254,4 +248,18 @@ class ProjectServiceContainer extends Container
|
|||||||
|
|
||||||
return $instance;
|
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',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,21 +17,18 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
|
|||||||
class ProjectServiceContainer extends Container
|
class ProjectServiceContainer extends Container
|
||||||
{
|
{
|
||||||
private $parameters;
|
private $parameters;
|
||||||
private $targetDirs;
|
private $targetDirs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$this->parameters = $this->getDefaultParameters();
|
||||||
|
|
||||||
$this->services =
|
$this->services =
|
||||||
$this->scopedServices =
|
$this->scopedServices =
|
||||||
$this->scopeStacks = array();
|
$this->scopeStacks = array();
|
||||||
$this->parameters = array(
|
|
||||||
'baz_class' => 'BazClass',
|
|
||||||
'foo_class' => 'FooClass',
|
|
||||||
'foo' => 'bar',
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->set('service_container', $this);
|
$this->set('service_container', $this);
|
||||||
|
|
||||||
@ -278,4 +275,17 @@ class ProjectServiceContainer extends Container
|
|||||||
|
|
||||||
return $this->parameterBag;
|
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