1
|
|
|
<?php |
2
|
|
|
namespace AcMailer\Factory; |
3
|
|
|
|
4
|
|
|
use Interop\Container\ContainerInterface; |
5
|
|
|
use Zend\ServiceManager\Exception\ServiceNotCreatedException; |
6
|
|
|
use Zend\ServiceManager\Exception\ServiceNotFoundException; |
7
|
|
|
use Zend\ServiceManager\Factory\AbstractFactoryInterface; |
8
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class AbstractAcMailerFactory |
12
|
|
|
* @author Alejandro Celaya Alastrué |
13
|
|
|
* @link http://www.alejandrocelaya.com |
14
|
|
|
*/ |
15
|
|
|
abstract class AbstractAcMailerFactory implements AbstractFactoryInterface |
16
|
|
|
{ |
17
|
|
|
const ACMAILER_PART = 'acmailer'; |
18
|
|
|
const SPECIFIC_PART = ''; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Can the factory create an instance for the service? |
22
|
|
|
* |
23
|
|
|
* @param ContainerInterface $container |
24
|
|
|
* @param string $requestedName |
25
|
1 |
|
* @return bool |
26
|
|
|
*/ |
27
|
1 |
|
public function canCreate(ContainerInterface $container, $requestedName) |
28
|
1 |
|
{ |
29
|
1 |
|
$parts = explode('.', $requestedName); |
30
|
|
|
if (count($parts) !== 3) { |
31
|
|
|
return false; |
32
|
1 |
|
} |
33
|
1 |
|
|
34
|
|
|
if ($parts[0] !== self::ACMAILER_PART || $parts[1] !== static::SPECIFIC_PART) { |
35
|
|
|
return false; |
36
|
1 |
|
} |
37
|
1 |
|
|
38
|
1 |
|
$specificServiceName = $parts[2]; |
39
|
|
|
$config = $this->getConfig($container); |
40
|
|
|
return array_key_exists($specificServiceName, $config); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param ContainerInterface $container |
45
|
9 |
|
* @return array |
46
|
|
|
*/ |
47
|
9 |
|
protected function getConfig(ContainerInterface $container) |
48
|
9 |
|
{ |
49
|
8 |
|
$config = $container->get('Config'); |
50
|
2 |
|
if (isset($config['acmailer_options']) && is_array($config['acmailer_options'])) { |
51
|
1 |
|
return $config['acmailer_options']; |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
return []; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|