MediaWiki REL1_40
DeprecatablePropertyArray.php
Go to the documentation of this file.
1<?php
2
4
5use ArrayAccess;
6
16class DeprecatablePropertyArray implements ArrayAccess {
17
19 private $container;
20
22 private $deprecatedProperties;
23
25 private $name;
26
28 private $component;
29
37 public function __construct(
38 array $initializer,
39 array $deprecatedProperties,
40 string $name,
41 string $component = null
42 ) {
43 $this->container = $initializer;
44 $this->deprecatedProperties = $deprecatedProperties;
45 $this->name = $name;
46 $this->component = $component;
47 }
48
49 public function offsetExists( $offset ): bool {
50 $this->checkDeprecatedAccess( $offset, 'exists' );
51 return isset( $this->container[$offset] );
52 }
53
54 #[\ReturnTypeWillChange]
55 public function offsetGet( $offset ) {
56 if ( $this->checkDeprecatedAccess( $offset, 'get' ) ) {
57 if ( is_callable( $this->container[$offset] ) ) {
58 $this->container[$offset] = call_user_func( $this->container[$offset] );
59 }
60 }
61 return $this->container[$offset] ?? null;
62 }
63
64 public function offsetSet( $offset, $value ): void {
65 if ( $offset === null ) {
66 $this->container[] = $value;
67 } else {
68 $this->container[$offset] = $value;
69 }
70 }
71
72 public function offsetUnset( $offset ): void {
73 $this->checkDeprecatedAccess( $offset, 'unset' );
74 unset( $this->container[$offset] );
75 }
76
82 private function checkDeprecatedAccess( $offset, string $fname ): bool {
83 if ( array_key_exists( $offset, $this->deprecatedProperties ) ) {
84 $deprecatedVersion = $this->deprecatedProperties[$offset];
86 "{$this->name} {$fname} '{$offset}'",
87 $deprecatedVersion,
88 $this->component ?? false,
89 3
90 );
91 return true;
92 }
93 return false;
94 }
95}
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition WebStart.php:88
ArrayAccess implementation that supports deprecating access to certain properties.
__construct(array $initializer, array $deprecatedProperties, string $name, string $component=null)