Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits; Chris@14: Chris@14: use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; Chris@14: use Symfony\Component\DependencyInjection\Reference; Chris@14: Chris@14: trait BindTrait Chris@14: { Chris@14: /** Chris@14: * Sets bindings. Chris@14: * Chris@14: * Bindings map $named or FQCN arguments to values that should be Chris@14: * injected in the matching parameters (of the constructor, of methods Chris@14: * called and of controller actions). Chris@14: * Chris@14: * @param string $nameOrFqcn A parameter name with its "$" prefix, or a FQCN Chris@14: * @param mixed $valueOrRef The value or reference to bind Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@14: final public function bind($nameOrFqcn, $valueOrRef) Chris@14: { Chris@14: $valueOrRef = static::processValue($valueOrRef, true); Chris@14: if (isset($nameOrFqcn[0]) && '$' !== $nameOrFqcn[0] && !$valueOrRef instanceof Reference) { Chris@14: throw new InvalidArgumentException(sprintf('Invalid binding for service "%s": named arguments must start with a "$", and FQCN must map to references. Neither applies to binding "%s".', $this->id, $nameOrFqcn)); Chris@14: } Chris@14: $bindings = $this->definition->getBindings(); Chris@14: $bindings[$nameOrFqcn] = $valueOrRef; Chris@14: $this->definition->setBindings($bindings); Chris@14: Chris@14: return $this; Chris@14: } Chris@14: }