-
Notifications
You must be signed in to change notification settings - Fork 0
/
GuardsProviderFactory.php
40 lines (35 loc) · 1.23 KB
/
GuardsProviderFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
* @see https://github.com/dotkernel/dot-rbac-guard/ for the canonical source repository
* @copyright Copyright (c) 2017 Apidemia (https://www.apidemia.com)
* @license https://github.com/dotkernel/dot-rbac-guard/blob/master/LICENSE.md MIT License
*/
declare(strict_types = 1);
namespace Dot\Rbac\Guard\Factory;
use Dot\Rbac\Guard\Guard\Factory;
use Dot\Rbac\Guard\Guard\GuardPluginManager;
use Dot\Rbac\Guard\Provider\ArrayGuardsProvider;
use Psr\Container\ContainerInterface;
/**
* Class ArrayGuardsProviderFactory
* @package Dot\Rbac\Guard\Factory
*/
class GuardsProviderFactory
{
/**
* @param ContainerInterface $container
* @param $requestedName
* @param array $options
* @return ArrayGuardsProvider
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$options = $options ?? [];
$options['guard_factory'] = isset($options['guard_factory'])
&& is_string($options['guard_factory'])
&& $container->has($options['guard_factory'])
? $container->get($options['guard_factory'])
: new Factory($container, $container->get(GuardPluginManager::class));
return new $requestedName($options);
}
}