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

UserAdapterFactory   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 2
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 17 8
A createService() 0 4 1
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 Interop\Container\ContainerInterface;
13
use Zend\ServiceManager\FactoryInterface;
14
use Zend\ServiceManager\ServiceLocatorInterface;
15
use Auth\Adapter\User;
16
17
/**
18
 * authentication adapter factory
19
 */
20
class UserAdapterFactory implements FactoryInterface
21
{
22
    /**
23
     * Create an User adapter
24
     *
25
     * authentication with username and password
26
     *
27
     * @param  ContainerInterface $container
28
     * @param  string             $requestedName
29
     * @param  null|array         $options
30
     *
31
     * @return User
32
     * @throws ServiceNotFoundException if unable to resolve the service.
33
     * @throws ServiceNotCreatedException if an exception is raised when
34
     *     creating a service.
35
     * @throws ContainerException if any other error occurs
36
     */
37
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
38
    {
39
        $config     = $container->get('Config');
40
        $config     = isset($config['Auth']['default_user']) ? $config['Auth']['default_user'] : array();
41
        $repository = $container->get('repositories')->get('Auth/User');
42
43
        $adapter = new User($repository);
44
45
        if (isset($config['login']) && !empty($config['login'])
46
            && isset($config['password']) && !empty($config['password'])
47
            && isset($config['role']) && !empty($config['role'])
48
        ) {
49
            $adapter->setDefaultUser($config['login'], $config['password'], $config['role']);
50
        }
51
52
        return $adapter;
53
    }
54
55
    /**
56
     * Creates an instance of \Auth\Adapter\UserAdapter
57
     *
58
     * - injects the UserRepository fetched from the service manager.
59
     *
60
     * @param ServiceLocatorInterface $serviceLocator
61
     * @return \Auth\Adapter\User
62
     * @see \Zend\ServiceManager\FactoryInterface::createService()
63
     */
64
    public function createService(ServiceLocatorInterface $serviceLocator)
65
    {
66
        return $this($serviceLocator, User::class);
67
    }
68
}
69