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

HybridAuthFactory::createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 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\Service;
11
12
use Hybrid_Auth;
13
use Interop\Container\ContainerInterface;
14
use Zend\ServiceManager\FactoryInterface;
15
use Zend\ServiceManager\ServiceLocatorInterface;
16
17
/**
18
 * Factory for creating the Hybrid_Auth instance.
19
 */
20
class HybridAuthFactory implements FactoryInterface
21
{
22
    /**
23
     * Creates an instance of \Hybrid_Auth
24
     *
25
     * - reads config from the application configuration array
26
     *   under the key 'hybridauth' and passes it as the key
27
     *   'providers' to the \Hybrid_Auth instance.
28
     *
29
     * - assembles the route "auth/hauth" and pass it as
30
     *   'base_url' to the \Hybrid_Auth instance.
31
     *
32
     * @param  ContainerInterface $container
33
     * @param  string             $requestedName
34
     * @param  null|array         $options
35
     *
36
     * @return Hybrid_Auth
37
     * @throws ServiceNotFoundException if unable to resolve the service.
38
     * @throws ServiceNotCreatedException if an exception is raised when
39
     *     creating a service.
40
     * @throws ContainerException if any other error occurs
41
     */
42
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
43
    {
44
        // Making sure the SessionManager is initialized
45
        // before creating HybridAuth components
46
        $container->get('SessionManager')->start();
47
48
        $options = $container->get('Config');
49
50
        $hauthOptions = $options['hybridauth'];
51
52
        $router = $container->get('Router');
53
54
        $baseUrl = $router->assemble(
55
            array(),
56
            array(
57
                'name' => 'auth-hauth',
58
                'force_canonical' => true,
59
            )
60
        );
61
62
        $hybridAuth = new Hybrid_Auth(
63
            array(
64
                'base_url' => $baseUrl,
65
                'providers' => $hauthOptions
66
67
            )
68
        );
69
70
        return $hybridAuth;
71
    }
72
73
    /**
74
     * @param ServiceLocatorInterface $services
75
     *
76
     * @return mixed
77
     */
78
    public function createService(ServiceLocatorInterface $services)
79
    {
80
        return $this($services, Hybrid_Auth::class);
81
    }
82
}
83