Completed
Push — master ( 111bcd...99ca87 )
by Andrey
26:30
created

createService()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.2
cc 4
eloc 11
nc 6
nop 1
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/jms-serializer-module
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\JmsSerializerModule\ModuleServiceManager;
7
8
use Zend\ServiceManager\FactoryInterface;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
use Zend\ServiceManager\Config;
11
use Nnx\JmsSerializerModule\Module;
12
13
14
/**
15
 * Class JmsSerializerModuleServiceManagerFactory
16
 *
17
 * @package Nnx\JmsSerializerModule\ModuleServiceManager
18
 */
19
class JmsSerializerModuleServiceManagerFactory implements FactoryInterface
20
{
21
22
    /**
23
     * @param ServiceLocatorInterface $serviceLocator
24
     *
25
     * @return JmsSerializerModuleServiceManager
26
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
27
     */
28
    public function createService(ServiceLocatorInterface $serviceLocator)
29
    {
30
        $appConfig = $serviceLocator->get('config');
31
        $isModuleConfig =
32
            is_array($appConfig)
33
            && array_key_exists(Module::MODULE_SERVICE_MANAGER_CONFIG_KEY, $appConfig)
34
            && is_array($appConfig[Module::MODULE_SERVICE_MANAGER_CONFIG_KEY]);
35
        $moduleServiceManagerConfig = $isModuleConfig ? $appConfig[Module::MODULE_SERVICE_MANAGER_CONFIG_KEY] : [];
36
37
        $configuration = new Config($moduleServiceManagerConfig);
38
        $jmsSerializerModuleServiceManager = new JmsSerializerModuleServiceManager($configuration);
39
        $jmsSerializerModuleServiceManager->setServiceLocator($serviceLocator);
40
        return $jmsSerializerModuleServiceManager;
41
    }
42
}
43