1
|
|
|
<?php |
2
|
|
|
namespace AcMailer\Options\Factory; |
3
|
|
|
|
4
|
|
|
use AcMailer\Factory\AbstractAcMailerFactory; |
5
|
|
|
use AcMailer\Options\MailOptions; |
6
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
7
|
|
|
use Zend\Stdlib\ArrayUtils; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class MailOptionsAbstractFactory |
11
|
|
|
* @author Alejandro Celaya Alastrué |
12
|
|
|
* @link http://www.alejandrocelaya.com |
13
|
|
|
*/ |
14
|
|
|
class MailOptionsAbstractFactory extends AbstractAcMailerFactory |
15
|
|
|
{ |
16
|
|
|
const SPECIFIC_PART = 'mailoptions'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Create service with name |
20
|
|
|
* |
21
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
22
|
|
|
* @param $name |
23
|
|
|
* @param $requestedName |
24
|
|
|
* @return mixed |
25
|
|
|
*/ |
26
|
7 |
|
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) |
27
|
|
|
{ |
28
|
7 |
|
$specificServiceName = explode('.', $name)[2]; |
29
|
7 |
|
$config = $this->getConfig($serviceLocator); |
30
|
7 |
|
$specificConfig = $config[$specificServiceName]; |
31
|
7 |
|
if (! is_array($specificConfig)) { |
32
|
1 |
|
$specificConfig = []; |
33
|
1 |
|
} |
34
|
|
|
|
35
|
|
|
do { |
36
|
|
|
// Get extends |
37
|
7 |
|
$extendsConfigKey = isset($specificConfig['extends']) && is_string($specificConfig['extends']) |
38
|
7 |
|
? trim($specificConfig['extends']) |
39
|
7 |
|
: null; |
40
|
|
|
|
41
|
|
|
// Always unset the extends, in case it had a value null, to prevent the MailOptions object to throw an |
42
|
|
|
// exception |
43
|
7 |
|
unset($specificConfig['extends']); |
44
|
|
|
|
45
|
|
|
// Try to extend from another configuration if defined and exists |
46
|
7 |
|
if (! is_null($extendsConfigKey) |
47
|
7 |
|
&& array_key_exists($extendsConfigKey, $config) |
48
|
7 |
|
&& is_array($config[$extendsConfigKey]) |
49
|
7 |
|
) { |
50
|
3 |
|
$specificConfig = ArrayUtils::merge($config[$extendsConfigKey], $specificConfig); |
51
|
3 |
|
} |
52
|
7 |
|
} while ($extendsConfigKey != null); |
|
|
|
|
53
|
|
|
|
54
|
7 |
|
return new MailOptions($specificConfig); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|