From 31314fca7d0ae1d365dc8b929b974f364004cb8a Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Sun, 13 Oct 2019 12:02:03 +0100 Subject: [PATCH] Issue #3087602 by Charlie ChX Negyesi, kim.pepper, mondrake, larowlan: DeprecatedArray implements \ArrayAccess, traversals not possible --- .../Component/Utility/DeprecatedArray.php | 51 ++++++++++++++----- .../Core/Pager/PagerManagerTest.php | 7 +++ 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/core/lib/Drupal/Component/Utility/DeprecatedArray.php b/core/lib/Drupal/Component/Utility/DeprecatedArray.php index 88d02872326..d8483ea6862 100644 --- a/core/lib/Drupal/Component/Utility/DeprecatedArray.php +++ b/core/lib/Drupal/Component/Utility/DeprecatedArray.php @@ -5,14 +5,7 @@ namespace Drupal\Component\Utility; /** * An array that triggers a deprecation warning when accessed. */ -class DeprecatedArray implements \ArrayAccess { - - /** - * The array values. - * - * @var array - */ - protected $values = []; +class DeprecatedArray extends \ArrayObject { /** * The deprecation message. @@ -30,8 +23,8 @@ class DeprecatedArray implements \ArrayAccess { * The deprecation message. */ public function __construct(array $values, $message) { - $this->values = $values; $this->message = $message; + parent::__construct($values); } /** @@ -39,7 +32,7 @@ class DeprecatedArray implements \ArrayAccess { */ public function offsetExists($offset) { @trigger_error($this->message, E_USER_DEPRECATED); - return isset($this->values[$offset]); + return parent::offsetExists($offset); } /** @@ -47,7 +40,7 @@ class DeprecatedArray implements \ArrayAccess { */ public function offsetGet($offset) { @trigger_error($this->message, E_USER_DEPRECATED); - return $this->values[$offset] ?? NULL; + return parent::offsetGet($offset); } /** @@ -55,7 +48,7 @@ class DeprecatedArray implements \ArrayAccess { */ public function offsetSet($offset, $value) { @trigger_error($this->message, E_USER_DEPRECATED); - return $this->values[$offset] = $value; + parent::offsetSet($offset, $value); } /** @@ -63,7 +56,39 @@ class DeprecatedArray implements \ArrayAccess { */ public function offsetUnset($offset) { @trigger_error($this->message, E_USER_DEPRECATED); - unset($this->values[$offset]); + parent::offsetUnset($offset); + } + + /** + * {@inheritdoc} + */ + public function getIterator() { + @trigger_error($this->message, E_USER_DEPRECATED); + return parent::getIterator(); + } + + /** + * {@inheritdoc} + */ + public function unserialize($serialized) { + @trigger_error($this->message, E_USER_DEPRECATED); + parent::unserialize($serialized); + } + + /** + * {@inheritdoc} + */ + public function serialize() { + @trigger_error($this->message, E_USER_DEPRECATED); + return parent::serialize(); + } + + /** + * {@inheritdoc} + */ + public function count() { + @trigger_error($this->message, E_USER_DEPRECATED); + return parent::count(); } } diff --git a/core/tests/Drupal/KernelTests/Core/Pager/PagerManagerTest.php b/core/tests/Drupal/KernelTests/Core/Pager/PagerManagerTest.php index a03e759ad30..10428a079f0 100644 --- a/core/tests/Drupal/KernelTests/Core/Pager/PagerManagerTest.php +++ b/core/tests/Drupal/KernelTests/Core/Pager/PagerManagerTest.php @@ -90,6 +90,13 @@ class PagerManagerTest extends KernelTestBase { $this->assertEquals(30, $GLOBALS['pager_total_items'][0]); $this->assertEquals(3, $GLOBALS['pager_total'][0]); $this->assertEquals(10, $GLOBALS['pager_limits'][0]); + + // Assert array is iterable. + foreach ($GLOBALS['pager_total_items'] as $pager_id => $total_items) { + // We only have one pager. + $this->assertEquals(0, $pager_id); + $this->assertEquals(30, $total_items); + } } }