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

Commit

Permalink
Merge branch 'weierophinney-hotfix/polyfill-via-class-alias' into dev…
Browse files Browse the repository at this point in the history
  • Loading branch information
Freeaqingme committed Mar 6, 2013
3 parents 79d9ad3 + 370a890 + 68a1766 commit 7c09779
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 88 deletions.
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
"autoload": {
"psr-4": {
"Zend\\Session\\": "src/"
},
"files": [
"Zend/Session/compatibility/autoload.php"
]
}
},
"require": {
"php": ">=5.3.3",
Expand Down
26 changes: 7 additions & 19 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

namespace Zend\Session;

if (version_compare(PHP_VERSION, '5.3.4', 'lt')) {
class_alias('Zend\Session\AbstractContainer', 'Zend\Session\AbstractBaseContainer');
} else {
class_alias('Zend\Session\Container\PhpReferenceCompatibility', 'Zend\Session\AbstractBaseContainer');
}

/**
* Session storage container
*
Expand All @@ -17,24 +23,6 @@
* 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
class Container extends AbstractBaseContainer
{
/**
* 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;
}
}
37 changes: 37 additions & 0 deletions src/Container/PhpReferenceCompatibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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\Container;

use Zend\Session\AbstractContainer;

/**
* Session storage container for PHP 5.3.4 and above.
*/
abstract class PhpReferenceCompatibility extends AbstractContainer
{
/**
* 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;
}
}
29 changes: 7 additions & 22 deletions src/Storage/SessionArrayStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,15 @@

namespace Zend\Session\Storage;

if (version_compare(PHP_VERSION, '5.3.4', 'lt')) {
class_alias('Zend\Session\Storage\AbstractSessionArrayStorage', 'Zend\Session\Storage\AbstractBaseSessionArrayStorage');
} else {
class_alias('Zend\Session\Storage\SessionArrayStorage\PhpReferenceCompatibility', 'Zend\Session\Storage\AbstractBaseSessionArrayStorage');
}

/**
* Session storage in $_SESSION
*/
class SessionArrayStorage extends AbstractSessionArrayStorage
class SessionArrayStorage extends AbstractBaseSessionArrayStorage
{
/**
* Get Offset
*
* @param mixed $key
* @return mixed
*/
public function &__get($key)
{
return $_SESSION[$key];
}

/**
* Offset Get
*
* @param mixed $key
* @return mixed
*/
public function &offsetGet($key)
{
return $_SESSION[$key];
}
}
40 changes: 40 additions & 0 deletions src/Storage/SessionArrayStorage/PhpReferenceCompatibility.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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\SessionArrayStorage;

use Zend\Session\Storage\AbstractSessionArrayStorage;

/**
* PHP 5.3.4 and greater variant of SessionArrayStorage
*/
abstract class PhpReferenceCompatibility extends AbstractSessionArrayStorage
{
/**
* Get Offset
*
* @param mixed $key
* @return mixed
*/
public function &__get($key)
{
return $_SESSION[$key];
}

/**
* Offset Get
*
* @param mixed $key
* @return mixed
*/
public function &offsetGet($key)
{
return $_SESSION[$key];
}
}
17 changes: 0 additions & 17 deletions src/compatibility/Container.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/compatibility/Storage/SessionArrayStorage.php

This file was deleted.

21 changes: 12 additions & 9 deletions src/compatibility/autoload.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php
if (version_compare(PHP_VERSION, '5.3.4', 'lt')) {
if (!class_exists('Zend\Stdlib\ArrayObject', false)
&& file_exists(__DIR__ . '/../../Stdlib/compatibility/autoload.php')
) {
require __DIR__ . '/../../Stdlib/compatibility/autoload.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
* @deprecated
*/

require_once __DIR__ . '/Container.php';
require_once __DIR__ . '/Storage/SessionArrayStorage.php';
}
/**
* Legacy purposes only, to prevent code that references it from breaking.
*/
trigger_error('Polyfill autoload support (file library/Zend/Session/compatibility/autoload.php) is no longer necessary; please remove your require statement referencing this file', E_USER_DEPRECATED);

0 comments on commit 7c09779

Please sign in to comment.