/** * Processes a ContainerBuilder object to populate the service reference graph. * * @param ehough_iconic_ContainerBuilder $container */ public function process(ehough_iconic_ContainerBuilder $container) { $this->container = $container; $this->graph = $container->getCompiler()->getServiceReferenceGraph(); $this->graph->clear(); foreach ($container->getDefinitions() as $id => $definition) { if ($definition->isSynthetic() || $definition->isAbstract()) { continue; } $this->currentId = $id; $this->currentDefinition = $definition; $this->processArguments($definition->getArguments()); if ($definition->getFactoryService()) { $this->processArguments(array(new ehough_iconic_Reference($definition->getFactoryService()))); } if (!$this->onlyConstructorArguments) { $this->processArguments($definition->getMethodCalls()); $this->processArguments($definition->getProperties()); if ($definition->getConfigurator()) { $this->processArguments(array($definition->getConfigurator())); } } } foreach ($container->getAliases() as $id => $alias) { $this->graph->connect($id, $alias, (string) $alias, $this->getDefinition((string) $alias), null); } }
/** * Process the Container to replace aliases with service definitions. * * @param ehough_iconic_ContainerBuilder $container * * @throws ehough_iconic_exception_InvalidArgumentException if the service definition does not exist */ public function process(ehough_iconic_ContainerBuilder $container) { $this->compiler = $container->getCompiler(); $this->formatter = $this->compiler->getLoggingFormatter(); foreach ($container->getAliases() as $id => $alias) { $aliasId = (string) $alias; try { $definition = $container->getDefinition($aliasId); } catch (ehough_iconic_exception_InvalidArgumentException $e) { if (version_compare(PHP_VERSION, '5.3') < 0) { throw new ehough_iconic_exception_InvalidArgumentException(sprintf('Unable to replace alias "%s" with "%s".', $alias, $id), null); } else { throw new ehough_iconic_exception_InvalidArgumentException(sprintf('Unable to replace alias "%s" with "%s".', $alias, $id), null, $e); } } if ($definition->isPublic()) { continue; } $definition->setPublic(true); $container->setDefinition($id, $definition); $container->removeDefinition($aliasId); $this->updateReferences($container, $aliasId, $id); // we have to restart the process due to concurrent modification of // the container $this->process($container); break; } }
/** * Checks the ContainerBuilder object for circular references. * * @param ehough_iconic_ContainerBuilder $container The ContainerBuilder instances */ public function process(ehough_iconic_ContainerBuilder $container) { $graph = $container->getCompiler()->getServiceReferenceGraph(); $this->checkedNodes = array(); foreach ($graph->getNodes() as $id => $node) { $this->currentId = $id; $this->currentPath = array($id); $this->checkOutEdges($node->getOutEdges()); } }
/** * Removes abstract definitions from the ContainerBuilder * * @param ehough_iconic_ContainerBuilder $container */ public function process(ehough_iconic_ContainerBuilder $container) { $compiler = $container->getCompiler(); $formatter = $compiler->getLoggingFormatter(); foreach ($container->getDefinitions() as $id => $definition) { if ($definition->isAbstract()) { $container->removeDefinition($id); $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'abstract')); } } }
/** * Removes private aliases from the ContainerBuilder * * @param ehough_iconic_ContainerBuilder $container */ public function process(ehough_iconic_ContainerBuilder $container) { $compiler = $container->getCompiler(); $formatter = $compiler->getLoggingFormatter(); foreach ($container->getAliases() as $id => $alias) { if ($alias->isPublic()) { continue; } $container->removeAlias($id); $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'private alias')); } }
/** * Processes the ContainerBuilder for inline service definitions. * * @param ehough_iconic_ContainerBuilder $container */ public function process(ehough_iconic_ContainerBuilder $container) { $this->compiler = $container->getCompiler(); $this->formatter = $this->compiler->getLoggingFormatter(); $this->graph = $this->compiler->getServiceReferenceGraph(); foreach ($container->getDefinitions() as $id => $definition) { $this->currentId = $id; $definition->setArguments($this->inlineArguments($container, $definition->getArguments())); $definition->setMethodCalls($this->inlineArguments($container, $definition->getMethodCalls())); $definition->setProperties($this->inlineArguments($container, $definition->getProperties())); } }
/** * Process the ContainerBuilder to replace ehough_iconic_DefinitionDecorator instances with their real ehough_iconic_Definition instances. * * @param ehough_iconic_ContainerBuilder $container */ public function process(ehough_iconic_ContainerBuilder $container) { $this->container = $container; $this->compiler = $container->getCompiler(); $this->formatter = $this->compiler->getLoggingFormatter(); foreach (array_keys($container->getDefinitions()) as $id) { // yes, we are specifically fetching the definition from the // container to ensure we are not operating on stale data $definition = $container->getDefinition($id); if (!$definition instanceof ehough_iconic_DefinitionDecorator || $definition->isAbstract()) { continue; } $this->resolveDefinition($id, $definition); } }
/** * Processes the ContainerBuilder to remove unused definitions. * * @param ehough_iconic_ContainerBuilder $container */ public function process(ehough_iconic_ContainerBuilder $container) { $compiler = $container->getCompiler(); $formatter = $compiler->getLoggingFormatter(); $graph = $compiler->getServiceReferenceGraph(); $hasChanged = false; foreach ($container->getDefinitions() as $id => $definition) { if ($definition->isPublic()) { continue; } if ($graph->hasNode($id)) { $edges = $graph->getNode($id)->getInEdges(); $referencingAliases = array(); $sourceIds = array(); foreach ($edges as $edge) { $node = $edge->getSourceNode(); $sourceIds[] = $node->getId(); if ($node->isAlias()) { $referencingAliases[] = $node->getValue(); } } $isReferenced = count(array_unique($sourceIds)) - count($referencingAliases) > 0; } else { $referencingAliases = array(); $isReferenced = false; } if (1 === count($referencingAliases) && false === $isReferenced) { $container->setDefinition((string) reset($referencingAliases), $definition); $definition->setPublic(true); $container->removeDefinition($id); $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'replaces alias ' . reset($referencingAliases))); } elseif (0 === count($referencingAliases) && false === $isReferenced) { $container->removeDefinition($id); $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'unused')); $hasChanged = true; } } if ($hasChanged) { $this->repeatedPass->setRepeat(); } }