Skip to content

[DependencyInjection] fix PhpDumper #12823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,8 @@ private function startClass($class, $baseClass, $namespace)
*/
class $class extends $baseClass
{
private \$parameters;

EOF;
}

Expand All @@ -837,14 +839,14 @@ private function addConstructor()

$code = <<<EOF

private static \$parameters = $parameters;

/**
* Constructor.
*/
public function __construct()
{
parent::__construct(new ParameterBag(self::\$parameters));
\$this->parameters = $parameters;

parent::__construct(new ParameterBag(\$this->parameters));

EOF;

Expand Down Expand Up @@ -876,8 +878,6 @@ private function addFrozenConstructor()

$code = <<<EOF

private static \$parameters = $parameters;

/**
* Constructor.
*/
Expand All @@ -886,6 +886,7 @@ public function __construct()
\$this->services =
\$this->scopedServices =
\$this->scopeStacks = array();
\$this->parameters = $parameters;

\$this->set('service_container', \$this);

Expand Down Expand Up @@ -1001,11 +1002,11 @@ public function getParameter(\$name)
{
\$name = strtolower(\$name);

if (!(isset(self::\$parameters[\$name]) || array_key_exists(\$name, self::\$parameters))) {
if (!(isset(\$this->parameters[\$name]) || array_key_exists(\$name, \$this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', \$name));
}

return self::\$parameters[\$name];
return \$this->parameters[\$name];
}

/**
Expand All @@ -1015,7 +1016,7 @@ public function hasParameter(\$name)
{
\$name = strtolower(\$name);

return isset(self::\$parameters[\$name]) || array_key_exists(\$name, self::\$parameters);
return isset(\$this->parameters[\$name]) || array_key_exists(\$name, \$this->parameters);
}

/**
Expand All @@ -1032,7 +1033,7 @@ public function setParameter(\$name, \$value)
public function getParameterBag()
{
if (null === \$this->parameterBag) {
\$this->parameterBag = new FrozenParameterBag(self::\$parameters);
\$this->parameterBag = new FrozenParameterBag(\$this->parameters);
}

return \$this->parameterBag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,6 @@ public function testDump()
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
*/
class Container extends AbstractContainer
{
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
*/
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/
class ProjectServiceContainer extends Container
{
private static $parameters = array(
'empty_value' => '',
'some_string' => '-',
);
private $parameters;

/**
* Constructor.
Expand All @@ -29,6 +26,10 @@ public function __construct()
$this->services =
$this->scopedServices =
$this->scopeStacks = array();
$this->parameters = array(
'empty_value' => '',
'some_string' => '-',
);

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

Expand Down Expand Up @@ -69,11 +70,11 @@ public function getParameter($name)
{
$name = strtolower($name);

if (!(isset(self::$parameters[$name]) || array_key_exists($name, self::$parameters))) {
if (!(isset($this->parameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
}

return self::$parameters[$name];
return $this->parameters[$name];
}

/**
Expand All @@ -83,7 +84,7 @@ public function hasParameter($name)
{
$name = strtolower($name);

return isset(self::$parameters[$name]) || array_key_exists($name, self::$parameters);
return isset($this->parameters[$name]) || array_key_exists($name, $this->parameters);
}

/**
Expand All @@ -100,7 +101,7 @@ public function setParameter($name, $value)
public function getParameterBag()
{
if (null === $this->parameterBag) {
$this->parameterBag = new FrozenParameterBag(self::$parameters);
$this->parameterBag = new FrozenParameterBag($this->parameters);
}

return $this->parameterBag;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@
*/
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);

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

/**
* {@inheritdoc}
*/
public function compile()
{
throw new LogicException('You cannot compile a dumped frozen container.');
}

/**
* Gets the 'test' service.
*
Expand Down Expand Up @@ -94,17 +107,4 @@ public function getParameterBag()

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'),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
*/
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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
*/
class ProjectServiceContainer extends Container
{
private static $parameters = array(
private $parameters;

/**
* Constructor.
*/
public function __construct()
{
$this->parameters = array(
'foo' => '%baz%',
'baz' => 'bar',
'bar' => 'foo is %%foo bar',
Expand All @@ -33,11 +40,6 @@ class ProjectServiceContainer extends Container
),
);

/**
* Constructor.
*/
public function __construct()
{
parent::__construct(new ParameterBag(self::$parameters));
parent::__construct(new ParameterBag($this->parameters));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
*/
class ProjectServiceContainer extends Container
{
private static $parameters = array(
'baz_class' => 'BazClass',
'foo_class' => 'Bar\\FooClass',
'foo' => 'bar',
);
private $parameters;

/**
* Constructor.
*/
public function __construct()
{
parent::__construct(new ParameterBag(self::$parameters));
$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',
Expand Down
Loading