Completed
Push — develop ( f11aab...a4697b )
by Alejandro
09:31
created

AbstractAcMailerFactory::getConfig()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 3
eloc 5
nc 2
nop 1
crap 3
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
     * @return bool
26
     */
27 1
    public function canCreate(ContainerInterface $container, $requestedName)
28
    {
29 1
        $parts = explode('.', $requestedName);
30 1
        if (count($parts) !== 3) {
31 1
            return false;
32
        }
33
34 1
        if ($parts[0] !== self::ACMAILER_PART || $parts[1] !== static::SPECIFIC_PART) {
35 1
            return false;
36
        }
37
38 1
        $specificServiceName = $parts[2];
39 1
        $config = $this->getConfig($container);
40 1
        return array_key_exists($specificServiceName, $config);
41
    }
42
43
    /**
44
     * @param ContainerInterface $container
45
     * @return array
46
     */
47 8
    protected function getConfig(ContainerInterface $container)
48
    {
49 8
        $config = $container->get('Config');
50 8
        if (isset($config['acmailer_options']) && is_array($config['acmailer_options'])) {
51 8
            return $config['acmailer_options'];
52
        }
53
54 1
        return [];
55
    }
56
}
57