55 * @license https://github.com/dotkernel/dot-controller-plugin-mail/blob/master/LICENSE.md MIT License
66 */
77
8+ declare (strict_types = 1 );
9+
810namespace Dot \Controller \Plugin \Mail ;
911
1012use Dot \Controller \Plugin \PluginInterface ;
@@ -81,7 +83,7 @@ public function __invoke(
8183 * @param array $args
8284 * @return array
8385 */
84- protected function normalizeMailArgs (array $ args )
86+ protected function normalizeMailArgs (array $ args ): array
8587 {
8688 // If the first argument is an array, use it as the mail configuration
8789 if (is_array ($ args [0 ])) {
@@ -107,8 +109,16 @@ protected function applyArgsToMailService(array $args)
107109 if (isset ($ args ['body ' ])) {
108110 $ body = $ args ['body ' ];
109111 if (is_array ($ body )) {
110- //consider this as a template name and its params
111- $ this ->mailService ->setTemplate ($ body [0 ], $ body [1 ]);
112+ $ charset = $ body ['charset ' ] ?? MailServiceInterface::DEFAULT_CHARSET ;
113+ if (isset ($ body ['content ' ]) && is_string ($ body ['content ' ])) {
114+ $ this ->mailService ->setBody ($ body ['content ' ], $ charset );
115+ } elseif (isset ($ body ['template ' ]) && is_array ($ body ['template ' ])) {
116+ $ name = $ body ['template ' ]['name ' ] ?? '' ;
117+ $ params = $ body ['template ' ]['params ' ] ?? [];
118+ if (!empty ($ name )) {
119+ $ this ->mailService ->setTemplate ($ name , $ params , $ charset );
120+ }
121+ }
112122 } else {
113123 $ this ->mailService ->setBody ($ body );
114124 }
@@ -149,18 +159,16 @@ protected function applyArgsToMailService(array $args)
149159 /**
150160 * @return MailServiceInterface
151161 */
152- public function getMailService ()
162+ public function getMailService (): MailServiceInterface
153163 {
154164 return $ this ->mailService ;
155165 }
156166
157167 /**
158168 * @param MailServiceInterface $mailService
159- * @return $this
160169 */
161170 public function setMailService (MailServiceInterface $ mailService )
162171 {
163172 $ this ->mailService = $ mailService ;
164- return $ this ;
165173 }
166174}
0 commit comments