Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#3689 branch 'hotfix/3684'
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 87 deletions.
5 changes: 4 additions & 1 deletion composer.json
Expand Up @@ -10,7 +10,10 @@
"autoload": {
"psr-4": {
"Zend\\Session\\": "src/"
}
},
"files": [
"compatibility/autoload.php"
]
},
"require": {
"php": ">=5.3.3",
Expand Down
80 changes: 30 additions & 50 deletions src/Container.php
Expand Up @@ -9,64 +9,44 @@

namespace Zend\Session;

if (version_compare(PHP_VERSION, '5.3.3') > 0) {
/**
* Session storage container
*
* Allows for interacting with session storage in isolated containers, which
* may have their own expiries, or even expiries per key in the container.
* Additionally, expiries may be absolute TTLs or measured in "hops", which
* are based on how many times the key or container were accessed.
*/
class Container extends AbstractContainer
{
/**
* Session storage container
* Exchange the current array with another array or object.
*
* Allows for interacting with session storage in isolated containers, which
* may have their own expiries, or even expiries per key in the container.
* Additionally, expiries may be absolute TTLs or measured in "hops", which
* are based on how many times the key or container were accessed.
* @param array|object $input
* @return array Returns the old array
* @see ArrayObject::exchangeArray()
*/
class Container extends AbstractContainer
public function exchangeArray(array $input)
{
/**
* Exchange the current array with another array or object.
*
* @param array|object $input
* @return array Returns the old array
* @see ArrayObject::exchangeArray()
*/
public function exchangeArray(array $input)
{
return parent::exchangeArrayCompat($input);
}

/**
* Retrieve a specific key in the container
*
* @param string $key
* @return mixed
*/
public function &offsetGet($key)
{
$ret = null;
if (!$this->offsetExists($key)) {
return $ret;
}
$storage = $this->getStorage();
$name = $this->getName();
$ret =& $storage[$name][$key];

return $ret;
}
return parent::exchangeArrayCompat($input);
}
} else {

/**
* Session storage container for PHP 5.3.3 and less
* Retrieve a specific key in the container
*
* @param string $key
* @return mixed
*/
class Container extends AbstractContainer
public function &offsetGet($key)
{
/**
* Exchange the current array with another array or object.
*
* @param array|object $input
* @return array Returns the old array
* @see ArrayObject::exchangeArray()
*/
public function exchangeArray($input)
{
return parent::exchangeArrayCompat($input);
$ret = null;
if (!$this->offsetExists($key)) {
return $ret;
}
$storage = $this->getStorage();
$name = $this->getName();
$ret =& $storage[$name][$key];

return $ret;
}
}
62 changes: 26 additions & 36 deletions src/Storage/SessionArrayStorage.php
Expand Up @@ -9,48 +9,38 @@

namespace Zend\Session\Storage;

use ArrayIterator;
use IteratorAggregate;
use Zend\Session\Exception;

if (version_compare(PHP_VERSION, '5.3.3') > 0) {
/**
* Session storage in $_SESSION
*/
class SessionArrayStorage extends AbstractSessionArrayStorage
{
/**
* Session storage in $_SESSION
* Get Offset
*
* @param mixed $key
* @return mixed
*/
class SessionArrayStorage extends AbstractSessionArrayStorage
public function &__get($key)
{
/**
* Get Offset
*
* @param mixed $key
* @return mixed
*/
public function &__get($key)
{
if (isset($_SESSION[$key])) {
return $_SESSION[$key];
}

return null;
if (isset($_SESSION[$key])) {
return $_SESSION[$key];
}

/**
* Offset Get
*
* @param mixed $key
* @return mixed
*/
public function &offsetGet($key)
{
if (isset($_SESSION[$key])) {
return $_SESSION[$key];
}

return null;
}
return null;
}
} else {
class SessionArrayStorage extends AbstractSessionArrayStorage

/**
* Offset Get
*
* @param mixed $key
* @return mixed
*/
public function &offsetGet($key)
{
if (isset($_SESSION[$key])) {
return $_SESSION[$key];
}

return null;
}
}
28 changes: 28 additions & 0 deletions src/compatibility/Container.php
@@ -0,0 +1,28 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Session;

/**
* Session storage container for PHP 5.3.3 and less
*/
class Container extends AbstractContainer
{
/**
* Exchange the current array with another array or object.
*
* @param array|object $input
* @return array Returns the old array
* @see ArrayObject::exchangeArray()
*/
public function exchangeArray($input)
{
return parent::exchangeArrayCompat($input);
}
}
17 changes: 17 additions & 0 deletions src/compatibility/Storage/SessionArrayStorage.php
@@ -0,0 +1,17 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Session\Storage;

/**
* PHP 5.3.3 variant of SessionArrayStorage
*/
class SessionArrayStorage extends AbstractSessionArrayStorage
{
}
5 changes: 5 additions & 0 deletions src/compatibility/autoload.php
@@ -0,0 +1,5 @@
<?php
if (version_compare(PHP_VERSION, '5.3.3', 'le')) {
require_once __DIR__ . '/Container.php';
require_once __DIR__ . '/Storage/SessionArrayStorage.php';
}

0 comments on commit 9533639

Please sign in to comment.