]> git.agnieray.net Git - galette.git/blobdiff - galette/lib/Galette/Features/Replacements.php
Properly use injection
[galette.git] / galette / lib / Galette / Features / Replacements.php
index 63fee5b82b3ff020d00a92579d79be21dcaaf266..31fb5ad74def6c73461e34f31ed9bd73c4b53285 100644 (file)
@@ -51,7 +51,9 @@ use Galette\Repository\DynamicFieldsSet;
 use Galette\DynamicFields\DynamicField;
 use Analog\Analog;
 use NumberFormatter;
+use PHPMailer\PHPMailer\PHPMailer;
 use Slim\Routing\RouteParser;
+use DI\Attribute\Inject;
 
 /**
  * Replacements feature
@@ -71,6 +73,7 @@ trait Replacements
     private $patterns = [];
     private $replaces = [];
     private $dynamic_patterns = [];
+    private ?PHPMailer $mail = null;
 
     /**
      * @var Db
@@ -466,6 +469,19 @@ trait Replacements
         return $c_patterns + $dynamic_patterns;
     }
 
+    /**
+     * Set mail instance
+     *
+     * @param PHPMailer $mail PHPMailer instance
+     *
+     * @return self
+     */
+    public function setMail(PHPMailer $mail): self
+    {
+        $this->mail = $mail;
+        return $this;
+    }
+
     /**
      * Set main replacements
      *
@@ -483,11 +499,17 @@ trait Replacements
         }
 
         $logo = new Logo();
-        $logo_elt = '<img' .
-            ' src="' . $this->preferences->getURL() . $this->routeparser->urlFor('logo') . '"' .
-            ' width="' . $logo->getOptimalWidth() . '"' .
-            ' height="' . $logo->getOptimalHeight() . '"' .
-            '/>';
+        if ($this->mail !== null) {
+            $logo_content = $this->preferences->getURL() . $this->routeparser->urlFor('logo');
+        } else {
+            $logo_content = '@' . base64_encode(file_get_contents($logo->getPath()));
+        }
+        $logo_elt = sprintf(
+            '<img src="%1$s" width="%2$s" height="%3$s" alt="" />',
+            $logo_content,
+            $logo->getOptimalWidth(),
+            $logo->getOptimalHeight()
+        );
 
         $this->setReplacements(
             array(
@@ -911,7 +933,7 @@ trait Replacements
             $replaced
         );
 
-        return $replaced;
+        return trim($replaced);
     }
 
     /**