|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com) |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under The MIT License |
|
6
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copyright 2016 - 2018, Cake Development Corporation (http://cakedc.com) |
|
9
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) |
|
14
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
|
15
|
|
|
* |
|
16
|
|
|
* Licensed under The MIT License |
|
17
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
18
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
19
|
|
|
* |
|
20
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
|
21
|
|
|
* @link http://cakephp.org CakePHP(tm) Project |
|
22
|
|
|
* @since 0.10.0 |
|
23
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace CakeDC\Api\Service\Auth; |
|
27
|
|
|
|
|
28
|
|
|
use Cake\Auth\Storage\StorageInterface; |
|
29
|
|
|
use Cake\Core\App; |
|
30
|
|
|
use Cake\Core\Exception\Exception; |
|
31
|
|
|
|
|
32
|
|
|
trait StorageTrait |
|
33
|
|
|
{ |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Storage object. |
|
37
|
|
|
* |
|
38
|
|
|
* @var \Cake\Auth\Storage\StorageInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $_storage; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get/set user record storage object. |
|
44
|
|
|
* |
|
45
|
|
|
* @param \Cake\Auth\Storage\StorageInterface|null $storage Sets provided |
|
46
|
|
|
* object as storage or if null returns configured storage object. |
|
47
|
|
|
* @return \Cake\Auth\Storage\StorageInterface|null |
|
48
|
|
|
*/ |
|
49
|
51 |
|
public function storage(StorageInterface $storage = null) |
|
50
|
|
|
{ |
|
51
|
51 |
|
if ($storage !== null) { |
|
52
|
|
|
$this->_storage = $storage; |
|
53
|
|
|
|
|
54
|
|
|
return null; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
51 |
|
if ($this->_storage) { |
|
58
|
47 |
|
return $this->_storage; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
51 |
|
$config = $this->_config['storage']; |
|
|
|
|
|
|
62
|
51 |
|
if (is_string($config)) { |
|
63
|
51 |
|
$class = $config; |
|
64
|
51 |
|
$config = []; |
|
65
|
51 |
|
} else { |
|
66
|
|
|
$class = $config['className']; |
|
67
|
|
|
unset($config['className']); |
|
68
|
|
|
} |
|
69
|
51 |
|
$className = App::className($class, 'Auth/Storage', 'Storage'); |
|
70
|
51 |
|
if (!class_exists($className)) { |
|
71
|
|
|
throw new Exception(sprintf('Auth storage adapter "%s" was not found.', $class)); |
|
72
|
|
|
} |
|
73
|
51 |
|
$this->_storage = new $className($this->request, $this->response, $config); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
51 |
|
return $this->_storage; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: