MediaWiki
master
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
20
public
function
__construct
(
HookContainer
$hookContainer,
string
$name ) {
21
$this->hookContainer = $hookContainer;
22
$this->name = $name;
23
}
24
28
#[\ReturnTypeWillChange]
29
public
function
offsetExists
( $offset ) {
30
return
$this->getHandler( $offset ) !==
null
;
31
}
32
36
#[\ReturnTypeWillChange]
37
public
function
offsetGet
( $offset ) {
38
$handler = $this->getHandler( $offset );
39
40
if
( !$handler ) {
41
throw
new
OutOfBoundsException(
"No such index in the handler list: $offset"
);
42
}
43
44
return
$handler;
45
}
46
50
#[\ReturnTypeWillChange]
51
public
function
offsetSet
( $offset, $value ) {
52
if
( $offset !==
null
) {
53
throw
new
InvalidArgumentException(
'$offset must be null, this array is append only'
);
54
}
55
56
$this->hookContainer->register( $this->name, $value );
57
$this->handlers =
null
;
58
}
59
64
#[\ReturnTypeWillChange]
65
public
function
offsetUnset
( $offset ) {
66
throw
new
LogicException(
'unset is not supported for hook handler arrays'
);
67
}
68
69
private
function
getHandler( $offset ) {
70
if
( $this->handlers ===
null
) {
71
// NOTE: getHandlerCallbacks() only exists to support this.
72
// It should be deleted when we no longer need it here.
73
$this->handlers = $this->hookContainer->getHandlerCallbacks( $this->name );
74
}
75
76
return
$this->handlers[$offset] ??
null
;
77
}
78
79
#[\ReturnTypeWillChange]
80
public
function
getIterator
() {
81
if
( $this->handlers ===
null
) {
82
// NOTE: getHandlerCallbacks() only exists to support this.
83
// It should be deleted when we no longer need it here.
84
$this->handlers = $this->hookContainer->getHandlerCallbacks( $this->name );
85
}
86
87
return
new \ArrayIterator( $this->handlers );
88
}
89
}
MediaWiki\HookContainer\FauxHookHandlerArray
Definition
FauxHookHandlerArray.php:12
MediaWiki\HookContainer\FauxHookHandlerArray\getIterator
getIterator()
Definition
FauxHookHandlerArray.php:80
MediaWiki\HookContainer\FauxHookHandlerArray\offsetSet
offsetSet( $offset, $value)
Definition
FauxHookHandlerArray.php:51
MediaWiki\HookContainer\FauxHookHandlerArray\offsetExists
offsetExists( $offset)
Definition
FauxHookHandlerArray.php:29
MediaWiki\HookContainer\FauxHookHandlerArray\offsetGet
offsetGet( $offset)
Definition
FauxHookHandlerArray.php:37
MediaWiki\HookContainer\FauxHookHandlerArray\offsetUnset
offsetUnset( $offset)
Definition
FauxHookHandlerArray.php:65
MediaWiki\HookContainer\FauxHookHandlerArray\__construct
__construct(HookContainer $hookContainer, string $name)
Definition
FauxHookHandlerArray.php:20
MediaWiki\HookContainer\HookContainer
HookContainer class.
Definition
HookContainer.php:57
MediaWiki\HookContainer
Definition
DeprecatedHooks.php:23
includes
HookContainer
FauxHookHandlerArray.php
Generated on Mon Jan 20 2025 17:24:14 for MediaWiki by
1.10.0