[ Index ]
 

Code source de CakePHP 1.1.13.4450

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/cake/libs/controller/components/ -> session.php (source)

   1  <?php
   2  /* SVN FILE: $Id: session.php 4409 2007-02-02 13:20:59Z phpnut $ */
   3  /**
   4   * Short description for file.
   5   *
   6   * Long description for file
   7   *
   8   * PHP versions 4 and 5
   9   *
  10   * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
  11   * Copyright 2005-2007, Cake Software Foundation, Inc.
  12   *                                1785 E. Sahara Avenue, Suite 490-204
  13   *                                Las Vegas, Nevada 89104
  14   *
  15   * Licensed under The MIT License
  16   * Redistributions of files must retain the above copyright notice.
  17   *
  18   * @filesource
  19   * @copyright        Copyright 2005-2007, Cake Software Foundation, Inc.
  20   * @link                http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
  21   * @package            cake
  22   * @subpackage        cake.cake.libs.controller.components
  23   * @since            CakePHP(tm) v 0.10.0.1232
  24   * @version            $Revision: 4409 $
  25   * @modifiedby        $LastChangedBy: phpnut $
  26   * @lastmodified    $Date: 2007-02-02 07:20:59 -0600 (Fri, 02 Feb 2007) $
  27   * @license            http://www.opensource.org/licenses/mit-license.php The MIT License
  28   */
  29  /**
  30   * Session Component.
  31   *
  32   * Session handling from the controller.
  33   *
  34   * @package        cake
  35   * @subpackage    cake.cake.libs.controller.components
  36   *
  37   */
  38  class SessionComponent extends CakeSession {
  39  /**
  40   * Used to determine if methods implementation is used, or bypassed
  41   *
  42   * @var boolean
  43   * @access private
  44   */
  45      var $__active = true;
  46  /**
  47   * Class constructor
  48   *
  49   * @param string $base
  50   */
  51  	function __construct($base = null) {
  52          if (!defined('AUTO_SESSION') || AUTO_SESSION === true) {
  53              parent::__construct($base);
  54          } else {
  55              $this->__active = false;
  56          }
  57      }
  58  /**
  59   * Startup method.  Copies controller data locally for rendering flash messages.
  60   *
  61   * @param object $controller
  62   * @access public
  63   */
  64  	function startup(&$controller) {
  65          $this->base = $controller->base;
  66          $this->webroot = $controller->webroot;
  67          $this->here = $controller->here;
  68          $this->params = $controller->params;
  69          $this->action = $controller->action;
  70          $this->data = $controller->data;
  71          $this->plugin = $controller->plugin;
  72      }
  73  /**
  74   * Used to write a value to a session key.
  75   *
  76   * In your controller: $this->Session->write('Controller.sessKey', 'session value');
  77   *
  78   * @param string $name The name of the key your are setting in the session.
  79   *                             This should be in a Controller.key format for better organizing
  80   * @param string $value The value you want to store in a session.
  81   * @access public
  82   */
  83  	function write($name, $value) {
  84          if ($this->__active === true) {
  85              $this->writeSessionVar($name, $value);
  86          }
  87      }
  88  /**
  89   * Used to read a session values for a key or return values for all keys.
  90   *
  91   * In your controller: $this->Session->read('Controller.sessKey');
  92   * Calling the method without a param will return all session vars
  93   *
  94   * @param string $name the name of the session key you want to read
  95   *
  96   * @return values from the session vars
  97   * @access public
  98   */
  99  	function read($name = null) {
 100          if ($this->__active === true) {
 101              return $this->readSessionVar($name);
 102          }
 103          return false;
 104      }
 105  /**
 106   * Used to delete a session variable.
 107   *
 108   * In your controller: $this->Session->del('Controller.sessKey');
 109   *
 110   * @param string $name
 111   * @return boolean, true is session variable is set and can be deleted, false is variable was not set.
 112   * @access public
 113   */
 114  	function del($name) {
 115          if ($this->__active === true) {
 116              return $this->delSessionVar($name);
 117          }
 118          return false;
 119      }
 120  /**
 121   * Wrapper for SessionComponent::del();
 122   *
 123   * In your controller: $this->Session->delete('Controller.sessKey');
 124   *
 125   * @param string $name
 126   * @return boolean, true is session variable is set and can be deleted, false is variable was not set.
 127   * @access public
 128   */
 129  	function delete($name) {
 130          if ($this->__active === true) {
 131              return $this->del($name);
 132          }
 133          return false;
 134      }
 135  /**
 136   * Used to check if a session variable is set
 137   *
 138   * In your controller: $this->Session->check('Controller.sessKey');
 139   *
 140   * @param string $name
 141   * @return boolean true is session variable is set, false if not
 142   * @access public
 143   */
 144  	function check($name) {
 145          if ($this->__active === true) {
 146              return $this->checkSessionVar($name);
 147          }
 148          return false;
 149      }
 150  /**
 151   * Used to determine the last error in a session.
 152   *
 153   * In your controller: $this->Session->error();
 154   *
 155   * @return string Last session error
 156   * @access public
 157   */
 158  	function error() {
 159          if ($this->__active === true) {
 160              return $this->getLastError();
 161          }
 162          return false;
 163      }
 164  /**
 165   * Used to set a session variable that can be used to output messages in the view.
 166   *
 167   * In your controller: $this->Session->setFlash('This has been saved');
 168   *
 169   * Additional params below can be passed to customize the output, or the Message.[key]
 170   *
 171   * @param string $flashMessage Message to be flashed
 172   * @param string $layout Layout to wrap flash message in
 173   * @param array $params Parameters to be sent to layout as view variables
 174   * @param string $key Message key, default is 'flash'
 175   * @access public
 176   */
 177  	function setFlash($flashMessage, $layout = 'default', $params = array(), $key = 'flash') {
 178          if ($this->__active === true) {
 179              if ($layout == 'default') {
 180                  $out = '<div id="' . $key . 'Message" class="message">' . $flashMessage . '</div>';
 181              } elseif ($layout == '' || $layout == null) {
 182                  $out = $flashMessage;
 183              } else {
 184                  $ctrl = null;
 185                  $view = new View($ctrl);
 186                  $view->base            = $this->base;
 187                  $view->webroot        = $this->webroot;
 188                  $view->here            = $this->here;
 189                  $view->params        = $this->params;
 190                  $view->action        = $this->action;
 191                  $view->data            = $this->data;
 192                  $view->plugin        = $this->plugin;
 193                  $view->helpers        = array('Html');
 194                  $view->layout        = $layout;
 195                  $view->pageTitle    = '';
 196                  $view->viewVars    = $params;
 197                  $out = $view->renderLayout($flashMessage);
 198              }
 199              $this->write('Message.' . $key, $out);
 200          }
 201      }
 202  /**
 203   * This method is deprecated.
 204   * You should use $session->flash('key'); in your views
 205   *
 206   * @deprecated will not be avialable after 1.1.x.x
 207   */
 208  	function flash($key = 'flash') {
 209          trigger_error('(SessionComponent::flash()) Deprecated: Use $session->flash() in your views instead', E_USER_WARNING);
 210          if ($this->__active === true) {
 211              if ($this->check('Message.' . $key)) {
 212                  e($this->read('Message.' . $key));
 213                  $this->del('Message.' . $key);
 214                  return;
 215              }
 216          }
 217          return false;
 218      }
 219  /**
 220   * Used to renew a session id
 221   *
 222   * In your controller: $this->Session->renew();
 223   * @access public
 224   */
 225  	function renew() {
 226          if ($this->__active === true) {
 227              parent::renew();
 228          }
 229      }
 230  /**
 231   * Used to check for a valid session.
 232   *
 233   * In your controller: $this->Session->valid();
 234   *
 235   * @return boolean true is session is valid, false is session is invalid
 236   * @access public
 237   */
 238  	function valid() {
 239          if ($this->__active === true) {
 240              return $this->isValid();
 241          }
 242          return false;
 243      }
 244  /**
 245   * Used to destroy sessions
 246   *
 247   * In your controller: $this->Session->destroy();
 248   * @access public
 249   */
 250  	function destroy() {
 251          if ($this->__active === true) {
 252              $this->destroyInvalid();
 253          }
 254      }
 255  }
 256  
 257  ?>


Généré le : Sun Feb 25 19:27:47 2007 par Balluche grâce à PHPXref 0.7