Преглед изворни кода

made the logger optional in AdminExtractor

Lukas Kahwe Smith пре 12 година
родитељ
комит
f15aabd6bc

+ 1 - 1
Resources/config/core.xml

@@ -40,8 +40,8 @@
         <!-- Translation extractor -->
         <service id="sonata.admin.translator.extractor.jms_translator_bundle" class="Sonata\AdminBundle\Translator\Extractor\JMSTranslatorBundle\AdminExtractor" >
             <tag name="jms_translation.extractor" alias="sonata_admin"/>
-            <argument type="service" id="logger" />
             <argument type="service" id="sonata.admin.pool" />
+            <argument type="service" id="logger" on-invalid="ignore" />
         </service>
 
         <!-- controller as services -->

+ 8 - 4
Translator/Extractor/JMSTranslatorBundle/AdminExtractor.php

@@ -25,10 +25,10 @@ class AdminExtractor implements ExtractorInterface, TranslatorInterface, Securit
     private $domain;
 
     /**
-     * @param \Symfony\Component\HttpKernel\Log\LoggerInterface $logger
      * @param \Sonata\AdminBundle\Admin\Pool                    $adminPool
+     * @param \Symfony\Component\HttpKernel\Log\LoggerInterface $logger
      */
-    public function __construct(LoggerInterface $logger, Pool $adminPool)
+    public function __construct(Pool $adminPool, LoggerInterface $logger = null)
     {
         $this->logger    = $logger;
         $this->adminPool = $adminPool;
@@ -91,14 +91,18 @@ class AdminExtractor implements ExtractorInterface, TranslatorInterface, Securit
                 )
             );
 
-            $this->logger->info(sprintf('Retrieving message from admin:%s - class: %s', $admin->getCode(), get_class($admin)));
+            if ($this->logger) {
+                $this->logger->info(sprintf('Retrieving message from admin:%s - class: %s', $admin->getCode(), get_class($admin)));
+            }
 
             foreach ($methods as $method => $calls) {
                 foreach ($calls as $args) {
                     try {
                         call_user_func_array(array($admin, $method), $args);
                     } catch (\Exception $e) {
-                        $this->logger->err(sprintf('ERROR : admin:%s - Raise an exception : %s', $admin->getCode(), $e->getMessage()));
+                        if ($this->logger) {
+                            $this->logger->err(sprintf('ERROR : admin:%s - Raise an exception : %s', $admin->getCode(), $e->getMessage()));
+                        }
 
                         throw $e;
                     }