77 * Time: 7:49 PM
88 */
99
10+ declare (strict_types = 1 );
11+
1012namespace Dot \Controller \Plugin \Mail ;
1113
1214use Dot \Controller \Plugin \PluginInterface ;
@@ -83,7 +85,7 @@ public function __invoke(
8385 * @param array $args
8486 * @return array
8587 */
86- protected function normalizeMailArgs (array $ args )
88+ protected function normalizeMailArgs (array $ args ): array
8789 {
8890 // If the first argument is an array, use it as the mail configuration
8991 if (is_array ($ args [0 ])) {
@@ -109,8 +111,16 @@ protected function applyArgsToMailService(array $args)
109111 if (isset ($ args ['body ' ])) {
110112 $ body = $ args ['body ' ];
111113 if (is_array ($ body )) {
112- //consider this as a template name and its params
113- $ this ->mailService ->setTemplate ($ body [0 ], $ body [1 ]);
114+ $ charset = $ body ['charset ' ] ?? MailServiceInterface::DEFAULT_CHARSET ;
115+ if (isset ($ body ['content ' ]) && is_string ($ body ['content ' ])) {
116+ $ this ->mailService ->setBody ($ body ['content ' ], $ charset );
117+ } elseif (isset ($ body ['template ' ]) && is_array ($ body ['template ' ])) {
118+ $ name = $ body ['template ' ]['name ' ] ?? '' ;
119+ $ params = $ body ['template ' ]['params ' ] ?? [];
120+ if (!empty ($ name )) {
121+ $ this ->mailService ->setTemplate ($ name , $ params , $ charset );
122+ }
123+ }
114124 } else {
115125 $ this ->mailService ->setBody ($ body );
116126 }
@@ -151,18 +161,16 @@ protected function applyArgsToMailService(array $args)
151161 /**
152162 * @return MailServiceInterface
153163 */
154- public function getMailService ()
164+ public function getMailService (): MailServiceInterface
155165 {
156166 return $ this ->mailService ;
157167 }
158168
159169 /**
160170 * @param MailServiceInterface $mailService
161- * @return $this
162171 */
163172 public function setMailService (MailServiceInterface $ mailService )
164173 {
165174 $ this ->mailService = $ mailService ;
166- return $ this ;
167175 }
168176}
0 commit comments