Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 399
Zeile 18... Zeile 18...
18
 */
18
 */
19
class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
19
class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
20
{
20
{
21
	use Nette\SmartObject;
21
	use Nette\SmartObject;
Zeile 22... Zeile -...
22
 
-
 
23
	/** @var mixed[] */
22
 
Zeile 24... Zeile 23...
24
	private $list = [];
23
	private array $list = [];
25
 
24
 
26
 
25
 
27
	/**
-
 
28
	 * Transforms array to ArrayList.
26
	/**
29
	 * @param  array<T>  $array
27
	 * Transforms array to ArrayList.
30
	 * @return static
28
	 * @param  array<T>  $array
31
	 */
29
	 */
32
	public static function from(array $array)
30
	public static function from(array $array): static
33
	{
31
	{
Zeile 41... Zeile 39...
41
	}
39
	}
Zeile 42... Zeile 40...
42
 
40
 
43
 
41
 
44
	/**
42
	/**
45
	 * Returns an iterator over all items.
43
	 * Returns an iterator over all items.
46
	 * @return \ArrayIterator<int, T>
44
	 * @return \Iterator<int, T>
47
	 */
45
	 */
48
	public function getIterator(): \ArrayIterator
46
	public function &getIterator(): \Iterator
-
 
47
	{
-
 
48
		foreach ($this->list as &$item) {
49
	{
49
			yield $item;
Zeile 50... Zeile 50...
50
		return new \ArrayIterator($this->list);
50
		}
51
	}
51
	}
Zeile 84... Zeile 84...
84
	 * Returns a item.
84
	 * Returns a item.
85
	 * @param  int  $index
85
	 * @param  int  $index
86
	 * @return T
86
	 * @return T
87
	 * @throws Nette\OutOfRangeException
87
	 * @throws Nette\OutOfRangeException
88
	 */
88
	 */
89
	#[\ReturnTypeWillChange]
-
 
90
	public function offsetGet($index)
89
	public function offsetGet($index): mixed
91
	{
90
	{
92
		if (!is_int($index) || $index < 0 || $index >= count($this->list)) {
91
		if (!is_int($index) || $index < 0 || $index >= count($this->list)) {
93
			throw new Nette\OutOfRangeException('Offset invalid or out of range');
92
			throw new Nette\OutOfRangeException('Offset invalid or out of range');
94
		}
93
		}
Zeile 124... Zeile 123...
124
 
123
 
125
	/**
124
	/**
126
	 * Prepends a item.
125
	 * Prepends a item.
127
	 * @param  T  $value
126
	 * @param  T  $value
128
	 */
127
	 */
129
	public function prepend($value): void
128
	public function prepend(mixed $value): void
130
	{
129
	{
131
		$first = array_slice($this->list, 0, 1);
130
		$first = array_slice($this->list, 0, 1);
132
		$this->offsetSet(0, $value);
131
		$this->offsetSet(0, $value);
133
		array_splice($this->list, 1, 0, $first);
132
		array_splice($this->list, 1, 0, $first);