| 1 |
<?php |
| 2 |
|
| 3 |
// AUTOMATICALLY GENERATED. DO NOT EDIT. |
| 4 |
// Use `composer build` to regenerate. |
| 5 |
|
| 6 |
namespace Wikimedia\IDLeDOM\Helper; |
| 7 |
|
| 8 |
use Wikimedia\IDLeDOM\Node; |
| 9 |
|
| 10 |
trait NodeList { |
| 11 |
|
| 12 |
// Underscore is used to avoid conflicts with DOM-reserved names |
| 13 |
// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
| 14 |
// phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName |
| 15 |
|
| 16 |
/** |
| 17 |
* Handle an attempt to get a non-existing property on this |
| 18 |
* object. The default implementation raises an exception |
| 19 |
* but the implementor can choose a different behavior: |
| 20 |
* return null (like JavaScript), dynamically create the |
| 21 |
* property, etc. |
| 22 |
* @param string $prop the name of the property requested |
| 23 |
* @return mixed |
| 24 |
*/ |
| 25 |
protected function _getMissingProp( string $prop ) { |
| 26 |
$trace = debug_backtrace(); |
| 27 |
while ( |
| 28 |
count( $trace ) > 0 && |
| 29 |
$trace[0]['function'] !== "__get" |
| 30 |
) { |
| 31 |
array_shift( $trace ); |
| 32 |
} |
| 33 |
trigger_error( |
| 34 |
'Undefined property' . |
| 35 |
' via ' . ( $trace[0]['function'] ?? '' ) . '(): ' . $prop . |
| 36 |
' in ' . ( $trace[0]['file'] ?? '' ) . |
| 37 |
' on line ' . ( $trace[0]['line'] ?? '' ), |
| 38 |
E_USER_NOTICE |
| 39 |
); |
| 40 |
return null; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Handle an attempt to set a non-existing property on this |
| 45 |
* object. The default implementation raises an exception |
| 46 |
* but the implementor can choose a different behavior: |
| 47 |
* ignore the operation (like JavaScript), dynamically create |
| 48 |
* the property, etc. |
| 49 |
* @param string $prop the name of the property requested |
| 50 |
* @param mixed $value the value to set |
| 51 |
*/ |
| 52 |
protected function _setMissingProp( string $prop, $value ): void { |
| 53 |
$trace = debug_backtrace(); |
| 54 |
while ( |
| 55 |
count( $trace ) > 0 && |
| 56 |
$trace[0]['function'] !== "__set" |
| 57 |
) { |
| 58 |
array_shift( $trace ); |
| 59 |
} |
| 60 |
trigger_error( |
| 61 |
'Undefined property' . |
| 62 |
' via ' . ( $trace[0]['function'] ?? '' ) . '(): ' . $prop . |
| 63 |
' in ' . ( $trace[0]['file'] ?? '' ) . |
| 64 |
' on line ' . ( $trace[0]['line'] ?? '' ), |
| 65 |
E_USER_NOTICE |
| 66 |
); |
| 67 |
} |
| 68 |
|
| 69 |
// phpcs:enable |
| 70 |
|
| 71 |
/** |
| 72 |
* @param string $name |
| 73 |
* @return mixed |
| 74 |
*/ |
| 75 |
public function __get( string $name ) { |
| 76 |
'@phan-var \Wikimedia\IDLeDOM\NodeList $this'; |
| 77 |
// @var \Wikimedia\IDLeDOM\NodeList $this |
| 78 |
switch ( $name ) { |
| 79 |
case "length": |
| 80 |
return $this->getLength(); |
| 81 |
default: |
| 82 |
break; |
| 83 |
} |
| 84 |
'@phan-var \Wikimedia\IDLeDOM\Helper\NodeList $this'; |
| 85 |
// @var \Wikimedia\IDLeDOM\Helper\NodeList $this |
| 86 |
return $this->_getMissingProp( $name ); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* @param string $name |
| 91 |
* @return bool |
| 92 |
*/ |
| 93 |
public function __isset( string $name ): bool { |
| 94 |
'@phan-var \Wikimedia\IDLeDOM\NodeList $this'; |
| 95 |
// @var \Wikimedia\IDLeDOM\NodeList $this |
| 96 |
switch ( $name ) { |
| 97 |
case "length": |
| 98 |
return true; |
| 99 |
default: |
| 100 |
break; |
| 101 |
} |
| 102 |
return false; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* @return int |
| 107 |
*/ |
| 108 |
public function count(): int { |
| 109 |
'@phan-var \Wikimedia\IDLeDOM\NodeList $this'; |
| 110 |
// @var \Wikimedia\IDLeDOM\NodeList $this |
| 111 |
return $this->getLength(); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* @param mixed $offset |
| 116 |
* @return bool |
| 117 |
*/ |
| 118 |
public function offsetExists( $offset ): bool { |
| 119 |
return $this->offsetGet( $offset ) !== null; |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* @param mixed $offset |
| 124 |
* @return mixed |
| 125 |
*/ |
| 126 |
#[\ReturnTypeWillChange] |
| 127 |
public function offsetGet( $offset ) { |
| 128 |
'@phan-var \Wikimedia\IDLeDOM\NodeList $this'; |
| 129 |
// @var \Wikimedia\IDLeDOM\NodeList $this |
| 130 |
if ( is_numeric( $offset ) ) { |
| 131 |
return $this->item( $offset ); |
| 132 |
} elseif ( is_string( $offset ) ) { |
| 133 |
/* Fall through */ |
| 134 |
} |
| 135 |
$trace = debug_backtrace(); |
| 136 |
while ( |
| 137 |
count( $trace ) > 0 && |
| 138 |
$trace[0]['function'] !== "offsetGet" && |
| 139 |
$trace[0]['function'] !== "offsetExists" |
| 140 |
) { |
| 141 |
array_shift( $trace ); |
| 142 |
} |
| 143 |
while ( |
| 144 |
count( $trace ) > 1 && ( |
| 145 |
$trace[1]['function'] === "offsetGet" || |
| 146 |
$trace[1]['function'] === "offsetExists" |
| 147 |
) ) { |
| 148 |
array_shift( $trace ); |
| 149 |
} |
| 150 |
trigger_error( |
| 151 |
'Undefined property' . |
| 152 |
' via ' . ( $trace[0]['function'] ?? '' ) . '(): ' . $offset . |
| 153 |
' in ' . ( $trace[0]['file'] ?? '' ) . |
| 154 |
' on line ' . ( $trace[0]['line'] ?? '' ), |
| 155 |
E_USER_NOTICE |
| 156 |
); |
| 157 |
return null; |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* @param mixed $offset |
| 162 |
* @param mixed $value |
| 163 |
*/ |
| 164 |
public function offsetSet( $offset, $value ): void { |
| 165 |
'@phan-var \Wikimedia\IDLeDOM\NodeList $this'; |
| 166 |
// @var \Wikimedia\IDLeDOM\NodeList $this |
| 167 |
if ( is_numeric( $offset ) ) { |
| 168 |
/* Fall through */ |
| 169 |
} elseif ( is_string( $offset ) ) { |
| 170 |
/* Fall through */ |
| 171 |
} |
| 172 |
$trace = debug_backtrace(); |
| 173 |
while ( |
| 174 |
count( $trace ) > 0 && |
| 175 |
$trace[0]['function'] !== "offsetSet" |
| 176 |
) { |
| 177 |
array_shift( $trace ); |
| 178 |
} |
| 179 |
trigger_error( |
| 180 |
'Undefined property' . |
| 181 |
' via ' . ( $trace[0]['function'] ?? '' ) . '(): ' . $offset . |
| 182 |
' in ' . ( $trace[0]['file'] ?? '' ) . |
| 183 |
' on line ' . ( $trace[0]['line'] ?? '' ), |
| 184 |
E_USER_NOTICE |
| 185 |
); |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* @param mixed $offset |
| 190 |
*/ |
| 191 |
public function offsetUnset( $offset ): void { |
| 192 |
'@phan-var \Wikimedia\IDLeDOM\NodeList $this'; |
| 193 |
// @var \Wikimedia\IDLeDOM\NodeList $this |
| 194 |
if ( is_numeric( $offset ) ) { |
| 195 |
/* Fall through */ |
| 196 |
} elseif ( is_string( $offset ) ) { |
| 197 |
/* Fall through */ |
| 198 |
} |
| 199 |
$trace = debug_backtrace(); |
| 200 |
while ( |
| 201 |
count( $trace ) > 0 && |
| 202 |
$trace[0]['function'] !== "offsetUnset" |
| 203 |
) { |
| 204 |
array_shift( $trace ); |
| 205 |
} |
| 206 |
trigger_error( |
| 207 |
'Undefined property' . |
| 208 |
' via ' . ( $trace[0]['function'] ?? '' ) . '(): ' . $offset . |
| 209 |
' in ' . ( $trace[0]['file'] ?? '' ) . |
| 210 |
' on line ' . ( $trace[0]['line'] ?? '' ), |
| 211 |
E_USER_NOTICE |
| 212 |
); |
| 213 |
} |
| 214 |
|
| 215 |
/** |
| 216 |
* @return \Iterator<Node> Value iterator returning Node items |
| 217 |
*/ |
| 218 |
public function getIterator(): \Iterator { |
| 219 |
'@phan-var \Wikimedia\IDLeDOM\NodeList $this'; |
| 220 |
// @var \Wikimedia\IDLeDOM\NodeList $this |
| 221 |
for ( $i = 0; $i < $this->getLength(); $i++ ) { |
| 222 |
yield $this->item( $i ); |
| 223 |
} |
| 224 |
} |
| 225 |
|
| 226 |
} |