Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
config.php
1<?php
2
4
10final class Config implements \IteratorAggregate
11{
13 private $items = [];
14
19 public function addItem(ConfigItem $item)
20 {
21 $this->items[] = $item;
22
23 return $this;
24 }
25
30 public function getItem(string $code): ?ConfigItem
31 {
32 foreach ($this->items as $item)
33 {
34 if ($item->getCode() !== $code)
35 {
36 continue;
37 }
38
39 return $item;
40 }
41
42 return null;
43 }
44
49 public function getValue(string $code)
50 {
51 $item = $this->getItem($code);
52 if (!$item)
53 {
54 return null;
55 }
56
57 return $item->getValue();
58 }
59
65 public function setValue(string $code, $value): bool
66 {
67 foreach ($this->items as $item)
68 {
69 if ($item->getCode() !== $code)
70 {
71 continue;
72 }
73
74 $item->setValue($value);
75
76 return true;
77 }
78
79 return false;
80 }
81
85 public function getIterator(): \Traversable
86 {
87 usort(
88 $this->items,
89 function (ConfigItem $item1, ConfigItem $item2)
90 {
91 if ($item1->getSort() == $item2->getSort())
92 {
93 return 0;
94 }
95
96 return ($item1->getSort() < $item2->getSort()) ? -1 : 1;
97 }
98 );
99
100 return new \ArrayIterator($this->items);
101 }
102}
setValue(string $code, $value)
Definition config.php:65