CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • CacheSession
  • DatabaseSession
  1: <?php
  2: /**
  3:  * Cache Session save handler. Allows saving session information into Cache.
  4:  *
  5:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  6:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  7:  *
  8:  * Licensed under The MIT License
  9:  * For full copyright and license information, please see the LICENSE.txt
 10:  * Redistributions of files must retain the above copyright notice.
 11:  *
 12:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 13:  * @link          https://cakephp.org CakePHP(tm) Project
 14:  * @since         2.0.0
 15:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 16:  */
 17: namespace Cake\Http\Session;
 18: 
 19: use Cake\Cache\Cache;
 20: use InvalidArgumentException;
 21: use SessionHandlerInterface;
 22: 
 23: /**
 24:  * CacheSession provides method for saving sessions into a Cache engine. Used with Session
 25:  *
 26:  * @see \Cake\Model\Datasource\Session for configuration information.
 27:  */
 28: class CacheSession implements SessionHandlerInterface
 29: {
 30: 
 31:     /**
 32:      * Options for this session engine
 33:      *
 34:      * @var array
 35:      */
 36:     protected $_options = [];
 37: 
 38:     /**
 39:      * Constructor.
 40:      *
 41:      * @param array $config The configuration to use for this engine
 42:      * It requires the key 'config' which is the name of the Cache config to use for
 43:      * storing the session
 44:      *
 45:      * @throws \InvalidArgumentException if the 'config' key is not provided
 46:      */
 47:     public function __construct(array $config = [])
 48:     {
 49:         if (empty($config['config'])) {
 50:             throw new InvalidArgumentException('The cache configuration name to use is required');
 51:         }
 52:         $this->_options = $config;
 53:     }
 54: 
 55:     /**
 56:      * Method called on open of a database session.
 57:      *
 58:      * @param string $savePath The path where to store/retrieve the session.
 59:      * @param string $name The session name.
 60:      * @return bool Success
 61:      */
 62:     public function open($savePath, $name)
 63:     {
 64:         return true;
 65:     }
 66: 
 67:     /**
 68:      * Method called on close of a database session.
 69:      *
 70:      * @return bool Success
 71:      */
 72:     public function close()
 73:     {
 74:         return true;
 75:     }
 76: 
 77:     /**
 78:      * Method used to read from a cache session.
 79:      *
 80:      * @param string|int $id ID that uniquely identifies session in cache.
 81:      * @return string Session data or empty string if it does not exist.
 82:      */
 83:     public function read($id)
 84:     {
 85:         $value = Cache::read($id, $this->_options['config']);
 86: 
 87:         if (empty($value)) {
 88:             return '';
 89:         }
 90: 
 91:         return $value;
 92:     }
 93: 
 94:     /**
 95:      * Helper function called on write for cache sessions.
 96:      *
 97:      * @param string|int $id ID that uniquely identifies session in cache.
 98:      * @param mixed $data The data to be saved.
 99:      * @return bool True for successful write, false otherwise.
100:      */
101:     public function write($id, $data)
102:     {
103:         if (!$id) {
104:             return false;
105:         }
106: 
107:         return (bool)Cache::write($id, $data, $this->_options['config']);
108:     }
109: 
110:     /**
111:      * Method called on the destruction of a cache session.
112:      *
113:      * @param string|int $id ID that uniquely identifies session in cache.
114:      * @return bool Always true.
115:      */
116:     public function destroy($id)
117:     {
118:         Cache::delete($id, $this->_options['config']);
119: 
120:         return true;
121:     }
122: 
123:     /**
124:      * Helper function called on gc for cache sessions.
125:      *
126:      * @param int $maxlifetime Sessions that have not updated for the last maxlifetime seconds will be removed.
127:      * @return bool Always true.
128:      */
129:     public function gc($maxlifetime)
130:     {
131:         Cache::gc($this->_options['config'], time() - $maxlifetime);
132: 
133:         return true;
134:     }
135: }
136: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs