Completed
Push — master ( 415cd3...c4b326 )
by Toni
02:10
created

RolloutCollectorFactory::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
cc 3
nc 3
nop 3
1
<?php
2
/*
3
 * This file is part of the Adlogix package.
4
 *
5
 * (c) Allan Segebarth <[email protected]>
6
 * (c) Jean-Jacques Courtens <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Adlogix\Zf2Rollout\Service\Factory;
13
14
use Collector\RolloutCollector;
15
use Interop\Container\ContainerInterface;
16
use Opensoft\Rollout\Rollout;
17
use Opensoft\Rollout\RolloutUserInterface;
18
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
19
use Zend\ServiceManager\FactoryInterface;
20
use Zend\ServiceManager\ServiceLocatorInterface;
21
22
/**
23
 * @author Toni Van de Voorde <[email protected]>
24
 */
25
final class RolloutCollectorFactory implements FactoryInterface
26
{
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function createService(ServiceLocatorInterface $serviceLocator)
32
    {
33
        return $this($serviceLocator, null);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
40
    {
41
        /** @var array $config */
42
        $config = $container->get('zf2_rollout_config');
43
44
45
        /** @var Rollout $rollout */
46
        $rollout = $container->get('zf2_rollout');
47
48
        $rolloutUserServiceId = $config['user_service'];
49
50
        if (!isset($rolloutUserServiceId)) {
51
            throw new ServiceNotCreatedException(sprintf('You must define a service for rollout user_service.'));
52
        }
53
54
        if (!$container->has($rolloutUserServiceId)) {
55
            throw new ServiceNotCreatedException(sprintf('Defined rollout user_service \'%s\' is not configured!',
56
                $rolloutUserServiceId));
57
        }
58
59
        /** @var RolloutUserInterface $rolloutUser */
60
        $rolloutUser = $container->get($rolloutUserServiceId);
61
62
        return new RolloutCollector($rollout, $rolloutUser);
63
    }
64
}
65