[ Index ] |
PHP Cross Reference of phpBB-3.3.14-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\Argument\ArgumentInterface; 15 use Symfony\Component\DependencyInjection\Definition; 16 use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException; 17 use Symfony\Component\DependencyInjection\Reference; 18 19 /** 20 * Inline service definitions where this is possible. 21 * 22 * @author Johannes M. Schmitt <schmittjoh@gmail.com> 23 */ 24 class InlineServiceDefinitionsPass extends AbstractRecursivePass implements RepeatablePassInterface 25 { 26 private $cloningIds = []; 27 private $inlinedServiceIds = []; 28 29 /** 30 * {@inheritdoc} 31 */ 32 public function setRepeatedPass(RepeatedPass $repeatedPass) 33 { 34 // no-op for BC 35 } 36 37 /** 38 * Returns an array of all services inlined by this pass. 39 * 40 * The key is the inlined service id and its value is the list of services it was inlined into. 41 * 42 * @deprecated since version 3.4, to be removed in 4.0. 43 * 44 * @return array 45 */ 46 public function getInlinedServiceIds() 47 { 48 @trigger_error('Calling InlineServiceDefinitionsPass::getInlinedServiceIds() is deprecated since Symfony 3.4 and will be removed in 4.0.', \E_USER_DEPRECATED); 49 50 return $this->inlinedServiceIds; 51 } 52 53 /** 54 * {@inheritdoc} 55 */ 56 protected function processValue($value, $isRoot = false) 57 { 58 if ($value instanceof ArgumentInterface) { 59 // Reference found in ArgumentInterface::getValues() are not inlineable 60 return $value; 61 } 62 63 if ($value instanceof Definition && $this->cloningIds) { 64 if ($value->isShared()) { 65 return $value; 66 } 67 $value = clone $value; 68 } 69 70 if (!$value instanceof Reference || !$this->container->hasDefinition($id = $this->container->normalizeId($value))) { 71 return parent::processValue($value, $isRoot); 72 } 73 74 $definition = $this->container->getDefinition($id); 75 76 if (!$this->isInlineableDefinition($id, $definition, $this->container->getCompiler()->getServiceReferenceGraph())) { 77 return $value; 78 } 79 80 $this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId)); 81 $this->inlinedServiceIds[$id][] = $this->currentId; 82 83 if ($definition->isShared()) { 84 return $definition; 85 } 86 87 if (isset($this->cloningIds[$id])) { 88 $ids = array_keys($this->cloningIds); 89 $ids[] = $id; 90 91 throw new ServiceCircularReferenceException($id, \array_slice($ids, array_search($id, $ids))); 92 } 93 94 $this->cloningIds[$id] = true; 95 try { 96 return $this->processValue($definition); 97 } finally { 98 unset($this->cloningIds[$id]); 99 } 100 } 101 102 /** 103 * Checks if the definition is inlineable. 104 * 105 * @return bool If the definition is inlineable 106 */ 107 private function isInlineableDefinition($id, Definition $definition, ServiceReferenceGraph $graph) 108 { 109 if ($definition->getErrors() || $definition->isDeprecated() || $definition->isLazy() || $definition->isSynthetic()) { 110 return false; 111 } 112 113 if (!$definition->isShared()) { 114 return true; 115 } 116 117 if ($definition->isPublic() || $definition->isPrivate()) { 118 return false; 119 } 120 121 if (!$graph->hasNode($id)) { 122 return true; 123 } 124 125 if ($this->currentId == $id) { 126 return false; 127 } 128 129 $ids = []; 130 $isReferencedByConstructor = false; 131 foreach ($graph->getNode($id)->getInEdges() as $edge) { 132 $isReferencedByConstructor = $isReferencedByConstructor || $edge->isReferencedByConstructor(); 133 if ($edge->isWeak() || $edge->isLazy()) { 134 return false; 135 } 136 $ids[] = $edge->getSourceNode()->getId(); 137 } 138 139 if (!$ids) { 140 return true; 141 } 142 143 if (\count(array_unique($ids)) > 1) { 144 return false; 145 } 146 147 if (\count($ids) > 1 && \is_array($factory = $definition->getFactory()) && ($factory[0] instanceof Reference || $factory[0] instanceof Definition)) { 148 return false; 149 } 150 151 return $this->container->getDefinition($ids[0])->isShared(); 152 } 153 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |