MediaWiki
1.42.1
FauxHookHandlerArray.php
Go to the documentation of this file.
1
<?php
2
3
namespace
MediaWiki\HookContainer
;
4
5
use InvalidArgumentException;
6
use LogicException;
7
use OutOfBoundsException;
8
12
class
FauxHookHandlerArray
implements
\ArrayAccess, \IteratorAggregate {
13
14
private
HookContainer
$hookContainer;
15
16
private
string
$name;
17
18
private
?array $handlers =
null
;
19
24
public
function
__construct
(
HookContainer
$hookContainer,
string
$name ) {
25
$this->hookContainer = $hookContainer;
26
$this->name = $name;
27
}
28
32
#[\ReturnTypeWillChange]
33
public
function
offsetExists
( $offset ) {
34
return
$this->getHandler( $offset ) !==
null
;
35
}
36
40
#[\ReturnTypeWillChange]
41
public
function
offsetGet
( $offset ) {
42
$handler = $this->getHandler( $offset );
43
44
if
( !$handler ) {
45
throw
new
OutOfBoundsException(
"No such index in the handler list: $offset"
);
46
}
47
48
return
$handler;
49
}
50
54
#[\ReturnTypeWillChange]
55
public
function
offsetSet
( $offset, $value ) {
56
if
( $offset !==
null
) {
57
throw
new
InvalidArgumentException(
'$offset must be null, this array is append only'
);
58
}
59
60
$this->hookContainer->register( $this->name, $value );
61
$this->handlers =
null
;
62
}
63
68
#[\ReturnTypeWillChange]
69
public
function
offsetUnset
( $offset ) {
70
throw
new
LogicException(
'unset is not supported for hook handler arrays'
);
71
}
72
73
private
function
getHandler( $offset ) {
74
if
( $this->handlers ===
null
) {
75
// NOTE: getHandlerCallbacks() only exists to support this.
76
// It should be deleted when we no longer need it here.
77
$this->handlers = $this->hookContainer->getHandlerCallbacks( $this->name );
78
}
79
80
return
$this->handlers[$offset] ??
null
;
81
}
82
83
#[\ReturnTypeWillChange]
84
public
function
getIterator
() {
85
if
( $this->handlers ===
null
) {
86
// NOTE: getHandlerCallbacks() only exists to support this.
87
// It should be deleted when we no longer need it here.
88
$this->handlers = $this->hookContainer->getHandlerCallbacks( $this->name );
89
}
90
91
return
new \ArrayIterator( $this->handlers );
92
}
93
}
MediaWiki\HookContainer\FauxHookHandlerArray
Definition
FauxHookHandlerArray.php:12
MediaWiki\HookContainer\FauxHookHandlerArray\getIterator
getIterator()
Definition
FauxHookHandlerArray.php:84
MediaWiki\HookContainer\FauxHookHandlerArray\offsetSet
offsetSet( $offset, $value)
Definition
FauxHookHandlerArray.php:55
MediaWiki\HookContainer\FauxHookHandlerArray\offsetExists
offsetExists( $offset)
Definition
FauxHookHandlerArray.php:33
MediaWiki\HookContainer\FauxHookHandlerArray\offsetGet
offsetGet( $offset)
Definition
FauxHookHandlerArray.php:41
MediaWiki\HookContainer\FauxHookHandlerArray\offsetUnset
offsetUnset( $offset)
Definition
FauxHookHandlerArray.php:69
MediaWiki\HookContainer\FauxHookHandlerArray\__construct
__construct(HookContainer $hookContainer, string $name)
Definition
FauxHookHandlerArray.php:24
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition
HookContainer.php:57
MediaWiki\HookContainer
Definition
DeprecatedHooks.php:23
includes
HookContainer
FauxHookHandlerArray.php
Generated on Thu Jun 27 2024 15:58:53 for MediaWiki by
1.10.0