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
|
|
|
|
15
|
|
|
use Interop\Container\ContainerInterface; |
16
|
|
|
use Opensoft\Rollout\RolloutUserInterface; |
17
|
|
|
use Zend\ServiceManager\Exception\ServiceNotCreatedException; |
18
|
|
|
use Zend\ServiceManager\FactoryInterface; |
19
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Toni Van de Voorde <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
final class RolloutUserFactory implements FactoryInterface |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* {@inheritdoc} |
29
|
|
|
*/ |
30
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
31
|
|
|
{ |
32
|
|
|
return $this($serviceLocator, null); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
39
|
|
|
{ |
40
|
|
|
/** @var array $config */ |
41
|
|
|
$config = $container->get('zf2_rollout_config'); |
42
|
|
|
|
43
|
|
|
$rolloutUserServiceId = $config['user_service']; |
44
|
|
|
|
45
|
|
|
if (!isset($rolloutUserServiceId)) { |
46
|
|
|
throw new ServiceNotCreatedException(sprintf('You must define a service for rollout user_service.')); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if (!$container->has($rolloutUserServiceId)) { |
50
|
|
|
throw new ServiceNotCreatedException(sprintf('Defined rollout user_service \'%s\' is not configured!', |
51
|
|
|
$rolloutUserServiceId)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** @var RolloutUserInterface $rolloutUser */ |
55
|
|
|
return $container->get($rolloutUserServiceId); |
56
|
|
|
} |
57
|
|
|
} |