annotate vendor/symfony/dependency-injection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children c2387f117808
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /*
Chris@0 4 * This file is part of the Symfony package.
Chris@0 5 *
Chris@0 6 * (c) Fabien Potencier <fabien@symfony.com>
Chris@0 7 *
Chris@0 8 * For the full copyright and license information, please view the LICENSE
Chris@0 9 * file that was distributed with this source code.
Chris@0 10 */
Chris@0 11
Chris@0 12 namespace Symfony\Component\DependencyInjection\Compiler;
Chris@0 13
Chris@14 14 use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
Chris@0 15 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
Chris@0 16 use Symfony\Component\DependencyInjection\ContainerInterface;
Chris@0 17 use Symfony\Component\DependencyInjection\Reference;
Chris@0 18
Chris@0 19 /**
Chris@0 20 * Checks that all references are pointing to a valid service.
Chris@0 21 *
Chris@0 22 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
Chris@0 23 */
Chris@14 24 class CheckExceptionOnInvalidReferenceBehaviorPass extends AbstractRecursivePass
Chris@0 25 {
Chris@14 26 protected function processValue($value, $isRoot = false)
Chris@14 27 {
Chris@14 28 if (!$value instanceof Reference) {
Chris@14 29 return parent::processValue($value, $isRoot);
Chris@14 30 }
Chris@14 31 if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior() && !$this->container->has($id = (string) $value)) {
Chris@14 32 throw new ServiceNotFoundException($id, $this->currentId);
Chris@14 33 }
Chris@14 34 if (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior() && $this->container->has($id = (string) $value) && !$this->container->findDefinition($id)->isShared()) {
Chris@14 35 throw new InvalidArgumentException(sprintf('Invalid ignore-on-uninitialized reference found in service "%s": target service "%s" is not shared.', $this->currentId, $id));
Chris@14 36 }
Chris@0 37
Chris@14 38 return $value;
Chris@0 39 }
Chris@0 40 }