[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\DependencyInjection\Compiler; 13 14 use Symfony\Component\DependencyInjection\ContainerInterface; 15 use Symfony\Component\DependencyInjection\ContainerBuilder; 16 use Symfony\Component\DependencyInjection\Exception\RuntimeException; 17 18 /** 19 * This pass validates each definition individually only taking the information 20 * into account which is contained in the definition itself. 21 * 22 * Later passes can rely on the following, and specifically do not need to 23 * perform these checks themselves: 24 * 25 * - non synthetic, non abstract services always have a class set 26 * - synthetic services are always public 27 * - synthetic services are always of non-prototype scope 28 * 29 * @author Johannes M. Schmitt <schmittjoh@gmail.com> 30 */ 31 class CheckDefinitionValidityPass implements CompilerPassInterface 32 { 33 /** 34 * Processes the ContainerBuilder to validate the Definition. 35 * 36 * @param ContainerBuilder $container 37 * 38 * @throws RuntimeException When the Definition is invalid 39 */ 40 public function process(ContainerBuilder $container) 41 { 42 foreach ($container->getDefinitions() as $id => $definition) { 43 // synthetic service is public 44 if ($definition->isSynthetic() && !$definition->isPublic()) { 45 throw new RuntimeException(sprintf( 46 'A synthetic service ("%s") must be public.', 47 $id 48 )); 49 } 50 51 // synthetic service has non-prototype scope 52 if ($definition->isSynthetic() && ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope()) { 53 throw new RuntimeException(sprintf( 54 'A synthetic service ("%s") cannot be of scope "prototype".', 55 $id 56 )); 57 } 58 59 // non-synthetic, non-abstract service has class 60 if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) { 61 if ($definition->getFactoryClass() || $definition->getFactoryService()) { 62 throw new RuntimeException(sprintf( 63 'Please add the class to service "%s" even if it is constructed by a factory ' 64 .'since we might need to add method calls based on compile-time checks.', 65 $id 66 )); 67 } 68 69 throw new RuntimeException(sprintf( 70 'The definition for "%s" has no class. If you intend to inject ' 71 .'this service dynamically at runtime, please mark it as synthetic=true. ' 72 .'If this is an abstract definition solely used by child definitions, ' 73 .'please add abstract=true, otherwise specify a class to get rid of this error.', 74 $id 75 )); 76 } 77 } 78 } 79 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |