Completed
Push — master ( 99f799...7b8dce )
by Andrey
04:09
created

ContextBuilderFactory::createService()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/form-comparator
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\FormComparator\Context;
7
8
use Webmozart\Assert\Assert;
9
use Zend\ServiceManager\AbstractPluginManager;
10
use Zend\ServiceManager\FactoryInterface;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
use Zend\Form\FormElementManager;
13
14
/**
15
 * Class ContextBuilderFactory
16
 *
17
 * @package Nnx\FormComparator\Context
18
 */
19
class ContextBuilderFactory implements FactoryInterface
20
{
21
    /**
22
     * @inheritdoc
23
     *
24
     * @param ServiceLocatorInterface $serviceLocator
25
     *
26
     * @return ContextBuilder
27
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
28
     */
29
    public function createService(ServiceLocatorInterface $serviceLocator)
30
    {
31
        $appServiceLocator = $serviceLocator instanceof AbstractPluginManager ? $serviceLocator->getServiceLocator() : $serviceLocator;
32
33
        /** @var FormElementManager $formElementManager */
34
        $formElementManager = $appServiceLocator->get('FormElementManager');
35
        Assert::isInstanceOf($formElementManager, FormElementManager::class);
36
37
        return new ContextBuilder($formElementManager);
38
    }
39
40
}
41