MediaWiki  master
DeprecatablePropertyArray.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Debug;
4 
5 use ArrayAccess;
6 
16 class DeprecatablePropertyArray implements ArrayAccess {
17 
19  private $container;
20 
23 
25  private $name;
26 
28  private $component;
29 
37  public function __construct(
38  array $initializer,
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 ) {
50  $this->checkDeprecatedAccess( $offset, 'exists' );
51  return isset( $this->container[$offset] );
52  }
53 
54  public function offsetGet( $offset ) {
55  if ( $this->checkDeprecatedAccess( $offset, 'get' ) ) {
56  if ( is_callable( $this->container[$offset] ) ) {
57  $this->container[$offset] = call_user_func( $this->container[$offset] );
58  }
59  }
60  return $this->container[$offset] ?? null;
61  }
62 
63  public function offsetSet( $offset, $value ) {
64  if ( $offset === null ) {
65  $this->container[] = $value;
66  } else {
67  $this->container[$offset] = $value;
68  }
69  }
70 
71  public function offsetUnset( $offset ) {
72  $this->checkDeprecatedAccess( $offset, 'unset' );
73  unset( $this->container[$offset] );
74  }
75 
81  private function checkDeprecatedAccess( $offset, string $fname ) : bool {
82  if ( array_key_exists( $offset, $this->deprecatedProperties ) ) {
83  $deprecatedVersion = $this->deprecatedProperties[$offset];
85  "{$this->name} {$fname} '{$offset}'",
86  $deprecatedVersion,
87  $this->component ?? false,
88  3
89  );
90  return true;
91  }
92  return false;
93  }
94 }
MediaWiki\Debug
Definition: DeprecatablePropertyArray.php:3
MediaWiki\Debug\DeprecatablePropertyArray\__construct
__construct(array $initializer, array $deprecatedProperties, string $name, string $component=null)
Definition: DeprecatablePropertyArray.php:37
MediaWiki\Debug\DeprecatablePropertyArray\$container
array $container
Definition: DeprecatablePropertyArray.php:19
MediaWiki\Debug\DeprecatablePropertyArray\offsetSet
offsetSet( $offset, $value)
Definition: DeprecatablePropertyArray.php:63
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
Definition: GlobalFunctions.php:1026
MediaWiki\Debug\DeprecatablePropertyArray\$component
string null $component
Definition: DeprecatablePropertyArray.php:28
MediaWiki\Debug\DeprecatablePropertyArray\offsetExists
offsetExists( $offset)
Definition: DeprecatablePropertyArray.php:49
MediaWiki\Debug\DeprecatablePropertyArray\$deprecatedProperties
array $deprecatedProperties
Map of deprecated property names to deprecation versions.
Definition: DeprecatablePropertyArray.php:22
MediaWiki\Debug\DeprecatablePropertyArray\checkDeprecatedAccess
checkDeprecatedAccess( $offset, string $fname)
Definition: DeprecatablePropertyArray.php:81
MediaWiki\Debug\DeprecatablePropertyArray\$name
string $name
Definition: DeprecatablePropertyArray.php:25
MediaWiki\Debug\DeprecatablePropertyArray\offsetGet
offsetGet( $offset)
Definition: DeprecatablePropertyArray.php:54
MediaWiki\Debug\DeprecatablePropertyArray
ArrayAccess implementation that supports deprecating access to certain properties.
Definition: DeprecatablePropertyArray.php:16
MediaWiki\Debug\DeprecatablePropertyArray\offsetUnset
offsetUnset( $offset)
Definition: DeprecatablePropertyArray.php:71