]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Helper/DownloadImages.php
Add instance url to the downloaded images
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / DownloadImages.php
index 004bb277515b1a436a761526a687c886b5f04082..e7982c560a0feec436229fc32985273e4dc51be3 100644 (file)
@@ -15,6 +15,7 @@ class DownloadImages
     private $baseFolder;
     private $logger;
     private $mimeGuesser;
+    private $wallabagUrl;
 
     public function __construct(Client $client, $baseFolder, LoggerInterface $logger)
     {
@@ -26,6 +27,17 @@ class DownloadImages
         $this->setFolder();
     }
 
+    /**
+     * Since we can't inject CraueConfig service because it'll generate a circular reference when injected in the subscriber
+     * we use a different way to inject the current wallabag url.
+     *
+     * @param string $url Usually from `$config->get('wallabag_url')`
+     */
+    public function setWallabagUrl($url)
+    {
+        $this->wallabagUrl = rtrim($url, '/');
+    }
+
     /**
      * Setup base folder where all images are going to be saved.
      */
@@ -143,7 +155,7 @@ class DownloadImages
 
         imagedestroy($im);
 
-        return '/assets/images/'.$relativePath.'/'.$hashImage.'.'.$ext;
+        return $this->wallabagUrl.'/assets/images/'.$relativePath.'/'.$hashImage.'.'.$ext;
     }
 
     /**