Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
templatecollection.php
1<?php
2
4
7
8final class TemplateCollection extends Collection
9{
11 protected $items = [];
12
19 public function addItem($template): int
20 {
21 if(!($template instanceof Template))
22 {
23 throw new ArgumentTypeException('field must be the instance of Template');
24 }
25
26 $this->removeTemplateByType($template->getType());
27 return parent::addItem($template);
28 }
29
33 private function removeTemplateByType(string $type): void
34 {
35 foreach ($this->items as $idx => $template)
36 {
37 if($template->getType() === $type)
38 {
39 unset($this->items[$idx]);
40 break;
41 }
42 }
43 }
44
49 public function getTemplate(string $type): ?Template
50 {
51 foreach ($this->items as $template)
52 {
53 if($template->getType() === $type)
54 {
55 return $template;
56 }
57 }
58
59 return null;
60 }
61}