|
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\AuthFactory as Factory; |
|
26
|
|
|
use Aura\Auth\Adapter\NullAdapter; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Config |
|
30
|
|
|
* |
|
31
|
|
|
* @category Config |
|
32
|
|
|
* @package Fusible\AuthProvider |
|
33
|
|
|
* @author Jake Johns <[email protected]> |
|
34
|
|
|
* @license http://jnj.mit-license.org/2016 MIT License |
|
35
|
|
|
* @link https://github.com/fusible/fusible.auth-provider |
|
36
|
|
|
* |
|
37
|
|
|
* @see ContainerConfig |
|
38
|
|
|
*/ |
|
39
|
|
|
class Config extends ContainerConfig |
|
40
|
|
|
{ |
|
41
|
|
|
const COOKIE = 'cookie'; |
|
42
|
|
|
|
|
43
|
|
|
const FACTORY = 'aura/auth:factory'; |
|
44
|
|
|
const ADAPTER = 'aura/auth:adapter'; |
|
45
|
|
|
|
|
46
|
|
|
const AUTH = 'aura/auth:auth'; |
|
47
|
|
|
|
|
48
|
|
|
const LOGIN = 'aura/auth:login'; |
|
49
|
|
|
const LOGOUT = 'aura/auth:logout'; |
|
50
|
|
|
const RESUME = 'aura/auth:resume'; |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Cookie |
|
55
|
|
|
* |
|
56
|
|
|
* @var array |
|
57
|
|
|
* |
|
58
|
|
|
* @access protected |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $cookie; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* __construct |
|
64
|
|
|
* |
|
65
|
|
|
* @param array $cookie Cookie array |
|
66
|
|
|
* |
|
67
|
|
|
* @access public |
|
68
|
|
|
*/ |
|
69
|
7 |
|
public function __construct(array $cookie = null) |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
7 |
|
$this->cookie = (null === $cookie) ? $_COOKIE : $cookie; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Define Aura\Auth factories and services |
|
76
|
|
|
* |
|
77
|
|
|
* @param Container $di DI Container |
|
78
|
|
|
* |
|
79
|
|
|
* @return void |
|
80
|
|
|
* |
|
81
|
|
|
* @access public |
|
82
|
|
|
* |
|
83
|
|
|
* @SuppressWarnings(PHPMD.ShortVariable) |
|
84
|
|
|
*/ |
|
85
|
7 |
|
public function define(Container $di) |
|
86
|
|
|
{ |
|
87
|
|
|
if (! isset($di->values[static::COOKIE])) { |
|
88
|
|
|
$di->values[static::COOKIE] = $this->cookie; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$di->params[Factory::class]['cookie'] = $di->lazyValue(static::COOKIE); |
|
92
|
|
|
|
|
93
|
|
|
$di->set( |
|
94
|
7 |
|
static::FACTORY, |
|
95
|
7 |
|
$di->lazyNew(Factory::class) |
|
96
|
|
|
); |
|
97
|
|
|
|
|
98
|
|
|
if (! $di->has(static::ADAPTER)) { |
|
99
|
|
|
$di->set( |
|
100
|
7 |
|
static::ADAPTER, |
|
101
|
7 |
|
$di->lazyNew(NullAdapter::class) |
|
102
|
|
|
); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
$di->set( |
|
106
|
7 |
|
static::AUTH, |
|
107
|
7 |
|
$di->lazyGetCall(static::FACTORY, 'newInstance') |
|
108
|
|
|
); |
|
109
|
|
|
|
|
110
|
|
|
$di->set( |
|
111
|
7 |
|
static::LOGIN, |
|
112
|
|
|
$di->lazyGetCall( |
|
113
|
7 |
|
static::FACTORY, |
|
114
|
7 |
|
'newLoginService', |
|
115
|
7 |
|
$di->lazyGet(static::ADAPTER) |
|
116
|
|
|
) |
|
117
|
|
|
); |
|
118
|
|
|
|
|
119
|
|
|
$di->set( |
|
120
|
7 |
|
static::LOGOUT, |
|
121
|
|
|
$di->lazyGetCall( |
|
122
|
7 |
|
static::FACTORY, |
|
123
|
7 |
|
'newLogoutService', |
|
124
|
7 |
|
$di->lazyGet(static::ADAPTER) |
|
125
|
|
|
) |
|
126
|
|
|
); |
|
127
|
|
|
|
|
128
|
|
|
$di->set( |
|
129
|
7 |
|
static::RESUME, |
|
130
|
|
|
$di->lazyGetCall( |
|
131
|
7 |
|
static::FACTORY, |
|
132
|
7 |
|
'newResumeService', |
|
133
|
7 |
|
$di->lazyGet(static::ADAPTER) |
|
134
|
|
|
) |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: