Skip to content

Commit c759a88

Browse files
authored
Develop (#2)
* refactoring
1 parent c1b98ea commit c759a88

5 files changed

Lines changed: 44 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## 0.1.0 - 2017-03-09
2+
3+
Initial tagged release
4+
5+
### Added
6+
* Everything
7+
8+
### Deprecated
9+
* Nothing
10+
11+
### Removed
12+
* Nothing
13+
14+
### Fixed
15+
* Nothing

composer.json

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dotkernel/dot-controller-plugin-mail",
33
"type": "library",
4-
"description": "Mail controller plugin for easy access of mail services inside DK controllers",
4+
"description": "DotKernel mail controller plugin component",
55
"license": "MIT",
66
"authors": [
77
{
@@ -10,18 +10,15 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^5.6 || ^7.0",
13+
"php": "^7.1",
1414
"container-interop/container-interop": "^1.1",
1515

16-
"dotkernel/dot-controller": "0.6.x-dev"
16+
"dotkernel/dot-controller": "~0.1",
17+
"dotkernel/dot-mail": "~0.1"
1718
},
1819
"require-dev": {
1920
"phpunit/phpunit": "^4.8",
20-
"squizlabs/php_codesniffer": "^2.3",
21-
22-
"dotkernel/dot-event": "0.6.x-dev",
23-
"dotkernel/dot-helpers": "0.6.x-dev",
24-
"dotkernel/dot-mail": "0.6.x-dev"
21+
"squizlabs/php_codesniffer": "^2.3"
2522
},
2623
"autoload": {
2724
"psr-4": {
@@ -35,7 +32,7 @@
3532
},
3633
"extra": {
3734
"branch-alias": {
38-
"dev-master": "0.6-dev"
35+
"dev-master": "0.2-dev"
3936
}
4037
}
4138
}

src/ConfigProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* Time: 7:49 PM
88
*/
99

10+
declare(strict_types = 1);
11+
1012
namespace Dot\Controller\Plugin\Mail;
1113

1214
use Dot\Controller\Plugin\Mail\Factory\MailPluginAbstractFactory;
@@ -20,11 +22,10 @@ class ConfigProvider
2022
/**
2123
* @return array
2224
*/
23-
public function __invoke()
25+
public function __invoke(): array
2426
{
2527
return [
2628
'dot_controller' => [
27-
2829
'plugin_manager' => [
2930
'abstract_factories' => [
3031
MailPluginAbstractFactory::class,

src/Factory/MailPluginAbstractFactory.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* Time: 7:49 PM
88
*/
99

10+
declare(strict_types = 1);
11+
1012
namespace Dot\Controller\Plugin\Mail\Factory;
1113

1214
use Dot\Controller\Plugin\Mail\MailPlugin;
@@ -27,7 +29,7 @@ class MailPluginAbstractFactory extends AbstractMailFactory
2729
* @param string $requestedName
2830
* @return bool
2931
*/
30-
public function canCreate(ContainerInterface $container, $requestedName)
32+
public function canCreate(ContainerInterface $container, $requestedName): bool
3133
{
3234
if (strpos($requestedName, 'sendMail') !== 0) {
3335
return false;
@@ -45,7 +47,7 @@ public function canCreate(ContainerInterface $container, $requestedName)
4547
* @param $requestedName
4648
* @return string
4749
*/
48-
protected function getSpecificServiceName($requestedName)
50+
protected function getSpecificServiceName(string $requestedName): string
4951
{
5052
$parts = explode('_', $this->camelCaseToUnderscore($requestedName));
5153

@@ -65,7 +67,7 @@ protected function getSpecificServiceName($requestedName)
6567
* @param $value
6668
* @return mixed
6769
*/
68-
protected function camelCaseToUnderscore($value)
70+
protected function camelCaseToUnderscore(string $value): string
6971
{
7072
if (!is_scalar($value) && !is_array($value)) {
7173
return $value;
@@ -88,7 +90,7 @@ protected function camelCaseToUnderscore($value)
8890
* @param array|null $options
8991
* @return MailPlugin
9092
*/
91-
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
93+
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): MailPlugin
9294
{
9395
$specificServiceName = $this->getSpecificServiceName($requestedName);
9496

src/MailPlugin.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* Time: 7:49 PM
88
*/
99

10+
declare(strict_types = 1);
11+
1012
namespace Dot\Controller\Plugin\Mail;
1113

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

Comments
 (0)