| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Debug; |
| 4 |
|
| 5 |
use ArrayAccess; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
class DeprecatablePropertyArray implements ArrayAccess { |
| 19 |
|
| 20 |
|
| 21 |
private $container; |
| 22 |
|
| 23 |
|
| 24 |
private $deprecatedProperties; |
| 25 |
|
| 26 |
|
| 27 |
private $name; |
| 28 |
|
| 29 |
|
| 30 |
private $component; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public function __construct( |
| 40 |
array $initializer, |
| 41 |
array $deprecatedProperties, |
| 42 |
string $name, |
| 43 |
?string $component = null |
| 44 |
) { |
| 45 |
$this->container = $initializer; |
| 46 |
$this->deprecatedProperties = $deprecatedProperties; |
| 47 |
$this->name = $name; |
| 48 |
$this->component = $component; |
| 49 |
} |
| 50 |
|
| 51 |
public function offsetExists( $offset ): bool { |
| 52 |
$this->checkDeprecatedAccess( $offset, 'exists' ); |
| 53 |
return isset( $this->container[$offset] ); |
| 54 |
} |
| 55 |
|
| 56 |
#[\ReturnTypeWillChange] |
| 57 |
public function offsetGet( $offset ) { |
| 58 |
if ( $this->checkDeprecatedAccess( $offset, 'get' ) ) { |
| 59 |
if ( is_callable( $this->container[$offset] ) ) { |
| 60 |
$this->container[$offset] = call_user_func( $this->container[$offset] ); |
| 61 |
} |
| 62 |
} |
| 63 |
return $this->container[$offset] ?? null; |
| 64 |
} |
| 65 |
|
| 66 |
public function offsetSet( $offset, $value ): void { |
| 67 |
if ( $offset === null ) { |
| 68 |
$this->container[] = $value; |
| 69 |
} else { |
| 70 |
$this->container[$offset] = $value; |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
public function offsetUnset( $offset ): void { |
| 75 |
$this->checkDeprecatedAccess( $offset, 'unset' ); |
| 76 |
unset( $this->container[$offset] ); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
private function checkDeprecatedAccess( $offset, string $fname ): bool { |
| 85 |
if ( array_key_exists( $offset, $this->deprecatedProperties ) ) { |
| 86 |
$deprecatedVersion = $this->deprecatedProperties[$offset]; |
| 87 |
wfDeprecated( |
| 88 |
"{$this->name} {$fname} '{$offset}'", |
| 89 |
$deprecatedVersion, |
| 90 |
$this->component ?? false, |
| 91 |
3 |
| 92 |
); |
| 93 |
return true; |
| 94 |
} |
| 95 |
return false; |
| 96 |
} |
| 97 |
} |