MediaWiki master
DeprecatablePropertyArray.php
Go to the documentation of this file.
1<?php
2
4
5use ArrayAccess;
6
18class DeprecatablePropertyArray implements ArrayAccess {
19
21 private $container;
22
24 private $deprecatedProperties;
25
27 private $name;
28
30 private $component;
31
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
52 public function offsetExists( $offset ): bool {
53 $this->checkDeprecatedAccess( $offset, 'exists' );
54 return isset( $this->container[$offset] );
55 }
56
58 #[\ReturnTypeWillChange]
59 public function offsetGet( $offset ) {
60 if ( $this->checkDeprecatedAccess( $offset, 'get' ) ) {
61 if ( is_callable( $this->container[$offset] ) ) {
62 $this->container[$offset] = $this->container[$offset]();
63 }
64 }
65 return $this->container[$offset] ?? null;
66 }
67
69 public function offsetSet( $offset, $value ): void {
70 if ( $offset === null ) {
71 $this->container[] = $value;
72 } else {
73 $this->container[$offset] = $value;
74 }
75 }
76
78 public function offsetUnset( $offset ): void {
79 $this->checkDeprecatedAccess( $offset, 'unset' );
80 unset( $this->container[$offset] );
81 }
82
88 private function checkDeprecatedAccess( $offset, string $fname ): bool {
89 if ( array_key_exists( $offset, $this->deprecatedProperties ) ) {
90 $deprecatedVersion = $this->deprecatedProperties[$offset];
92 "{$this->name} {$fname} '{$offset}'",
93 $deprecatedVersion,
94 $this->component ?? false,
95 3
96 );
97 return true;
98 }
99 return false;
100 }
101}
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:82
ArrayAccess with support for deprecating access to certain offsets.
__construct(array $initializer, array $deprecatedProperties, string $name, ?string $component=null)