]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Inject parameter instead of service
authorJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 30 Oct 2016 19:27:41 +0000 (20:27 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 30 Oct 2016 19:27:41 +0000 (20:27 +0100)
We are injecting CraueConfig service when we only need to retrieve one or two values from it.
Instead I discovered we can directly inject a value from a service in the service definition!

src/Wallabag/CoreBundle/Helper/EntriesExport.php
src/Wallabag/CoreBundle/Resources/config/services.yml
src/Wallabag/ImportBundle/Resources/config/services.yml
src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
src/Wallabag/UserBundle/Resources/config/services.yml

index e50c68a67a91f0870a97f254df0328ace7e886c8..4bf292a4f815c0a32b4f26be31ea9cd76d9ce135 100644 (file)
@@ -8,7 +8,6 @@ use JMS\Serializer\SerializerBuilder;
 use PHPePub\Core\EPub;
 use PHPePub\Core\Structure\OPF\DublinCore;
 use Symfony\Component\HttpFoundation\Response;
-use Craue\ConfigBundle\Util\Config;
 
 /**
  * This class doesn't have unit test BUT it's fully covered by a functional test with ExportControllerTest.
@@ -27,12 +26,12 @@ class EntriesExport
         </div>';
 
     /**
-     * @param Config $craueConfig CraueConfig instance to get wallabag instance url from database
+     * @param string $wallabagUrl Wallabag instance url
      * @param string $logoPath    Path to the logo FROM THE BUNDLE SCOPE
      */
-    public function __construct(Config $craueConfig, $logoPath)
+    public function __construct($wallabagUrl, $logoPath)
     {
-        $this->wallabagUrl = $craueConfig->get('wallabag_url');
+        $this->wallabagUrl = $wallabagUrl;
         $this->logoPath = $logoPath;
     }
 
index 614488a64fd92596243a19ba5bea04d81c989c1a..b7b1b61beec1becfc979f5c0bd504db4412cc74e 100644 (file)
@@ -91,7 +91,7 @@ services:
     wallabag_core.helper.entries_export:
         class: Wallabag\CoreBundle\Helper\EntriesExport
         arguments:
-            - "@craue_config"
+            - '@=service(''craue_config'').get(''wallabag_url'')'
             - src/Wallabag/CoreBundle/Resources/public/themes/_global/img/appicon/apple-touch-icon-152.png
 
     wallabag.operator.array.matches:
index 89adc71b3453a4dd720b3a99bcc0ce5a438a1fd1..d600be0f800e25f8fb87045cf7dedec2cef05b10 100644 (file)
@@ -20,7 +20,6 @@ services:
         arguments:
             - "@doctrine.orm.entity_manager"
             - "@wallabag_core.content_proxy"
-            - "@craue_config"
         calls:
             - [ setClient, [ "@wallabag_import.pocket.client" ] ]
             - [ setLogger, [ "@logger" ]]
index ca9d18f171bc8974b64731774e62f001d78a0605..961208f27d2ff1340c93806d77a8a83a149c62af 100644 (file)
@@ -4,7 +4,6 @@ namespace Wallabag\UserBundle\Mailer;
 
 use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
 use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface;
-use Craue\ConfigBundle\Util\Config;
 
 /**
  * Custom mailer for TwoFactorBundle email.
@@ -61,16 +60,17 @@ class AuthCodeMailer implements AuthCodeMailerInterface
      * @param \Twig_Environment $twig
      * @param string            $senderEmail
      * @param string            $senderName
-     * @param Config            $craueConfig Craue\Config instance to get wallabag support url from database
+     * @param string            $supportUrl  wallabag support url
+     * @param string            $wallabagUrl wallabag instance url
      */
-    public function __construct(\Swift_Mailer $mailer, \Twig_Environment $twig, $senderEmail, $senderName, Config $craueConfig)
+    public function __construct(\Swift_Mailer $mailer, \Twig_Environment $twig, $senderEmail, $senderName, $supportUrl, $wallabagUrl)
     {
         $this->mailer = $mailer;
         $this->twig = $twig;
         $this->senderEmail = $senderEmail;
         $this->senderName = $senderName;
-        $this->supportUrl = $craueConfig->get('wallabag_support_url');
-        $this->wallabagUrl = $craueConfig->get('wallabag_url');
+        $this->supportUrl = $supportUrl;
+        $this->wallabagUrl = $wallabagUrl;
     }
 
     /**
index eb9c8e676e0cbd03b4f92eda2b502a1f5c88ad32..a8ee721b9e60f70a66071cc6e698849a92a02152 100644 (file)
@@ -6,7 +6,8 @@ services:
             - "@twig"
             - "%scheb_two_factor.email.sender_email%"
             - "%scheb_two_factor.email.sender_name%"
-            - "@craue_config"
+            - '@=service(''craue_config'').get(''wallabag_support_url'')'
+            - '@=service(''craue_config'').get(''wallabag_url'')'
 
     wallabag_user.password_resetting:
         class: Wallabag\UserBundle\EventListener\PasswordResettingListener