|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Aura\Auth Provider for Aura\Di |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* Copyright (C) 2016 Jake Johns |
|
8
|
|
|
* |
|
9
|
|
|
* This software may be modified and distributed under the terms |
|
10
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
11
|
|
|
* |
|
12
|
|
|
* @category Config |
|
13
|
|
|
* @package Fusible\AuthProvider |
|
14
|
|
|
* @author Jake Johns <[email protected]> |
|
15
|
|
|
* @copyright 2016 Jake Johns |
|
16
|
|
|
* @license http://jnj.mit-license.org/2016 MIT License |
|
17
|
|
|
* @link https://github.com/fusible/fusible.auth-provider |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Fusible\AuthProvider; |
|
21
|
|
|
|
|
22
|
|
|
use Aura\Di\Container; |
|
23
|
|
|
use Aura\Di\ContainerConfig; |
|
24
|
|
|
|
|
25
|
|
|
use Aura\Auth; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Config |
|
29
|
|
|
* |
|
30
|
|
|
* @category Config |
|
31
|
|
|
* @package Fusible\AuthProvider |
|
32
|
|
|
* @author Jake Johns <[email protected]> |
|
33
|
|
|
* @license http://jnj.mit-license.org/2016 MIT License |
|
34
|
|
|
* @link https://github.com/fusible/fusible.auth-provider |
|
35
|
|
|
* |
|
36
|
|
|
* @see ContainerConfig |
|
37
|
|
|
*/ |
|
38
|
|
|
class Config extends ContainerConfig |
|
39
|
|
|
{ |
|
40
|
|
|
const AUTH_ADAPTER = self::class . '::AUTH_ADAPTER'; |
|
41
|
|
|
const FACTORY = Auth\AuthFactory::class; |
|
42
|
|
|
const AUTH = Auth\Auth::class; |
|
43
|
|
|
const LOGIN = Auth\Service\LoginService::class; |
|
44
|
|
|
const LOGOUT = Auth\Service\LogoutService::class; |
|
45
|
|
|
const RESUME = Auth\Service\ResumeService::class; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Cookie |
|
49
|
|
|
* |
|
50
|
|
|
* @var array |
|
51
|
|
|
* |
|
52
|
|
|
* @access protected |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $cookie; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* __construct |
|
58
|
|
|
* |
|
59
|
|
|
* @param array $cookie Cookie array |
|
60
|
|
|
* |
|
61
|
|
|
* @access public |
|
62
|
|
|
*/ |
|
63
|
|
|
public function __construct(array $cookie = null) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->cookie = (null === $cookie) ? $_COOKIE : $cookie; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
7 |
|
* Define Aura\Auth factories and services |
|
70
|
|
|
* |
|
71
|
7 |
|
* @param Container $di DI Container |
|
72
|
7 |
|
* |
|
73
|
|
|
* @return void |
|
74
|
|
|
* |
|
75
|
|
|
* @access public |
|
76
|
|
|
* |
|
77
|
|
|
* @SuppressWarnings(PHPMD.ShortVariable) |
|
78
|
|
|
*/ |
|
79
|
|
|
public function define(Container $di) |
|
80
|
|
|
{ |
|
81
|
|
|
if (! isset($di->values['_COOKIE'])) { |
|
82
|
|
|
$di->values['_COOKIE'] = $this->cookie; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
7 |
|
$di->params[Auth\AuthFactory::class]['cookie'] = $di->lazyValue('_COOKIE'); |
|
86
|
|
|
|
|
87
|
7 |
|
$di->set( |
|
88
|
7 |
|
self::FACTORY, |
|
89
|
7 |
|
$di->lazyNew(Auth\AuthFactory::class) |
|
90
|
|
|
); |
|
91
|
7 |
|
|
|
92
|
|
|
if (! $di->has(self::AUTH_ADAPTER)) { |
|
93
|
7 |
|
$di->set( |
|
94
|
7 |
|
self::AUTH_ADAPTER, |
|
95
|
7 |
|
$di->lazyNew(Auth\Adapter\NullAdapter::class) |
|
96
|
7 |
|
); |
|
97
|
|
|
} |
|
98
|
7 |
|
|
|
99
|
7 |
|
$di->set( |
|
100
|
7 |
|
self::AUTH, |
|
101
|
7 |
|
$di->lazyGetCall(Auth\AuthFactory::class, 'newInstance') |
|
102
|
7 |
|
); |
|
103
|
7 |
|
|
|
104
|
|
|
$di->set( |
|
105
|
7 |
|
self::LOGIN, |
|
106
|
7 |
|
$di->lazyGetCall( |
|
107
|
7 |
|
Auth\AuthFactory::class, |
|
108
|
7 |
|
'newLoginService', |
|
109
|
|
|
$di->lazyGet(self::AUTH_ADAPTER) |
|
110
|
7 |
|
) |
|
111
|
7 |
|
); |
|
112
|
7 |
|
|
|
113
|
7 |
|
$di->set( |
|
114
|
7 |
|
self::LOGOUT, |
|
115
|
7 |
|
$di->lazyGetCall( |
|
116
|
7 |
|
Auth\AuthFactory::class, |
|
117
|
7 |
|
'newLogoutService', |
|
118
|
|
|
$di->lazyGet(self::AUTH_ADAPTER) |
|
119
|
7 |
|
) |
|
120
|
7 |
|
); |
|
121
|
7 |
|
|
|
122
|
7 |
|
$di->set( |
|
123
|
7 |
|
self::RESUME, |
|
124
|
7 |
|
$di->lazyGetCall( |
|
125
|
7 |
|
Auth\AuthFactory::class, |
|
126
|
7 |
|
'newResumeService', |
|
127
|
|
|
$di->lazyGet(self::AUTH_ADAPTER) |
|
128
|
7 |
|
) |
|
129
|
7 |
|
); |
|
130
|
7 |
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|