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