Skip to content

Commit f525de6

Browse files
committed
Add Auth StorageInterface and classes
1 parent a4f5190 commit f525de6

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

src/Auth/Storage/NullStorage.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5+
*
6+
* Licensed under The MIT License
7+
* For full copyright and license information, please see the LICENSE.txt
8+
* Redistributions of files must retain the above copyright notice.
9+
*
10+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11+
* @link http://cakephp.org CakePHP(tm) Project
12+
* @since 3.1.0
13+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
14+
*/
15+
namespace Cake\Auth\Storage;
16+
17+
use Cake\Core\InstanceConfigTrait;
18+
use Cake\Network\Request;
19+
20+
class NullStorage implements StorageInterface
21+
{
22+
public function get()
23+
{
24+
}
25+
26+
public function set(array $user)
27+
{
28+
}
29+
30+
public function remove()
31+
{
32+
}
33+
}

src/Auth/Storage/SessionStorage.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5+
*
6+
* Licensed under The MIT License
7+
* For full copyright and license information, please see the LICENSE.txt
8+
* Redistributions of files must retain the above copyright notice.
9+
*
10+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11+
* @link http://cakephp.org CakePHP(tm) Project
12+
* @since 3.1.0
13+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
14+
*/
15+
namespace Cake\Auth\Storage;
16+
17+
use Cake\Core\InstanceConfigTrait;
18+
use Cake\Network\Request;
19+
20+
class SessionStorage implements StorageInterface
21+
{
22+
23+
use InstanceConfigTrait;
24+
25+
protected $_session;
26+
27+
protected $_defaultConfig = [
28+
'key' => 'Auth.User'
29+
];
30+
31+
public function __construct(Request $request, array $config = [])
32+
{
33+
$this->_session = $request->session();
34+
$this->config($config);
35+
}
36+
37+
public function get()
38+
{
39+
if (!$this->_session->check($this->_config['key'])) {
40+
return;
41+
}
42+
43+
return $this->_session->read($this->_config['key']);
44+
}
45+
46+
public function set(array $user)
47+
{
48+
$this->_session->renew();
49+
$this->_session->write($this->_config['key'], $user);
50+
}
51+
52+
public function remove()
53+
{
54+
$this->_session->delete($this->_config['key']);
55+
$this->_session->renew();
56+
}
57+
}

src/Auth/Storage/StorageInterface.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5+
*
6+
* Licensed under The MIT License
7+
* For full copyright and license information, please see the LICENSE.txt
8+
* Redistributions of files must retain the above copyright notice.
9+
*
10+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11+
* @link http://cakephp.org CakePHP(tm) Project
12+
* @since 3.1.0
13+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
14+
*/
15+
namespace Cake\Auth\Storage;
16+
17+
interface StorageInterface
18+
{
19+
public function get();
20+
21+
public function set(array $user);
22+
23+
public function remove();
24+
}

0 commit comments

Comments
 (0)