From d2b83a6a0e349c185d04ec93d8fb832c03925999 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 4 Jul 2014 00:13:26 +0200 Subject: [PATCH] Removed all DIC dependency in twig extension and DataCollector * Instead of that, just injected in both cases expected service instance --- DataCollector/LadybugDataCollector.php | 17 +++++++++-------- Resources/config/services.xml | 4 ++-- Twig/Extension/LadybugExtension.php | 26 +++++++++----------------- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/DataCollector/LadybugDataCollector.php b/DataCollector/LadybugDataCollector.php index 10a75e7..162a3d9 100644 --- a/DataCollector/LadybugDataCollector.php +++ b/DataCollector/LadybugDataCollector.php @@ -7,6 +7,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; +use Ladybug\Dumper; /** * The LadybugDataCollector class. @@ -14,19 +15,20 @@ class LadybugDataCollector extends DataCollector { /** + * @var Dumper * - * @var ContainerInterface $container The Symfony DIC. + * Ladybug Dumper */ - private $container; + private $ladybug; /** - * Main constructor. + * Main constructor * - * @param ContainerInterface $container + * @param Dumper $ladybug Ladybyg Dumper */ - public function __construct(ContainerInterface $container) + public function __construct(Dumper $ladybug) { - $this->container = $container; + $this->ladybug = $ladybug; } /** @@ -34,8 +36,7 @@ public function __construct(ContainerInterface $container) */ public function log() { - $ladybug = $this->container->get('ladybug.dumper'); - $content = call_user_func_array(array($ladybug,'dump'), func_get_args()); + $content = call_user_func_array(array($this->ladybug,'dump'), func_get_args()); $trace = debug_backtrace(); diff --git a/Resources/config/services.xml b/Resources/config/services.xml index a1d23d8..642c259 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -13,11 +13,11 @@ - + - + diff --git a/Twig/Extension/LadybugExtension.php b/Twig/Extension/LadybugExtension.php index af887d5..acbc101 100644 --- a/Twig/Extension/LadybugExtension.php +++ b/Twig/Extension/LadybugExtension.php @@ -3,6 +3,7 @@ namespace RaulFraile\Bundle\LadybugBundle\Twig\Extension; use Symfony\Component\DependencyInjection\ContainerInterface; +use Ladybug\Dumper; /** * Twig extension for the bundle. @@ -10,28 +11,20 @@ class LadybugExtension extends \Twig_Extension { /** - * @var ContainerInterface $container The Symfony2 DIC. - */ - private $container; - - /** - * Main constructor. + * @var Dumper * - * @param ContainerInterface $container + * Ladybug Dumper */ - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } + private $ladybug; /** - * Getter. + * Main constructor * - * @return ContainerInterface + * @param Dumper $ladybug Ladybyg Dumper */ - public function getContainer() + public function __construct(Dumper $ladybug) { - return $this->container; + $this->ladybug = $ladybug; } /** @@ -67,8 +60,7 @@ public function getFunctions() */ public function ladybug_dump() { - $ladybug = $this->container->get('ladybug.dumper'); - $html = call_user_func_array(array($ladybug, 'dump'), func_get_args()); + $html = call_user_func_array(array($this->ladybug, 'dump'), func_get_args()); return $html; }