Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
attachcollection.php
1<?php
2
3
5
6
7use Bitrix\Calendar\SerializeObject;
8use ArrayIterator;
9use IteratorAggregate;
10use LogicException;
11use Serializable;
12
13class AttachCollection implements IteratorAggregate, Serializable
14{
15 use SerializeObject;
19 private $collection;
20
25 public static function createInstance(array $collection = []): AttachCollection
26 {
27 return new self($collection);
28 }
29
34 public function __construct(array $collection = [])
35 {
36 if (!$this->checkCollection($collection))
37 {
38 throw new LogicException('The collection contains elements of the wrong class. You need to pass a collection of objects Bitrix\\Calendar\\ICal\\Parser\\Attendee');
39 }
40 $this->collection = $collection;
41 }
42
47 public function add(Attach $attach): AttachCollection
48 {
49 $this->collection[] = $attach;
50
51 return $this;
52 }
53
57 public function getCollection(): array
58 {
59 return $this->collection;
60 }
61
65 public function getIterator(): ArrayIterator
66 {
67 return new ArrayIterator($this->collection);
68 }
69
70 public function getCount(): int
71 {
72 return count($this->collection);
73 }
78 private function checkCollection(array $collection): bool
79 {
80 if (is_null($collection))
81 {
82 return true;
83 }
84
85 $attach = array_filter($collection, function ($attach) {
86 return !($attach instanceof Attach);
87 });
88
89 return empty($attach);
90 }
91}