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.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 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\Http\Session for configuration information.
 27:  */
 28: class CacheSession implements SessionHandlerInterface
 29: {
 30:     /**
 31:      * Options for this session engine
 32:      *
 33:      * @var array
 34:      */
 35:     protected $_options = [];
 36: 
 37:     /**
 38:      * Constructor.
 39:      *
 40:      * @param array $config The configuration to use for this engine
 41:      * It requires the key 'config' which is the name of the Cache config to use for
 42:      * storing the session
 43:      *
 44:      * @throws \InvalidArgumentException if the 'config' key is not provided
 45:      */
 46:     public function __construct(array $config = [])
 47:     {
 48:         if (empty($config['config'])) {
 49:             throw new InvalidArgumentException('The cache configuration name to use is required');
 50:         }
 51:         $this->_options = $config;
 52:     }
 53: 
 54:     /**
 55:      * Method called on open of a database session.
 56:      *
 57:      * @param string $savePath The path where to store/retrieve the session.
 58:      * @param string $name The session name.
 59:      * @return bool Success
 60:      */
 61:     public function open($savePath, $name)
 62:     {
 63:         return true;
 64:     }
 65: 
 66:     /**
 67:      * Method called on close of a database session.
 68:      *
 69:      * @return bool Success
 70:      */
 71:     public function close()
 72:     {
 73:         return true;
 74:     }
 75: 
 76:     /**
 77:      * Method used to read from a cache session.
 78:      *
 79:      * @param string|int $id ID that uniquely identifies session in cache.
 80:      * @return string Session data or empty string if it does not exist.
 81:      */
 82:     public function read($id)
 83:     {
 84:         $value = Cache::read($id, $this->_options['config']);
 85: 
 86:         if (empty($value)) {
 87:             return '';
 88:         }
 89: 
 90:         return $value;
 91:     }
 92: 
 93:     /**
 94:      * Helper function called on write for cache sessions.
 95:      *
 96:      * @param string|int $id ID that uniquely identifies session in cache.
 97:      * @param mixed $data The data to be saved.
 98:      * @return bool True for successful write, false otherwise.
 99:      */
100:     public function write($id, $data)
101:     {
102:         if (!$id) {
103:             return false;
104:         }
105: 
106:         return (bool)Cache::write($id, $data, $this->_options['config']);
107:     }
108: 
109:     /**
110:      * Method called on the destruction of a cache session.
111:      *
112:      * @param string|int $id ID that uniquely identifies session in cache.
113:      * @return bool Always true.
114:      */
115:     public function destroy($id)
116:     {
117:         Cache::delete($id, $this->_options['config']);
118: 
119:         return true;
120:     }
121: 
122:     /**
123:      * Helper function called on gc for cache sessions.
124:      *
125:      * @param int $maxlifetime Sessions that have not updated for the last maxlifetime seconds will be removed.
126:      * @return bool Always true.
127:      */
128:     public function gc($maxlifetime)
129:     {
130:         Cache::gc($this->_options['config'], time() - $maxlifetime);
131: 
132:         return true;
133:     }
134: }
135: 
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