Skip to content

Commit

Permalink
[DependencyInjection] Unescape parameters for all types of injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicofuma authored and Tristan Darricau committed Nov 19, 2015
1 parent 1728dcc commit 331a046
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Expand Up @@ -895,7 +895,7 @@ public function createService(Definition $definition, $id, $tryProxy = true)
$this->callMethod($service, $call);
}

$properties = $this->resolveServices($parameterBag->resolveValue($definition->getProperties()));
$properties = $this->resolveServices($parameterBag->unescapeValue($parameterBag->resolveValue($definition->getProperties())));
foreach ($properties as $name => $value) {
$service->$name = $value;
}
Expand Down Expand Up @@ -1054,7 +1054,7 @@ private function callMethod($service, $call)
}
}

call_user_func_array(array($service, $call[0]), $this->resolveServices($this->getParameterBag()->resolveValue($call[1])));
call_user_func_array(array($service, $call[0]), $this->resolveServices($this->getParameterBag()->unescapeValue($this->getParameterBag()->resolveValue($call[1]))));
}

/**
Expand Down
Expand Up @@ -305,6 +305,24 @@ public function testCreateServiceMethodCalls()
$this->assertEquals(array('bar', $builder->get('bar')), $builder->get('foo1')->bar, '->createService() replaces the values in the method calls arguments');
}

public function testCreateServiceMethodCallsWithEscapedParam()
{
$builder = new ContainerBuilder();
$builder->register('bar', 'stdClass');
$builder->register('foo1', 'FooClass')->addMethodCall('setBar', array(array('%%unescape_it%%')));
$builder->setParameter('value', 'bar');
$this->assertEquals(array('%unescape_it%'), $builder->get('foo1')->bar, '->createService() replaces the values in the method calls arguments');
}

public function testCreateServiceProperties()
{
$builder = new ContainerBuilder();
$builder->register('bar', 'stdClass');
$builder->register('foo1', 'FooClass')->setProperty('bar', array('%value%', new Reference('bar'), '%%unescape_it%%'));
$builder->setParameter('value', 'bar');
$this->assertEquals(array('bar', $builder->get('bar'), '%unescape_it%'), $builder->get('foo1')->bar, '->createService() replaces the values in the properties');
}

public function testCreateServiceConfigurator()
{
$builder = new ContainerBuilder();
Expand Down

0 comments on commit 331a046

Please sign in to comment.