This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/lib/Rails/ActionDispatch/Http/Session.php

64 lines
1.5 KiB
PHP
Raw Normal View History

2013-10-02 18:14:53 +02:00
<?php
namespace Rails\ActionDispatch\Http;
use Rails\ArrayHelper\GlobalVar;
class Session implements \IteratorAggregate
{
public function getIterator()
{
return new \ArrayIterator($_SESSION);
}
public function __set($prop, $value)
{
$this->set($prop, $value);
}
public function __get($prop)
{
return $this->get($prop);
}
public function set($prop, $value)
{
if (is_object($value)) {
$this->$prop = $value;
$_SESSION[$prop] = $value;
} elseif (is_array($value)) {
$arr = new GlobalVar($value, '_SESSION', $prop);
$this->$prop = $arr;
} else {
$_SESSION[$prop] = $value;
}
return $this;
}
public function get($prop)
{
if (isset($_SESSION[$prop])) {
if (is_array($_SESSION[$prop])) {
$this->$prop = new GlobalVar($_SESSION[$prop], '_SESSION', $prop);
return $this->$prop;
} elseif (is_object($_SESSION[$prop])) {
$this->$prop = $_SESSION[$prop];
return $this->$prop;
} else {
return $_SESSION[$prop];
}
}
return null;
}
public function delete($prop)
{
unset($this->$prop, $_SESSION[$prop]);
}
public function merge()
{
$params = func_get_args();
array_unshift($params, $_SESSION);
return call_user_func_array('array_merge', $params);
}
}