Debian Codegraph @

includes/HookContainer/FauxGlobalHookArray.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\HookContainer;
4
5 use InvalidArgumentException;
6
7 /**
8 * @internal
9 */
10 class FauxGlobalHookArray implements \ArrayAccess {
11
12 private HookContainer $hookContainer;
13
14 /**
15 * The original handler array.
16 * @var array
17 */
18 private array $originalArray;
19
20 /**
21 * @param HookContainer $hookContainer
22 * @param array $originalArray
23 */
24 public function __construct( HookContainer $hookContainer, array $originalArray = [] ) {
25 $this->hookContainer = $hookContainer;
26 $this->originalArray = $originalArray;
27 }
28
29 /**
30 * @inheritDoc
31 */
32 #[\ReturnTypeWillChange]
33 public function offsetExists( $key ) {
34 wfDeprecatedMsg(
35 'Accessing $wgHooks directly is deprecated, use HookContainer::isRegistered() instead.',
36 '1.40'
37 );
38 return $this->hookContainer->isRegistered( $key );
39 }
40
41 /**
42 * @inheritDoc
43 */
44 #[\ReturnTypeWillChange]
45 public function offsetGet( $key ) {
46 wfDeprecatedMsg(
47 'Accessing $wgHooks directly is deprecated, use HookContainer::getHandlers() ' .
48 'or HookContainer::register() instead.',
49 '1.40'
50 );
51
52 return new FauxHookHandlerArray( $this->hookContainer, $key );
53 }
54
55 /**
56 * @inheritDoc
57 */
58 #[\ReturnTypeWillChange]
59 public function offsetSet( $key, $value ) {
60 if ( !is_string( $key ) ) {
61 throw new InvalidArgumentException( '$key must be a string' );
62 }
63 if ( !is_array( $value ) ) {
64 throw new InvalidArgumentException( '$value must be an array' );
65 }
66
67 wfDeprecatedMsg(
68 'Manipulating $wgHooks is deprecated, use HookContainer::clear() and ' .
69 'HookContainer::register() instead.',
70 '1.40'
71 );
72
73 $this->hookContainer->clear( $key );
74
75 foreach ( $value as $handler ) {
76 $this->hookContainer->register( $key, $handler );
77 }
78 }
79
80 /**
81 * @inheritDoc
82 */
83 #[\ReturnTypeWillChange]
84 public function offsetUnset( $key ) {
85 wfDeprecatedMsg( 'Manipulating $wgHooks is deprecated, use HookContainer::clear() instead.', '1.40' );
86 if ( $this->hookContainer->isRegistered( $key ) ) {
87 $this->hookContainer->clear( $key );
88 }
89 }
90
91 public function getOriginalArray(): array {
92 return $this->originalArray;
93 }
94 }