Issue #3087602 by Charlie ChX Negyesi, kim.pepper, mondrake, larowlan: DeprecatedArray implements \ArrayAccess, traversals not possible
parent
1c4e7f7f9a
commit
31314fca7d
|
@ -5,14 +5,7 @@ namespace Drupal\Component\Utility;
|
||||||
/**
|
/**
|
||||||
* An array that triggers a deprecation warning when accessed.
|
* An array that triggers a deprecation warning when accessed.
|
||||||
*/
|
*/
|
||||||
class DeprecatedArray implements \ArrayAccess {
|
class DeprecatedArray extends \ArrayObject {
|
||||||
|
|
||||||
/**
|
|
||||||
* The array values.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $values = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The deprecation message.
|
* The deprecation message.
|
||||||
|
@ -30,8 +23,8 @@ class DeprecatedArray implements \ArrayAccess {
|
||||||
* The deprecation message.
|
* The deprecation message.
|
||||||
*/
|
*/
|
||||||
public function __construct(array $values, $message) {
|
public function __construct(array $values, $message) {
|
||||||
$this->values = $values;
|
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
|
parent::__construct($values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +32,7 @@ class DeprecatedArray implements \ArrayAccess {
|
||||||
*/
|
*/
|
||||||
public function offsetExists($offset) {
|
public function offsetExists($offset) {
|
||||||
@trigger_error($this->message, E_USER_DEPRECATED);
|
@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) {
|
public function offsetGet($offset) {
|
||||||
@trigger_error($this->message, E_USER_DEPRECATED);
|
@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) {
|
public function offsetSet($offset, $value) {
|
||||||
@trigger_error($this->message, E_USER_DEPRECATED);
|
@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) {
|
public function offsetUnset($offset) {
|
||||||
@trigger_error($this->message, E_USER_DEPRECATED);
|
@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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,13 @@ class PagerManagerTest extends KernelTestBase {
|
||||||
$this->assertEquals(30, $GLOBALS['pager_total_items'][0]);
|
$this->assertEquals(30, $GLOBALS['pager_total_items'][0]);
|
||||||
$this->assertEquals(3, $GLOBALS['pager_total'][0]);
|
$this->assertEquals(3, $GLOBALS['pager_total'][0]);
|
||||||
$this->assertEquals(10, $GLOBALS['pager_limits'][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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue