From 26edc746d56dd05b93b3b2056e31d1de83874991 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 5 Mar 2013 11:19:58 -0600 Subject: [PATCH 01/11] Reworked polyfill support for Zend\Stdlib\ArrayObject - Instead of using an autoload file, instead created two separate classes, named after the type of support they provide. The file Zend\Stdlib\ArrayObject now simply has a conditional in it; based on the condition met, a class_alias() is created -- and from then on, that alias will be used for Zend\Stdlib\ArrayObject. - Removed autoload.files entries from composer.json files; no longer necessary. - One test failure currently in doing a comparison of merged array objects; will investigate in a later commit. --- src/ArrayObject.php | 434 +----------------- .../PhpLegacyCompatibility.php} | 4 +- src/ArrayObject/PhpReferenceCompatibility.php | 434 ++++++++++++++++++ src/compatibility/autoload.php | 6 - 4 files changed, 449 insertions(+), 429 deletions(-) rename src/{compatibility/ArrayObject.php => ArrayObject/PhpLegacyCompatibility.php} (91%) create mode 100644 src/ArrayObject/PhpReferenceCompatibility.php delete mode 100644 src/compatibility/autoload.php diff --git a/src/ArrayObject.php b/src/ArrayObject.php index ec3ef0723..3d5f21135 100644 --- a/src/ArrayObject.php +++ b/src/ArrayObject.php @@ -7,427 +7,19 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -namespace Zend\Stdlib; - -use IteratorAggregate; -use ArrayAccess; -use Serializable; -use Countable; - /** - * ArrayObject - * - * This ArrayObject is a rewrite of the implementation to fix - * issues with php's implementation of ArrayObject where you - * are unable to unset multi-dimensional arrays because you - * need to fetch the properties / lists as references. + * If the version is less than 5.3.4, we'll use Zend\Stdlib\ArrayObject\PhpLegacyCompatibility + * which extend sthe native PHP ArrayObject implementation. For versions greater than or equal + * to 5.3.4, we'll use Zend\Stdlib\ArrayObject\PhpReferenceCompatibility, which corrects + * issues with how PHP handles references inside ArrayObject. + * + * class_alias is a global construct, so we can alias either one to Zend\Stdlib\ArrayObject, + * and from this point forward, that alias will be used. */ -class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Countable -{ - /** - * Properties of the object have their normal functionality - * when accessed as list (var_dump, foreach, etc.). - */ - const STD_PROP_LIST = 1; - - /** - * Entries can be accessed as properties (read and write). - */ - const ARRAY_AS_PROPS = 2; - - /** - * @var array - */ - protected $storage; - - /** - * @var int - */ - protected $flag; - - /** - * @var string - */ - protected $iteratorClass; - - /** - * @var array - */ - protected $protectedProperties; - - /** - * Constructor - * - * @param array $input - * @param int $flags - * @param string $iteratorClass - * @return ArrayObject - */ - public function __construct($input = array(), $flags = self::STD_PROP_LIST, $iteratorClass = 'ArrayIterator') - { - $this->setFlags($flags); - $this->storage = $input; - $this->setIteratorClass($iteratorClass); - $this->protectedProperties = array_keys(get_object_vars($this)); - } - - /** - * Returns whether the requested key exists - * - * @param mixed $key - * @return boolean - */ - public function __isset($key) - { - if ($this->flag == self::ARRAY_AS_PROPS) { - return $this->offsetExists($key); - } - if (in_array($key, $this->protectedProperties)) { - throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); - } - - return isset($this->$key); - } - - /** - * Sets the value at the specified key to value - * - * @param mixed $key - * @param mixed $value - * @return void - */ - public function __set($key, $value) - { - if ($this->flag == self::ARRAY_AS_PROPS) { - return $this->offsetSet($key, $value); - } - if (in_array($key, $this->protectedProperties)) { - throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); - } - $this->$key = $value; - } - - /** - * Unsets the value at the specified key - * - * @param mixed $key - * @return void - */ - public function __unset($key) - { - if ($this->flag == self::ARRAY_AS_PROPS) { - return $this->offsetUnset($key); - } - if (in_array($key, $this->protectedProperties)) { - throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); - } - unset($this->$key); - } - - /** - * Returns the value at the specified key by reference - * - * @param mixed $key - * @return mixed - */ - public function &__get($key) - { - $ret = null; - if ($this->flag == self::ARRAY_AS_PROPS) { - $ret =& $this->offsetGet($key); - - return $ret; - } - if (in_array($key, $this->protectedProperties)) { - throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); - } - - return $this->$key; - } - - /** - * Appends the value - * - * @param mixed $value - * @return void - */ - public function append($value) - { - $this->storage[] = $value; - } - - /** - * Sort the entries by value - * - * @return void - */ - public function asort() - { - asort($this->storage); - } - - /** - * Get the number of public properties in the ArrayObject - * - * @return int - */ - public function count() - { - return count($this->storage); - } - - /** - * Exchange the array for another one. - * - * @param array|ArrayObject $data - * @return array - */ - public function exchangeArray($data) - { - if (!is_array($data) && !is_object($data)) { - throw new Exception\InvalidArgumentException('Passed variable is not an array or object, using empty array instead'); - } - - if (is_object($data) && ($data instanceof ArrayObject || $data instanceof \ArrayObject)) { - $data = $data->getArrayCopy(); - } - if (!is_array($data)) { - $data = (array) $data; - } - - $storage = $this->storage; - - $this->storage = $data; - - return $storage; - } - - /** - * Creates a copy of the ArrayObject. - * - * @return array - */ - public function getArrayCopy() - { - return $this->storage; - } - - /** - * Gets the behavior flags. - * - * @return int - */ - public function getFlags() - { - return $this->flag; - } - - /** - * Create a new iterator from an ArrayObject instance - * - * @return \Iterator - */ - public function getIterator() - { - $class = $this->iteratorClass; - - return new $class($this->storage); - } - - /** - * Gets the iterator classname for the ArrayObject. - * - * @return string - */ - public function getIteratorClass() - { - return $this->iteratorClass; - } - - /** - * Sort the entries by key - * - * @return void - */ - public function ksort() - { - ksort($this->storage); - } - - /** - * Sort an array using a case insensitive "natural order" algorithm - * - * @return void - */ - public function natcasesort() - { - natcasesort($this->storage); - } - - /** - * Sort entries using a "natural order" algorithm - * - * @return void - */ - public function natsort() - { - natsort($this->storage); - } - - /** - * Returns whether the requested key exists - * - * @param mixed $key - * @return boolean - */ - public function offsetExists($key) - { - return isset($this->storage[$key]); - } - - /** - * Returns the value at the specified key - * - * @param mixed $key - * @return mixed - */ - public function &offsetGet($key) - { - $ret = null; - if (!$this->offsetExists($key)) { - return $ret; - } - $ret =& $this->storage[$key]; - - return $ret; - } - - /** - * Sets the value at the specified key to value - * - * @param mixed $key - * @param mixed $value - * @return void - */ - public function offsetSet($key, $value) - { - $this->storage[$key] = $value; - } - - /** - * Unsets the value at the specified key - * - * @param mixed $key - * @return void - */ - public function offsetUnset($key) - { - if ($this->offsetExists($key)) { - unset($this->storage[$key]); - } - } - - /** - * Serialize an ArrayObject - * - * @return string - */ - public function serialize() - { - return serialize(get_object_vars($this)); - } - - /** - * Sets the behavior flags - * - * @param int $flags - * @return void - */ - public function setFlags($flags) - { - $this->flag = $flags; - } - - /** - * Sets the iterator classname for the ArrayObject - * - * @param string $class - * @return void - */ - public function setIteratorClass($class) - { - if (class_exists($class)) { - $this->iteratorClass = $class; - - return ; - } - - if (strpos($class, '\\') === 0) { - $class = '\\' . $class; - if (class_exists($class)) { - $this->iteratorClass = $class; - - return ; - } - } - - throw new Exception\InvalidArgumentException('The iterator class does not exist'); - } - - /** - * Sort the entries with a user-defined comparison function and maintain key association - * - * @param callable $function - * @return void - */ - public function uasort($function) - { - if (is_callable($function)) { - uasort($this->storage, $function); - } - } - - /** - * Sort the entries by keys using a user-defined comparison function - * - * @param callable $function - * @return void - */ - public function uksort($function) - { - if (is_callable($function)) { - uksort($this->storage, $function); - } - } - - /** - * Unserialize an ArrayObject - * - * @param string $data - * @return void - */ - public function unserialize($data) - { - $ar = unserialize($data); - $this->setFlags($ar['flag']); - $this->exchangeArray($ar['storage']); - $this->setIteratorClass($ar['iteratorClass']); - foreach ($ar as $k => $v) { - switch ($k) { - case 'flag': - $this->setFlags($v); - break; - case 'storage': - $this->exchangeArray($v); - break; - case 'iteratorClass': - $this->setIteratorClass($v); - break; - case 'protectedProperties': - continue; - default: - $this->__set($k, $v); - } - } - } +if (version_compare(PHP_VERSION, '5.3.4', 'lt') + && !class_exists('Zend\Stdlib\ArrayObject', false) +) { + class_alias('Zend\Stdlib\ArrayObject\PhpLegacyCompatibility', 'Zend\Stdlib\ArrayObject'); +} else { + class_alias('Zend\Stdlib\ArrayObject\PhpReferenceCompatibility', 'Zend\Stdlib\ArrayObject'); } diff --git a/src/compatibility/ArrayObject.php b/src/ArrayObject/PhpLegacyCompatibility.php similarity index 91% rename from src/compatibility/ArrayObject.php rename to src/ArrayObject/PhpLegacyCompatibility.php index ec9316c55..70aa858ed 100644 --- a/src/compatibility/ArrayObject.php +++ b/src/ArrayObject/PhpLegacyCompatibility.php @@ -7,7 +7,7 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ -namespace Zend\Stdlib; +namespace Zend\Stdlib\ArrayObject; use ArrayObject as PhpArrayObject; @@ -19,7 +19,7 @@ * simply extends the PHP ArrayObject implementation, and provides default * behavior in the constructor. */ -class ArrayObject extends PhpArrayObject +class PhpLegacyCompatibility extends PhpArrayObject { /** * Constructor diff --git a/src/ArrayObject/PhpReferenceCompatibility.php b/src/ArrayObject/PhpReferenceCompatibility.php new file mode 100644 index 000000000..4aa5febc7 --- /dev/null +++ b/src/ArrayObject/PhpReferenceCompatibility.php @@ -0,0 +1,434 @@ +setFlags($flags); + $this->storage = $input; + $this->setIteratorClass($iteratorClass); + $this->protectedProperties = array_keys(get_object_vars($this)); + } + + /** + * Returns whether the requested key exists + * + * @param mixed $key + * @return boolean + */ + public function __isset($key) + { + if ($this->flag == self::ARRAY_AS_PROPS) { + return $this->offsetExists($key); + } + if (in_array($key, $this->protectedProperties)) { + throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); + } + + return isset($this->$key); + } + + /** + * Sets the value at the specified key to value + * + * @param mixed $key + * @param mixed $value + * @return void + */ + public function __set($key, $value) + { + if ($this->flag == self::ARRAY_AS_PROPS) { + return $this->offsetSet($key, $value); + } + if (in_array($key, $this->protectedProperties)) { + throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); + } + $this->$key = $value; + } + + /** + * Unsets the value at the specified key + * + * @param mixed $key + * @return void + */ + public function __unset($key) + { + if ($this->flag == self::ARRAY_AS_PROPS) { + return $this->offsetUnset($key); + } + if (in_array($key, $this->protectedProperties)) { + throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); + } + unset($this->$key); + } + + /** + * Returns the value at the specified key by reference + * + * @param mixed $key + * @return mixed + */ + public function &__get($key) + { + $ret = null; + if ($this->flag == self::ARRAY_AS_PROPS) { + $ret =& $this->offsetGet($key); + + return $ret; + } + if (in_array($key, $this->protectedProperties)) { + throw new Exception\InvalidArgumentException('$key is a protected property, use a different key'); + } + + return $this->$key; + } + + /** + * Appends the value + * + * @param mixed $value + * @return void + */ + public function append($value) + { + $this->storage[] = $value; + } + + /** + * Sort the entries by value + * + * @return void + */ + public function asort() + { + asort($this->storage); + } + + /** + * Get the number of public properties in the ArrayObject + * + * @return int + */ + public function count() + { + return count($this->storage); + } + + /** + * Exchange the array for another one. + * + * @param array|ArrayObject $data + * @return array + */ + public function exchangeArray($data) + { + if (!is_array($data) && !is_object($data)) { + throw new Exception\InvalidArgumentException('Passed variable is not an array or object, using empty array instead'); + } + + if (is_object($data) && ($data instanceof ArrayObject || $data instanceof \ArrayObject)) { + $data = $data->getArrayCopy(); + } + if (!is_array($data)) { + $data = (array) $data; + } + + $storage = $this->storage; + + $this->storage = $data; + + return $storage; + } + + /** + * Creates a copy of the ArrayObject. + * + * @return array + */ + public function getArrayCopy() + { + return $this->storage; + } + + /** + * Gets the behavior flags. + * + * @return int + */ + public function getFlags() + { + return $this->flag; + } + + /** + * Create a new iterator from an ArrayObject instance + * + * @return \Iterator + */ + public function getIterator() + { + $class = $this->iteratorClass; + + return new $class($this->storage); + } + + /** + * Gets the iterator classname for the ArrayObject. + * + * @return string + */ + public function getIteratorClass() + { + return $this->iteratorClass; + } + + /** + * Sort the entries by key + * + * @return void + */ + public function ksort() + { + ksort($this->storage); + } + + /** + * Sort an array using a case insensitive "natural order" algorithm + * + * @return void + */ + public function natcasesort() + { + natcasesort($this->storage); + } + + /** + * Sort entries using a "natural order" algorithm + * + * @return void + */ + public function natsort() + { + natsort($this->storage); + } + + /** + * Returns whether the requested key exists + * + * @param mixed $key + * @return boolean + */ + public function offsetExists($key) + { + return isset($this->storage[$key]); + } + + /** + * Returns the value at the specified key + * + * @param mixed $key + * @return mixed + */ + public function &offsetGet($key) + { + $ret = null; + if (!$this->offsetExists($key)) { + return $ret; + } + $ret =& $this->storage[$key]; + + return $ret; + } + + /** + * Sets the value at the specified key to value + * + * @param mixed $key + * @param mixed $value + * @return void + */ + public function offsetSet($key, $value) + { + $this->storage[$key] = $value; + } + + /** + * Unsets the value at the specified key + * + * @param mixed $key + * @return void + */ + public function offsetUnset($key) + { + if ($this->offsetExists($key)) { + unset($this->storage[$key]); + } + } + + /** + * Serialize an ArrayObject + * + * @return string + */ + public function serialize() + { + return serialize(get_object_vars($this)); + } + + /** + * Sets the behavior flags + * + * @param int $flags + * @return void + */ + public function setFlags($flags) + { + $this->flag = $flags; + } + + /** + * Sets the iterator classname for the ArrayObject + * + * @param string $class + * @return void + */ + public function setIteratorClass($class) + { + if (class_exists($class)) { + $this->iteratorClass = $class; + + return ; + } + + if (strpos($class, '\\') === 0) { + $class = '\\' . $class; + if (class_exists($class)) { + $this->iteratorClass = $class; + + return ; + } + } + + throw new Exception\InvalidArgumentException('The iterator class does not exist'); + } + + /** + * Sort the entries with a user-defined comparison function and maintain key association + * + * @param callable $function + * @return void + */ + public function uasort($function) + { + if (is_callable($function)) { + uasort($this->storage, $function); + } + } + + /** + * Sort the entries by keys using a user-defined comparison function + * + * @param callable $function + * @return void + */ + public function uksort($function) + { + if (is_callable($function)) { + uksort($this->storage, $function); + } + } + + /** + * Unserialize an ArrayObject + * + * @param string $data + * @return void + */ + public function unserialize($data) + { + $ar = unserialize($data); + $this->setFlags($ar['flag']); + $this->exchangeArray($ar['storage']); + $this->setIteratorClass($ar['iteratorClass']); + foreach ($ar as $k => $v) { + switch ($k) { + case 'flag': + $this->setFlags($v); + break; + case 'storage': + $this->exchangeArray($v); + break; + case 'iteratorClass': + $this->setIteratorClass($v); + break; + case 'protectedProperties': + continue; + default: + $this->__set($k, $v); + } + } + } +} diff --git a/src/compatibility/autoload.php b/src/compatibility/autoload.php deleted file mode 100644 index fc6c3974a..000000000 --- a/src/compatibility/autoload.php +++ /dev/null @@ -1,6 +0,0 @@ - Date: Tue, 5 Mar 2013 11:43:25 -0600 Subject: [PATCH 02/11] Solved failing test in ArrayObject tests - changed a typehint from "ArrayObject" to "self" --- src/ArrayObject/PhpReferenceCompatibility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArrayObject/PhpReferenceCompatibility.php b/src/ArrayObject/PhpReferenceCompatibility.php index 4aa5febc7..b5fa3422f 100644 --- a/src/ArrayObject/PhpReferenceCompatibility.php +++ b/src/ArrayObject/PhpReferenceCompatibility.php @@ -189,7 +189,7 @@ public function exchangeArray($data) throw new Exception\InvalidArgumentException('Passed variable is not an array or object, using empty array instead'); } - if (is_object($data) && ($data instanceof ArrayObject || $data instanceof \ArrayObject)) { + if (is_object($data) && ($data instanceof self || $data instanceof \ArrayObject)) { $data = $data->getArrayCopy(); } if (!is_array($data)) { From a6da63949d1e2df15b9c65029460231bea732630 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 5 Mar 2013 11:59:24 -0600 Subject: [PATCH 03/11] Re-added autoload.php files - BC measure, so that code referencing these files doesn't break --- src/autoload.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/autoload.php diff --git a/src/autoload.php b/src/autoload.php new file mode 100644 index 000000000..2c4e31e83 --- /dev/null +++ b/src/autoload.php @@ -0,0 +1,12 @@ + Date: Tue, 5 Mar 2013 12:05:03 -0600 Subject: [PATCH 04/11] Fix typo - per @DASPRiD --- src/ArrayObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ArrayObject.php b/src/ArrayObject.php index 3d5f21135..a1d6961a7 100644 --- a/src/ArrayObject.php +++ b/src/ArrayObject.php @@ -9,7 +9,7 @@ /** * If the version is less than 5.3.4, we'll use Zend\Stdlib\ArrayObject\PhpLegacyCompatibility - * which extend sthe native PHP ArrayObject implementation. For versions greater than or equal + * which extends the native PHP ArrayObject implementation. For versions greater than or equal * to 5.3.4, we'll use Zend\Stdlib\ArrayObject\PhpReferenceCompatibility, which corrects * issues with how PHP handles references inside ArrayObject. * From e9352f52fe1e372c1742f0e487d64fb59f039381 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 5 Mar 2013 15:04:43 -0600 Subject: [PATCH 05/11] Renamed compat autoload files and marked as deprecated - moved autoload.php files into compatibility subdirs where they belong - marked each with @deprecated annotation --- src/{ => compatibility}/autoload.php | 1 + 1 file changed, 1 insertion(+) rename src/{ => compatibility}/autoload.php (96%) diff --git a/src/autoload.php b/src/compatibility/autoload.php similarity index 96% rename from src/autoload.php rename to src/compatibility/autoload.php index 2c4e31e83..a52e30f48 100644 --- a/src/autoload.php +++ b/src/compatibility/autoload.php @@ -5,6 +5,7 @@ * @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 */ /** From 669123ae9b9a678fb854a7aa2d218377a2addfc7 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 5 Mar 2013 15:08:46 -0600 Subject: [PATCH 06/11] Remove class_exists check - bad cut-and-paste --- src/ArrayObject.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ArrayObject.php b/src/ArrayObject.php index a1d6961a7..afa632b5b 100644 --- a/src/ArrayObject.php +++ b/src/ArrayObject.php @@ -16,9 +16,7 @@ * class_alias is a global construct, so we can alias either one to Zend\Stdlib\ArrayObject, * and from this point forward, that alias will be used. */ -if (version_compare(PHP_VERSION, '5.3.4', 'lt') - && !class_exists('Zend\Stdlib\ArrayObject', false) -) { +if (version_compare(PHP_VERSION, '5.3.4', 'lt')) { class_alias('Zend\Stdlib\ArrayObject\PhpLegacyCompatibility', 'Zend\Stdlib\ArrayObject'); } else { class_alias('Zend\Stdlib\ArrayObject\PhpReferenceCompatibility', 'Zend\Stdlib\ArrayObject'); From 4eea76f704c89f63694646a3a27f251874e44635 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 5 Mar 2013 15:37:14 -0600 Subject: [PATCH 07/11] Fake scanners out - Use __halt_compiler(), and then define stub class, in order to trick classmap compilers into thinking a class exists. --- src/ArrayObject.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ArrayObject.php b/src/ArrayObject.php index afa632b5b..ee5c8e223 100644 --- a/src/ArrayObject.php +++ b/src/ArrayObject.php @@ -7,12 +7,14 @@ * @license http://framework.zend.com/license/new-bsd New BSD License */ +namespace Zend\Stdlib; + /** * If the version is less than 5.3.4, we'll use Zend\Stdlib\ArrayObject\PhpLegacyCompatibility * which extends the native PHP ArrayObject implementation. For versions greater than or equal * to 5.3.4, we'll use Zend\Stdlib\ArrayObject\PhpReferenceCompatibility, which corrects * issues with how PHP handles references inside ArrayObject. - * + * * class_alias is a global construct, so we can alias either one to Zend\Stdlib\ArrayObject, * and from this point forward, that alias will be used. */ @@ -21,3 +23,9 @@ class_alias('Zend\Stdlib\ArrayObject\PhpLegacyCompatibility', 'Zend\Stdlib\Array } else { class_alias('Zend\Stdlib\ArrayObject\PhpReferenceCompatibility', 'Zend\Stdlib\ArrayObject'); } + +__halt_compiler(); + +class ArrayObject extends \ArrayObject +{ +} From 967adce305ac8650fe7a9c049ecc57c0b147a504 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 5 Mar 2013 15:56:45 -0600 Subject: [PATCH 08/11] Class stubs to force classmap generation --- src/ArrayObject.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ArrayObject.php b/src/ArrayObject.php index ee5c8e223..21fa5bdd9 100644 --- a/src/ArrayObject.php +++ b/src/ArrayObject.php @@ -26,6 +26,9 @@ class_alias('Zend\Stdlib\ArrayObject\PhpReferenceCompatibility', 'Zend\Stdlib\Ar __halt_compiler(); +/** + * Class stub to force classmap generation + */ class ArrayObject extends \ArrayObject { } From bb6593dba4539dbe4afa14cd50f00c23dc6513bd Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 5 Mar 2013 17:18:34 -0600 Subject: [PATCH 09/11] Trigger E_USER_DEPRECATED in deprecated polyfill autoload files --- src/compatibility/autoload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compatibility/autoload.php b/src/compatibility/autoload.php index a52e30f48..cfc569626 100644 --- a/src/compatibility/autoload.php +++ b/src/compatibility/autoload.php @@ -11,3 +11,4 @@ /** * Legacy purposes only, to prevent code that references it from breaking. */ +trigger_error('Polyfill autoload support (file library/Zend/Stdlib/compatibility/autoload.php) is no longer necessary; please remove your require statement referencing this file', E_USER_DEPRECATED); From ad5bea179ca5cb620c1f5b87cd9a05421637bcc8 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 6 Mar 2013 06:23:17 -0600 Subject: [PATCH 10/11] Simpler polyfill support - Have a base class that extends a polyfill class - makes classmap generation simpler - makes typehinting and mock objects simpler --- src/ArrayObject.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ArrayObject.php b/src/ArrayObject.php index 21fa5bdd9..806c128fc 100644 --- a/src/ArrayObject.php +++ b/src/ArrayObject.php @@ -19,16 +19,16 @@ * and from this point forward, that alias will be used. */ if (version_compare(PHP_VERSION, '5.3.4', 'lt')) { - class_alias('Zend\Stdlib\ArrayObject\PhpLegacyCompatibility', 'Zend\Stdlib\ArrayObject'); + class_alias('Zend\Stdlib\ArrayObject\PhpLegacyCompatibility', 'Zend\Stdlib\AbstractArrayObject'); } else { - class_alias('Zend\Stdlib\ArrayObject\PhpReferenceCompatibility', 'Zend\Stdlib\ArrayObject'); + class_alias('Zend\Stdlib\ArrayObject\PhpReferenceCompatibility', 'Zend\Stdlib\AbstractArrayObject'); } -__halt_compiler(); - /** - * Class stub to force classmap generation + * Custom framework ArrayObject implementation + * + * Extends version-specific "abstract" implementation. */ -class ArrayObject extends \ArrayObject +class ArrayObject extends AbstractArrayObject { } From a5811ab08709f213be4c3bcdcd3e1157b961ad61 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 6 Mar 2013 06:34:18 -0600 Subject: [PATCH 11/11] Mark all polyfill bases as abstract - they are not intended to be instantiated directly; they are intended as bases for the typehinted class that uses the polyfills. --- src/ArrayObject/PhpLegacyCompatibility.php | 2 +- src/ArrayObject/PhpReferenceCompatibility.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ArrayObject/PhpLegacyCompatibility.php b/src/ArrayObject/PhpLegacyCompatibility.php index 70aa858ed..4d0f44d47 100644 --- a/src/ArrayObject/PhpLegacyCompatibility.php +++ b/src/ArrayObject/PhpLegacyCompatibility.php @@ -19,7 +19,7 @@ * simply extends the PHP ArrayObject implementation, and provides default * behavior in the constructor. */ -class PhpLegacyCompatibility extends PhpArrayObject +abstract class PhpLegacyCompatibility extends PhpArrayObject { /** * Constructor diff --git a/src/ArrayObject/PhpReferenceCompatibility.php b/src/ArrayObject/PhpReferenceCompatibility.php index b5fa3422f..9e680abbf 100644 --- a/src/ArrayObject/PhpReferenceCompatibility.php +++ b/src/ArrayObject/PhpReferenceCompatibility.php @@ -23,7 +23,7 @@ * are unable to unset multi-dimensional arrays because you * need to fetch the properties / lists as references. */ -class PhpReferenceCompatibility implements IteratorAggregate, ArrayAccess, Serializable, Countable +abstract class PhpReferenceCompatibility implements IteratorAggregate, ArrayAccess, Serializable, Countable { /** * Properties of the object have their normal functionality