Completed
Push — master ( 9f08b5...90d78c )
by Андрей
03:09
created

ResourceLoaderServiceFactory::createService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/doctrine-fixture-module
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\DoctrineFixtureModule\ResourceLoader;
7
8
use Nnx\ModuleOptions\ModuleOptionsPluginManagerInterface;
9
use Zend\ServiceManager\AbstractPluginManager;
10
use Zend\ServiceManager\FactoryInterface;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
use Nnx\DoctrineFixtureModule\Options\ModuleOptions;
13
14
/**
15
 * Class ResourceLoaderServiceFactory
16
 *
17
 * @package Nnx\DoctrineFixtureModule\ResourceLoader
18
 */
19
class ResourceLoaderServiceFactory implements FactoryInterface
20
{
21
    /**
22
     * @inheritDoc
23
     *
24
     * @return ResourceLoaderService
25
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
26
     */
27
    public function createService(ServiceLocatorInterface $serviceLocator)
28
    {
29
        $appServiceLocator = $serviceLocator instanceof AbstractPluginManager ? $serviceLocator->getServiceLocator() : $serviceLocator;
30
31
        /** @var ModuleOptionsPluginManagerInterface $moduleOptionsPluginManager */
32
        $moduleOptionsPluginManager = $appServiceLocator->get(ModuleOptionsPluginManagerInterface::class);
33
34
        /** @var ModuleOptions $moduleOptions */
35
        $moduleOptions = $moduleOptionsPluginManager->get(ModuleOptions::class);
36
37
        /** @var ResourceLoaderManagerInterface $resourceLoaderManager */
38
        $resourceLoaderManager = $appServiceLocator->get(ResourceLoaderManagerInterface::class);
39
40
        $resourceLoaderService = new ResourceLoaderService($resourceLoaderManager);
41
42
        $resourceLoaderService->setClassFixtureToResourceLoader($moduleOptions->getResourceLoader());
43
44
        return $resourceLoaderService;
45
    }
46
}
47