Browse Source

Add Auth StorageInterface and classes

ADmad 11 years ago
parent
commit
f525de6c7a

+ 33 - 0
src/Auth/Storage/NullStorage.php

@@ -0,0 +1,33 @@
+<?php
+/**
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link          http://cakephp.org CakePHP(tm) Project
+ * @since         3.1.0
+ * @license       http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+namespace Cake\Auth\Storage;
+
+use Cake\Core\InstanceConfigTrait;
+use Cake\Network\Request;
+
+class NullStorage implements StorageInterface
+{
+    public function get()
+    {
+    }
+
+    public function set(array $user)
+    {
+    }
+
+    public function remove()
+    {
+    }
+}

+ 57 - 0
src/Auth/Storage/SessionStorage.php

@@ -0,0 +1,57 @@
+<?php
+/**
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link          http://cakephp.org CakePHP(tm) Project
+ * @since         3.1.0
+ * @license       http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+namespace Cake\Auth\Storage;
+
+use Cake\Core\InstanceConfigTrait;
+use Cake\Network\Request;
+
+class SessionStorage implements StorageInterface
+{
+
+    use InstanceConfigTrait;
+
+    protected $_session;
+
+    protected $_defaultConfig = [
+        'key' => 'Auth.User'
+    ];
+
+    public function __construct(Request $request, array $config = [])
+    {
+        $this->_session = $request->session();
+        $this->config($config);
+    }
+
+    public function get()
+    {
+        if (!$this->_session->check($this->_config['key'])) {
+            return;
+        }
+
+        return $this->_session->read($this->_config['key']);
+    }
+
+    public function set(array $user)
+    {
+        $this->_session->renew();
+        $this->_session->write($this->_config['key'], $user);
+    }
+
+    public function remove()
+    {
+        $this->_session->delete($this->_config['key']);
+        $this->_session->renew();
+    }
+}

+ 24 - 0
src/Auth/Storage/StorageInterface.php

@@ -0,0 +1,24 @@
+<?php
+/**
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * For full copyright and license information, please see the LICENSE.txt
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link          http://cakephp.org CakePHP(tm) Project
+ * @since         3.1.0
+ * @license       http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+namespace Cake\Auth\Storage;
+
+interface StorageInterface
+{
+    public function get();
+
+    public function set(array $user);
+
+    public function remove();
+}