1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
EntityCollection.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
5namespace Bitrix\Main\Entity;
6
7use Bitrix\Main\ArgumentTypeException;
8
10{
11 protected array $items = [];
12
14 {
15 foreach ($items as $item)
16 {
17 $this->add($item);
18 }
19 }
20
21 public function count(): int
22 {
23 return count($this->items);
24 }
25
26 public function isEmpty(): bool
27 {
28 return empty($this->items);
29 }
30
31 public function getIterator(): \ArrayIterator
32 {
33 return new \ArrayIterator($this->items);
34 }
35
39 public function add(EntityInterface $item): void
40 {
41 if (!is_a($item, static::getEntityClass()))
42 {
43 throw new ArgumentTypeException('item', static::getEntityClass());
44 }
45
46 $this->items[] = $item;
47 }
48
49 public function find(callable $callback): ?EntityInterface
50 {
51 // On PHP 8.4 replace to
52 // return array_find($this->items, $callback);
53
54 foreach ($this->items as $key => $item)
55 {
56 if ($callback($item, $key))
57 {
58 return $item;
59 }
60 }
61
62 return null;
63 }
64
65 public function filter(callable $callback): static
66 {
67 return new static(...array_filter($this->items, $callback));
68 }
69
73 public function map(callable $callback): array
74 {
75 return array_map($callback, $this->items);
76 }
77
81 protected static function getEntityClass(): string
82 {
83 return EntityInterface::class;
84 }
85}
__construct(EntityInterface ... $items)
Определения EntityCollection.php:13
add(EntityInterface $item)
Определения EntityCollection.php:39
filter(callable $callback)
Определения EntityCollection.php:65
map(callable $callback)
Определения EntityCollection.php:73
find(callable $callback)
Определения EntityCollection.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(empty($signedUserToken)) $key
Определения quickway.php:257