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
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
84 private function checkDeprecatedAccess( $offset, string $fname ): bool {
85 if ( array_key_exists( $offset, $this->deprecatedProperties ) ) {
86 $deprecatedVersion = $this->deprecatedProperties[$offset];
88 "{$this->name} {$fname} '{$offset}'",
89 $deprecatedVersion,
90 $this->component ?? false,
91 3
92 );
93 return true;
94 }
95 return false;
96 }
97}
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:81
ArrayAccess with support for deprecating access to certain offsets.
__construct(array $initializer, array $deprecatedProperties, string $name, string $component=null)