* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Argument\ArgumentInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException; use Symfony\Component\DependencyInjection\Reference; /** * Inline service definitions where this is possible. * * @author Johannes M. Schmitt */ class InlineServiceDefinitionsPass extends AbstractRecursivePass implements RepeatablePassInterface { private $cloningIds = array(); private $inlinedServiceIds = array(); /** * {@inheritdoc} */ public function setRepeatedPass(RepeatedPass $repeatedPass) { // no-op for BC } /** * Returns an array of all services inlined by this pass. * * The key is the inlined service id and its value is the list of services it was inlined into. * * @deprecated since version 3.4, to be removed in 4.0. * * @return array */ public function getInlinedServiceIds() { @trigger_error('Calling InlineServiceDefinitionsPass::getInlinedServiceIds() is deprecated since Symfony 3.4 and will be removed in 4.0.', E_USER_DEPRECATED); return $this->inlinedServiceIds; } /** * {@inheritdoc} */ protected function processValue($value, $isRoot = false) { if ($value instanceof ArgumentInterface) { // Reference found in ArgumentInterface::getValues() are not inlineable return $value; } if ($value instanceof Definition && $this->cloningIds) { if ($value->isShared()) { return $value; } $value = clone $value; } if (!$value instanceof Reference || !$this->container->hasDefinition($id = $this->container->normalizeId($value))) { return parent::processValue($value, $isRoot); } $definition = $this->container->getDefinition($id); if (!$this->isInlineableDefinition($id, $definition, $this->container->getCompiler()->getServiceReferenceGraph())) { return $value; } $this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId)); $this->inlinedServiceIds[$id][] = $this->currentId; if ($definition->isShared()) { return $definition; } if (isset($this->cloningIds[$id])) { $ids = array_keys($this->cloningIds); $ids[] = $id; throw new ServiceCircularReferenceException($id, array_slice($ids, array_search($id, $ids))); } $this->cloningIds[$id] = true; try { return $this->processValue($definition); } finally { unset($this->cloningIds[$id]); } } /** * Checks if the definition is inlineable. * * @return bool If the definition is inlineable */ private function isInlineableDefinition($id, Definition $definition, ServiceReferenceGraph $graph) { if (!$definition->isShared()) { return true; } if ($definition->isDeprecated() || $definition->isPublic() || $definition->isPrivate() || $definition->isLazy()) { return false; } if (!$graph->hasNode($id)) { return true; } if ($this->currentId == $id) { return false; } $ids = array(); foreach ($graph->getNode($id)->getInEdges() as $edge) { if ($edge->isWeak()) { return false; } $ids[] = $edge->getSourceNode()->getId(); } if (count(array_unique($ids)) > 1) { return false; } if (count($ids) > 1 && is_array($factory = $definition->getFactory()) && ($factory[0] instanceof Reference || $factory[0] instanceof Definition)) { return false; } return $this->container->getDefinition($ids[0])->isShared(); } } __halt_compiler();----SIGNATURE:----CnlgqyXEHmqYFKm0tBx4u/izC43e8Q88dS4ea4SzBjWgotXFablVlmSdCnU0YPTu2elnpxUe3WZcS6g4BCYRkJ32CMDC1OxdW6Ad7icvOUL6AZW/xYgepdLZY0Vag9CIlrayPq4fYlImrjTRgrPJK+qic2iLSckW+l7s26RRwgi+bn8TshQ53PDVhrV/A4B9ou2VsAOhFkljY9vKyPKRULex9/pQK8XGEodStKwkRXYXL1Wol6noOLAUjeTm0OvX5hFHzyk3hmzsOXuP/dsbKaIOLUJrB5LIjTlksN3M3Uj0G8L47ZFFWx50H6AjW8LpYUwKoIQCkdQhUIxvNHguw4KK+7NjXvlDpwViT5ndE+NCSRAn/Dwxtk8u95S8gcmr0XnO3WNYWl3IS9Mij5yo1gy+Qj8m+9BuvvDyMxteJRhp3jjHT6m7tK6kcuzLXIIRn97b4/wYABGgeyyKAyiTONzu+Gf9wgCzyAEXyYLiynW7Vz+Y18XyJYFIg6pMRJNh8b5iOhRehYDNLQrZ57GfXuErNw4BGH+E/XxFrTPnFWTVCKv0jhFVFkVHSV+3eZiU0GoG2V9FDTrvUkhvcP3u3N4C8Kh8OT+CQY3YSCzo75FVAb3gU0x41YBjDBViUfguJbRE50PfyO9sILz8rQ/m69qo3aZ3M/q5pnlTU0g02io=----ATTACHMENT:----MTI0NzEyMDEyNTUzNTEzOCA0Nzk3MTUyOTQzMzAyOTQ4IDg1Mjc1NzExMTkyNjA1MTU=