Completed
Push — develop ( 49270f...975a05 )
by
unknown
06:55
created

ExternalApplicationAdapterFactory::__invoke()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 2
nop 3
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
namespace Auth\Factory\Adapter;
11
12
use Zend\ServiceManager\FactoryInterface;
13
use Zend\ServiceManager\ServiceLocatorInterface;
14
use Auth\Adapter\ExternalApplication;
15
16
/**
17
 * authentication adapter factory
18
 */
19
class ExternalApplicationAdapterFactory implements FactoryInterface
20
{
21
    /**
22
     * Create an ExternalApplication adapter
23
     *
24
     * authentication for external applications
25
     *
26
     * @param  ContainerInterface $container
27
     * @param  string             $requestedName
28
     * @param  null|array         $options
29
     *
30
     * @return ExternalApplication
31
     * @throws ServiceNotFoundException if unable to resolve the service.
32
     * @throws ServiceNotCreatedException if an exception is raised when
33
     *     creating a service.
34
     * @throws ContainerException if any other error occurs
35
     */
36
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
37
    {
38
        $repository = $container->get('repositories')->get('Auth/User');
39
        $adapter = new ExternalApplication($repository);
40
        $adapter->setServiceLocator($container);
41
        $config  = $container->get('Config');
42
        if (isset($config['Auth']['external_applications']) && is_array($config['Auth']['external_applications'])) {
43
            $adapter->setApplicationKeys($config['Auth']['external_applications']);
44
        }
45
46
        return $adapter;
47
    }
48
49
    /**
50
     * Creates an instance of \Auth\Adapter\ExternalApplication
51
     *
52
     * - injects the UserRepository fetched from the service manager.
53
     *
54
     * @param ServiceLocatorInterface $serviceLocator
55
     * @return \Auth\Adapter\ExternalApplication
56
     * @see \Zend\ServiceManager\FactoryInterface::createService()
57
     */
58
    public function createService(ServiceLocatorInterface $serviceLocator)
59
    {
60
        return $this($serviceLocator, ExternalApplication::class);
61
    }
62
}
63