If you directly call setArguments() keep in mind that you must follow
certain conventions when you want to overwrite the arguments of the
parent definition, otherwise your arguments will only be appended.
public replaceArgument ( integer $index, mixed $value ) : self | ||
$index | integer | |
$value | mixed | |
return | self | the current instance |
/** * {@inheritdoc} */ protected function createListener($container, $id, $config, $userProvider) { $listenerId = $this->getListenerId(); $listener = new ChildDefinition($listenerId); $listener->replaceArgument(2, $id); $listener->replaceArgument(3, new Reference($this->createAuthenticationSuccessHandler($container, $id, $config))); $listener->replaceArgument(4, new Reference($this->createAuthenticationFailureHandler($container, $id, $config))); $listener->replaceArgument(5, array_intersect_key($config, $this->options)); $listenerId .= '.' . $id; $container->setDefinition($listenerId, $listener); return $listenerId; }
/** * @expectedException \OutOfBoundsException */ public function testGetArgumentShouldCheckBounds() { $def = new ChildDefinition('foo'); $def->setArguments(array(0 => 'foo')); $def->replaceArgument(0, 'foo'); $def->getArgument(1); }
private function createVersion(ContainerBuilder $container, $version, $format, $name) { if (null === $version) { return new Reference('assets.empty_version_strategy'); } $def = new ChildDefinition('assets.static_version_strategy'); $def->replaceArgument(0, $version)->replaceArgument(1, $format); $container->setDefinition('assets._version_' . $name, $def); return new Reference('assets._version_' . $name); }