Skip to content

Commit

Permalink
[DependencyInjection] removed injection for protected and private pro…
Browse files Browse the repository at this point in the history
…perties
  • Loading branch information
fabpot committed Jun 27, 2011
1 parent 9cd1590 commit c3bb214
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
11 changes: 1 addition & 10 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
Expand Up @@ -699,17 +699,8 @@ private function createService(Definition $definition, $id)
}

$properties = $this->resolveServices($this->getParameterBag()->resolveValue($definition->getProperties()));
$outsideClass = new \ReflectionClass($service);
foreach ($properties as $name => $value) {
$class = $outsideClass;
do {
if ($class->hasProperty($name)) {
$property = $class->getProperty($name);
$property->setAccessible(true);
$property->setValue($service, $value);
continue 2;
}
} while (false !== $class = $class->getParentClass());
$service->$name = $value;
}

if ($callable = $definition->getConfigurator()) {
Expand Down
Expand Up @@ -374,9 +374,7 @@ private function addServiceProperties($id, $definition, $variableName = 'instanc
{
$code = '';
foreach ($definition->getProperties() as $name => $value) {
$code .= sprintf(" \$%s = new \ReflectionProperty(\$%s, %s);\n", $refName = $this->getNextVariableName(), $variableName, var_export($name, true));
$code .= sprintf(" \$%s->setAccessible(true);\n", $refName);
$code .= sprintf(" \$%s->setValue(\$%s, %s);\n", $refName, $variableName, $this->dumpValue($value));
$code .= sprintf(" \$%s->%s = %s;\n", $variableName, $name, $this->dumpValue($value));
}

return $code;
Expand Down
Expand Up @@ -2,7 +2,7 @@

class FooClass
{
private $foo, $moo;
public $foo, $moo;

public $bar = null, $initialized = false, $configured = false, $called = false, $arguments = array();

Expand Down
Expand Up @@ -66,12 +66,8 @@ protected function getFooService()

$instance->setBar($this->get('bar'));
$instance->initialize();
$b = new \ReflectionProperty($instance, 'foo');
$b->setAccessible(true);
$b->setValue($instance, 'bar');
$c = new \ReflectionProperty($instance, 'moo');
$c->setAccessible(true);
$c->setValue($instance, $a);
$instance->foo = 'bar';
$instance->moo = $a;
sc_configure($instance);

return $instance;
Expand Down

2 comments on commit c3bb214

@lsmith77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@schmittjoh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a convenience feature all from the start; with this change it is not anymore, and should be removed entirely imo.

Please sign in to comment.