Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
[zendframework#3684] Do polyfill for Session component as well
Browse files Browse the repository at this point in the history
- SessionArrayStorage and Container were both doing version-specific conditional
  declarations; moved these into a compat layer as was done in Stdlib, and
  updated the composer.json for each of the component and framework.
- Currently, the SessionConfigTest suite is not running for me, but appears to
  be a random autoloading error from running in isolated processes; will see how
  the Travis-CI run looks.
  • Loading branch information
weierophinney committed Feb 6, 2013
1 parent 834d631 commit 352a040
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 89 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"ZendTest\\": "tests/"
},
"files": [
"library/Zend/Stdlib/compatibility/autoload.php"
"library/Zend/Stdlib/compatibility/autoload.php",
"library/Zend/Session/compatibility/autoload.php"
]
},
"bin": [
Expand Down
80 changes: 30 additions & 50 deletions library/Zend/Session/Container.php
Original file line number Diff line number Diff line change
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 library/Zend/Session/Storage/SessionArrayStorage.php
Original file line number Diff line number Diff line change
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 library/Zend/Session/compatibility/Container.php
Original file line number Diff line number Diff line change
@@ -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 library/Zend/Session/compatibility/Storage/SessionArrayStorage.php
Original file line number Diff line number Diff line change
@@ -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 library/Zend/Session/compatibility/autoload.php
Original file line number Diff line number Diff line change
@@ -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';
}
7 changes: 5 additions & 2 deletions library/Zend/Session/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"autoload": {
"psr-0": {
"Zend\\Session\\": ""
}
},
"files": [
"compatibility/autoload.php"
]
},
"target-dir": "Zend/Session",
"require": {
Expand All @@ -20,4 +23,4 @@
"zendframework/zend-validator": "Zend\\Validator component",
"zendframework/zend-eventmanager": "Zend\\EventManager component"
}
}
}

0 comments on commit 352a040

Please sign in to comment.