123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- /**
- * @package Grav.Common
- *
- * @copyright Copyright (C) 2015 - 2018 Trilby Media, LLC. All rights reserved.
- * @license MIT License; see LICENSE file for details.
- */
- namespace Grav\Common;
- class Session extends \Grav\Framework\Session\Session
- {
- /** @var bool */
- protected $autoStart = false;
- /**
- * @return \Grav\Framework\Session\Session
- * @deprecated 1.5 Use getInstance() method instead
- */
- public static function instance()
- {
- user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getInstance() method instead', E_USER_DEPRECATED);
- return static::getInstance();
- }
- /**
- * Initialize session.
- *
- * Code in this function has been moved into SessionServiceProvider class.
- */
- public function init()
- {
- if ($this->autoStart) {
- $this->start();
- $this->autoStart = false;
- }
- }
- /**
- * @param bool $auto
- * @return $this
- */
- public function setAutoStart($auto)
- {
- $this->autoStart = (bool)$auto;
- return $this;
- }
- /**
- * Returns attributes.
- *
- * @return array Attributes
- * @deprecated 1.5 Use getAll() method instead
- */
- public function all()
- {
- user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use getAll() method instead', E_USER_DEPRECATED);
- return $this->getAll();
- }
- /**
- * Checks if the session was started.
- *
- * @return Boolean
- * @deprecated 1.5 Use isStarted() method instead
- */
- public function started()
- {
- user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use isStarted() method instead', E_USER_DEPRECATED);
- return $this->isStarted();
- }
- /**
- * Store something in session temporarily.
- *
- * @param string $name
- * @param mixed $object
- * @return $this
- */
- public function setFlashObject($name, $object)
- {
- $this->{$name} = serialize($object);
- return $this;
- }
- /**
- * Return object and remove it from session.
- *
- * @param string $name
- * @return mixed
- */
- public function getFlashObject($name)
- {
- $object = unserialize($this->{$name});
- $this->{$name} = null;
- return $object;
- }
- /**
- * Store something in cookie temporarily.
- *
- * @param string $name
- * @param mixed $object
- * @param int $time
- * @return $this
- */
- public function setFlashCookieObject($name, $object, $time = 60)
- {
- setcookie($name, json_encode($object), time() + $time, '/');
- return $this;
- }
- /**
- * Return object and remove it from the cookie.
- *
- * @param string $name
- * @return mixed|null
- */
- public function getFlashCookieObject($name)
- {
- if (isset($_COOKIE[$name])) {
- $object = json_decode($_COOKIE[$name]);
- setcookie($name, '', time() - 3600, '/');
- return $object;
- }
- return null;
- }
- }
|