Procházet zdrojové kódy

[DependencyInjection] refactored code a bit, added some more logging messages

Johannes M. Schmitt před 14 roky
rodič
revize
6ea9fb16c7

+ 4 - 1
src/Symfony/Component/DependencyInjection/Compiler/Compiler.php

@@ -107,11 +107,14 @@ class Compiler
      */
     public function compile(ContainerBuilder $container)
     {
+        $start = microtime(true);
         foreach ($this->passConfig->getPasses() as $pass) {
             $this->startPass($pass);
             $pass->process($container);
             $this->endPass($pass);
         }
+
+        $this->addLogMessage(sprintf('Compilation finished in %.3fs.', microtime(true) - $start));
     }
 
     /**
@@ -133,6 +136,6 @@ class Compiler
     private function endPass(CompilerPassInterface $pass)
     {
         $this->currentPass = null;
-        $this->addLogMessage(sprintf('%s finished in %.3fs', get_class($pass), microtime(true) - $this->currentStartTime));
+        $this->addLogMessage($this->loggingFormatter->formatPassTime($pass, microtime(true) - $this->currentStartTime));
     }
 }

+ 1 - 1
src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php

@@ -82,7 +82,7 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface
                 }
 
                 if ($this->isInlinableDefinition($container, $id, $definition = $container->getDefinition($id))) {
-                    $this->compiler->addLogMessage($this->formatter->formatInlineDefinition($this, $id, $this->currentId));
+                    $this->compiler->addLogMessage($this->formatter->formatInlineService($this, $id, $this->currentId));
 
                     if (ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope()) {
                         $arguments[$k] = $definition;

+ 14 - 4
src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php

@@ -11,14 +11,24 @@ use Symfony\Component\DependencyInjection\Definition;
  */
 class LoggingFormatter
 {
-    public function formatRemoveDefinition(CompilerPassInterface $pass, $id, $reason)
+    public function formatRemoveService(CompilerPassInterface $pass, $id, $reason)
     {
-        return $this->format($pass, sprintf('Removed definition "%s"; reason: %s', $id, $reason));
+        return $this->format($pass, sprintf('Removed service "%s"; reason: %s', $id, $reason));
     }
 
-    public function formatInlineDefinition(CompilerPassInterface $pass, $id, $target)
+    public function formatInlineService(CompilerPassInterface $pass, $id, $target)
     {
-        return $this->format($pass, sprintf('Inlined definition "%s" to "%s".', $id, $target));
+        return $this->format($pass, sprintf('Inlined service "%s" to "%s".', $id, $target));
+    }
+
+    public function formatResolveInheritance(CompilerPassInterface $pass, $childId, $parentId)
+    {
+        return $this->format($pass, sprintf('Resolving inheritance for "%s" (parent: %s).', $childId, $parentId));
+    }
+
+    public function formatPassTime(CompilerPassInterface $pass, $time)
+    {
+        return $this->format($pass, sprintf('finished in %.3fs.', $time));
     }
 
     public function format(CompilerPassInterface $pass, $message)

+ 1 - 1
src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php

@@ -23,7 +23,7 @@ class RemoveAbstractDefinitionsPass implements CompilerPassInterface
         foreach ($container->getDefinitions() as $id => $definition) {
             if ($definition->isAbstract()) {
                 $container->remove($id);
-                $compiler->addLogMessage($formatter->formatRemoveDefinition($this, $id, 'abstract'));
+                $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'abstract'));
             }
         }
     }

+ 1 - 1
src/Symfony/Component/DependencyInjection/Compiler/RemovePrivateAliasesPass.php

@@ -38,7 +38,7 @@ class RemovePrivateAliasesPass implements CompilerPassInterface
             }
 
             $container->removeAlias($id);
-            $compiler->addLogMessage($formatter->formatRemoveDefinition($this, $id, 'private alias'));
+            $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'private alias'));
         }
     }
 }

+ 1 - 1
src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php

@@ -76,7 +76,7 @@ class RemoveUnusedDefinitionsPass implements RepeatablePassInterface
                 $compiler->addLogMessage($formatter->formatRemovedDefinition($this, $id, 'replaces alias '.reset($referencingAliases)));
             } else if (0 === count($referencingAliases) && false === $isReferenced) {
                 $container->remove($id);
-                $compiler->addLogMessage($formatter->formatRemoveDefinition($this, $id, 'unused'));
+                $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'unused'));
                 $hasChanged = true;
             }
         }

+ 6 - 0
src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php

@@ -15,6 +15,8 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
 class ResolveDefinitionTemplatesPass implements CompilerPassInterface
 {
     private $container;
+    private $compiler;
+    private $formatter;
 
     /**
      * Process the ContainerBuilder to replace DefinitionDecorator instances with their real Definition instances.
@@ -24,6 +26,9 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
     public function process(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
@@ -54,6 +59,7 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
             $parentDef = $this->resolveDefinition($parent, $parentDef);
         }
 
+        $this->compiler->addLogMessage($this->formatter->formatResolveInheritance($this, $id, $parent));
         $def = new Definition();
 
         // merge in parent definition