PageRenderTime 56ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/libs/controller/components/session.php

https://github.com/v2ninad/nm_cake
PHP | 189 lines | 45 code | 16 blank | 128 comment | 1 complexity | ac1bed26d8944822e93798f1479c42ee MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * SessionComponent. Provides access to Sessions from the Controller layer
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package cake.libs.controller.components
  16. * @since CakePHP(tm) v 0.10.0.1232
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. if (!class_exists('cakesession')) {
  20. require LIBS . 'cake_session.php';
  21. }
  22. /**
  23. * Session Component.
  24. *
  25. * Session handling from the controller.
  26. *
  27. * @package cake.libs.controller.components
  28. * @link http://book.cakephp.org/view/1310/Sessions
  29. *
  30. */
  31. class SessionComponent extends Component {
  32. /**
  33. * Get / Set the userAgent
  34. *
  35. * @param string $userAgent Set the userAgent
  36. * @return void
  37. */
  38. public function userAgent($userAgent = null) {
  39. return CakeSession::userAgent($userAgent);
  40. }
  41. /**
  42. * Used to write a value to a session key.
  43. *
  44. * In your controller: $this->Session->write('Controller.sessKey', 'session value');
  45. *
  46. * @param string $name The name of the key your are setting in the session.
  47. * This should be in a Controller.key format for better organizing
  48. * @param string $value The value you want to store in a session.
  49. * @return boolean Success
  50. * @link http://book.cakephp.org/view/1312/write
  51. */
  52. public function write($name, $value = null) {
  53. return CakeSession::write($name, $value);
  54. }
  55. /**
  56. * Used to read a session values for a key or return values for all keys.
  57. *
  58. * In your controller: $this->Session->read('Controller.sessKey');
  59. * Calling the method without a param will return all session vars
  60. *
  61. * @param string $name the name of the session key you want to read
  62. * @return mixed value from the session vars
  63. * @link http://book.cakephp.org/view/1314/read
  64. */
  65. public function read($name = null) {
  66. return CakeSession::read($name);
  67. }
  68. /**
  69. * Wrapper for SessionComponent::del();
  70. *
  71. * In your controller: $this->Session->delete('Controller.sessKey');
  72. *
  73. * @param string $name the name of the session key you want to delete
  74. * @return boolean true is session variable is set and can be deleted, false is variable was not set.
  75. * @link http://book.cakephp.org/view/1316/delete
  76. */
  77. public function delete($name) {
  78. return CakeSession::delete($name);
  79. }
  80. /**
  81. * Used to check if a session variable is set
  82. *
  83. * In your controller: $this->Session->check('Controller.sessKey');
  84. *
  85. * @param string $name the name of the session key you want to check
  86. * @return boolean true is session variable is set, false if not
  87. * @link http://book.cakephp.org/view/1315/check
  88. */
  89. public function check($name) {
  90. return CakeSession::check($name);
  91. }
  92. /**
  93. * Used to determine the last error in a session.
  94. *
  95. * In your controller: $this->Session->error();
  96. *
  97. * @return string Last session error
  98. * @link http://book.cakephp.org/view/1318/error
  99. */
  100. public function error() {
  101. return CakeSession::error();
  102. }
  103. /**
  104. * Used to set a session variable that can be used to output messages in the view.
  105. *
  106. * In your controller: $this->Session->setFlash('This has been saved');
  107. *
  108. * Additional params below can be passed to customize the output, or the Message.[key]
  109. *
  110. * @param string $message Message to be flashed
  111. * @param string $element Element to wrap flash message in.
  112. * @param array $params Parameters to be sent to layout as view variables
  113. * @param string $key Message key, default is 'flash'
  114. * @link http://book.cakephp.org/view/1313/setFlash
  115. */
  116. public function setFlash($message, $element = 'default', $params = array(), $key = 'flash') {
  117. CakeSession::write('Message.' . $key, compact('message', 'element', 'params'));
  118. }
  119. /**
  120. * Used to renew a session id
  121. *
  122. * In your controller: $this->Session->renew();
  123. *
  124. * @return void
  125. */
  126. public function renew() {
  127. return CakeSession::renew();
  128. }
  129. /**
  130. * Used to check for a valid session.
  131. *
  132. * In your controller: $this->Session->valid();
  133. *
  134. * @return boolean true is session is valid, false is session is invalid
  135. */
  136. public function valid() {
  137. return CakeSession::valid();
  138. }
  139. /**
  140. * Used to destroy sessions
  141. *
  142. * In your controller: $this->Session->destroy();
  143. *
  144. * @return void
  145. * @link http://book.cakephp.org/view/1317/destroy
  146. */
  147. public function destroy() {
  148. return CakeSession::destroy();
  149. }
  150. /**
  151. * Returns Session id
  152. *
  153. * If $id is passed in a beforeFilter, the Session will be started
  154. * with the specified id
  155. *
  156. * @param $id string
  157. * @return string
  158. */
  159. public function id($id = null) {
  160. return CakeSession::id($id);
  161. }
  162. /**
  163. * Returns a bool, whether or not the session has been started.
  164. *
  165. * @return boolean
  166. */
  167. public function started() {
  168. return CakeSession::started();
  169. }
  170. public function start() {
  171. return CakeSession::start();
  172. }
  173. }