Skip to content

Commit 398a6f6

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # CHANGELOG.md # composer.json
2 parents b60acd2 + c759a88 commit 398a6f6

3 files changed

Lines changed: 23 additions & 12 deletions

File tree

src/ConfigProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* @license https://github.com/dotkernel/dot-controller-plugin-mail/blob/master/LICENSE.md MIT License
66
*/
77

8+
declare(strict_types = 1);
9+
810
namespace Dot\Controller\Plugin\Mail;
911

1012
use Dot\Controller\Plugin\Mail\Factory\MailPluginAbstractFactory;
@@ -18,11 +20,10 @@ class ConfigProvider
1820
/**
1921
* @return array
2022
*/
21-
public function __invoke()
23+
public function __invoke(): array
2224
{
2325
return [
2426
'dot_controller' => [
25-
2627
'plugin_manager' => [
2728
'abstract_factories' => [
2829
MailPluginAbstractFactory::class,

src/Factory/MailPluginAbstractFactory.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* @license https://github.com/dotkernel/dot-controller-plugin-mail/blob/master/LICENSE.md MIT License
66
*/
77

8+
declare(strict_types = 1);
9+
810
namespace Dot\Controller\Plugin\Mail\Factory;
911

1012
use Dot\Controller\Plugin\Mail\MailPlugin;
@@ -25,7 +27,7 @@ class MailPluginAbstractFactory extends AbstractMailFactory
2527
* @param string $requestedName
2628
* @return bool
2729
*/
28-
public function canCreate(ContainerInterface $container, $requestedName)
30+
public function canCreate(ContainerInterface $container, $requestedName): bool
2931
{
3032
if (strpos($requestedName, 'sendMail') !== 0) {
3133
return false;
@@ -43,7 +45,7 @@ public function canCreate(ContainerInterface $container, $requestedName)
4345
* @param $requestedName
4446
* @return string
4547
*/
46-
protected function getSpecificServiceName($requestedName)
48+
protected function getSpecificServiceName(string $requestedName): string
4749
{
4850
$parts = explode('_', $this->camelCaseToUnderscore($requestedName));
4951

@@ -63,7 +65,7 @@ protected function getSpecificServiceName($requestedName)
6365
* @param $value
6466
* @return mixed
6567
*/
66-
protected function camelCaseToUnderscore($value)
68+
protected function camelCaseToUnderscore(string $value): string
6769
{
6870
if (!is_scalar($value) && !is_array($value)) {
6971
return $value;
@@ -86,7 +88,7 @@ protected function camelCaseToUnderscore($value)
8688
* @param array|null $options
8789
* @return MailPlugin
8890
*/
89-
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
91+
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): MailPlugin
9092
{
9193
$specificServiceName = $this->getSpecificServiceName($requestedName);
9294

src/MailPlugin.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* @license https://github.com/dotkernel/dot-controller-plugin-mail/blob/master/LICENSE.md MIT License
66
*/
77

8+
declare(strict_types = 1);
9+
810
namespace Dot\Controller\Plugin\Mail;
911

1012
use 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

Comments
 (0)