Completed
Push — master ( a1da34...22dfea )
by Tom
23s queued 13s
created

ServiceManagerFactory::getConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace DoctrineORMModuleTest;
4
5
use Zend\Mvc\Service\ServiceManagerConfig;
6
use Zend\ServiceManager\ServiceManager;
7
8
/**
9
 * Utility used to retrieve a freshly bootstrapped application's service manager
10
 *
11
 * @license MIT
12
 * @link    http://www.doctrine-project.org/
13
 * @author  Marco Pivetta <[email protected]>
14
 */
15
class ServiceManagerFactory
16
{
17
    /**
18
     * Builds a new ServiceManager instance
19
     *
20
     * @param  array|null     $configuration
21
     * @return ServiceManager
22
     */
23
    public static function getServiceManager(array $configuration = null)
24
    {
25
        $configuration        = $configuration ?: include __DIR__ . '/../config.php';
26
        $serviceManager       = new ServiceManager();
27
        $serviceManagerConfig = new ServiceManagerConfig(
28
            $configuration['service_manager'] ?? []
29
        );
30
        $serviceManagerConfig->configureServiceManager($serviceManager);
31
        $serviceManager->setService('ApplicationConfig', $configuration);
32
33
        /** @var $moduleManager \Zend\ModuleManager\ModuleManager */
34
        $moduleManager = $serviceManager->get('ModuleManager');
35
        $moduleManager->loadModules();
36
37
        return $serviceManager;
38
    }
39
}
40