1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
BaseCollection.php
См. документацию.
1
<?php
2
3
declare(strict_types=1);
4
5
namespace
Bitrix\Rest\Entity\Collection;
6
7
use Bitrix\Main\ArgumentException;
8
use Closure;
9
use Countable;
10
use IteratorAggregate;
11
use Traversable;
12
17
abstract
class
BaseCollection
implements
Countable, IteratorAggregate
18
{
22
private
array
$items = [];
23
28
public
function
__construct
(mixed ...$items)
29
{
30
foreach
($items as $item)
31
{
32
$this->
add
($item);
33
}
34
}
35
39
abstract
protected
static
function
getItemClassName
(): string;
40
45
public
function
add
(mixed $item): void
46
{
47
if
(!$this->isValidType($item))
48
{
49
$type
= static::getItemClassName();
50
throw
new
ArgumentException
(
"Item must be of type {$type}"
);
51
}
52
53
$this->items[] = $item;
54
}
55
59
public
function
get
(
int
$index): mixed
60
{
61
return
$this->items[$index] ??
null
;
62
}
63
67
public
function
first
(): mixed
68
{
69
return
$this->
get
(0);
70
}
71
75
public
function
all
():
array
76
{
77
return
$this->items
;
78
}
79
80
public
function
remove
(
int
$index): void
81
{
82
if
(isset($this->items[$index]))
83
{
84
unset($this->items[$index]);
85
$this->items = array_values($this->items);
86
}
87
}
88
89
public
function
count
(): int
90
{
91
return
count
($this->items);
92
}
93
94
public
function
isEmpty
(): bool
95
{
96
return
$this->
count
() === 0;
97
}
98
102
public
function
getIterator
(): Traversable
103
{
104
return
new \ArrayIterator($this->items);
105
}
106
111
public
function
contains
(mixed $item): bool
112
{
113
return
in_array($item, $this->items,
true
);
114
}
115
116
public
function
clear
(): void
117
{
118
$this->items = [];
119
}
120
126
public
function
filter
(Closure $callback): self
127
{
128
$filtered = array_filter($this->items, $callback);
129
$collection =
new
static
();
130
131
foreach
($filtered as $item)
132
{
133
$collection->add($item);
134
}
135
136
return
$collection;
137
}
138
144
public
function
map
(Closure $callback):
array
145
{
146
return
array_map($callback, $this->items);
147
}
148
149
public
function
__clone
(): void
150
{
151
$this->items = $this->
map
(
static
fn($item) => clone $item);
152
}
153
158
private
function
isValidType(mixed $item): bool
159
{
160
return
$item instanceof (static::getItemClassName());
161
}
162
}
$type
$type
Определения
options.php:106
Bitrix\Main\ArgumentException
Определения
ArgumentException.php:9
Bitrix\Rest\Entity\Collection\BaseCollection
Определения
BaseCollection.php:18
Bitrix\Rest\Entity\Collection\BaseCollection\contains
contains(mixed $item)
Определения
BaseCollection.php:111
Bitrix\Rest\Entity\Collection\BaseCollection\add
add(mixed $item)
Определения
BaseCollection.php:45
Bitrix\Rest\Entity\Collection\BaseCollection\getIterator
getIterator()
Определения
BaseCollection.php:102
Bitrix\Rest\Entity\Collection\BaseCollection\__construct
__construct(mixed ... $items)
Определения
BaseCollection.php:28
Bitrix\Rest\Entity\Collection\BaseCollection\getItemClassName
static getItemClassName()
Bitrix\Rest\Entity\Collection\BaseCollection\clear
clear()
Определения
BaseCollection.php:116
Bitrix\Rest\Entity\Collection\BaseCollection\first
first()
Определения
BaseCollection.php:67
Bitrix\Rest\Entity\Collection\BaseCollection\count
count()
Определения
BaseCollection.php:89
Bitrix\Rest\Entity\Collection\BaseCollection\map
map(Closure $callback)
Определения
BaseCollection.php:144
Bitrix\Rest\Entity\Collection\BaseCollection\__clone
__clone()
Определения
BaseCollection.php:149
Bitrix\Rest\Entity\Collection\BaseCollection\isEmpty
isEmpty()
Определения
BaseCollection.php:94
Bitrix\Rest\Entity\Collection\BaseCollection\filter
filter(Closure $callback)
Определения
BaseCollection.php:126
Bitrix\Rest\Entity\Collection\BaseCollection\all
all()
Определения
BaseCollection.php:75
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$items
$items
Определения
template.php:224
bitrix
modules
rest
lib
Entity
Collection
BaseCollection.php
Создано системой
1.14.0