Mercurial > hg > isophonics-drupal-site
annotate vendor/symfony/dependency-injection/Loader/Configurator/Traits/BindTrait.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 1fec387a4317 |
children |
rev | line source |
---|---|
Chris@14 | 1 <?php |
Chris@14 | 2 |
Chris@14 | 3 /* |
Chris@14 | 4 * This file is part of the Symfony package. |
Chris@14 | 5 * |
Chris@14 | 6 * (c) Fabien Potencier <fabien@symfony.com> |
Chris@14 | 7 * |
Chris@14 | 8 * For the full copyright and license information, please view the LICENSE |
Chris@14 | 9 * file that was distributed with this source code. |
Chris@14 | 10 */ |
Chris@14 | 11 |
Chris@14 | 12 namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits; |
Chris@14 | 13 |
Chris@14 | 14 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; |
Chris@14 | 15 use Symfony\Component\DependencyInjection\Reference; |
Chris@14 | 16 |
Chris@14 | 17 trait BindTrait |
Chris@14 | 18 { |
Chris@14 | 19 /** |
Chris@14 | 20 * Sets bindings. |
Chris@14 | 21 * |
Chris@14 | 22 * Bindings map $named or FQCN arguments to values that should be |
Chris@14 | 23 * injected in the matching parameters (of the constructor, of methods |
Chris@14 | 24 * called and of controller actions). |
Chris@14 | 25 * |
Chris@14 | 26 * @param string $nameOrFqcn A parameter name with its "$" prefix, or a FQCN |
Chris@14 | 27 * @param mixed $valueOrRef The value or reference to bind |
Chris@14 | 28 * |
Chris@14 | 29 * @return $this |
Chris@14 | 30 */ |
Chris@14 | 31 final public function bind($nameOrFqcn, $valueOrRef) |
Chris@14 | 32 { |
Chris@14 | 33 $valueOrRef = static::processValue($valueOrRef, true); |
Chris@14 | 34 if (isset($nameOrFqcn[0]) && '$' !== $nameOrFqcn[0] && !$valueOrRef instanceof Reference) { |
Chris@14 | 35 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 | 36 } |
Chris@14 | 37 $bindings = $this->definition->getBindings(); |
Chris@14 | 38 $bindings[$nameOrFqcn] = $valueOrRef; |
Chris@14 | 39 $this->definition->setBindings($bindings); |
Chris@14 | 40 |
Chris@14 | 41 return $this; |
Chris@14 | 42 } |
Chris@14 | 43 } |