1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
resourcecollection.php
См. документацию.
1<?php
2
3namespace Bitrix\Landing\Assets;
4
5
13{
14 protected const KEY_PATH = 'path';
15 protected const KEY_TYPE = 'type';
16 protected const KEY_LOCATION = 'location';
17 protected const KEY_ORDER = 'order';
18
23 protected array $resources;
28 protected int $order;
33 protected array $strings = [];
34
38 public function __construct()
39 {
40 $this->resources = [];
41 $this->order = 0;
42 }
43
49 public function add(string $path, string $type, int $location): void
50 {
51 // overwrite only if new location more
52 if (
53 $this->isResourceAdded($path)
54 && !$this->isNeedRaiseLocation($path, $location)
55 )
56 {
57 return;
58 }
59
60 $this->resources[$path] = [
61 self::KEY_PATH => $path,
62 self::KEY_TYPE => $type,
63 self::KEY_LOCATION => $location,
64 self::KEY_ORDER => $this->order++,
65 ];
66 }
67
68 protected function isResourceAdded(string $path): bool
69 {
70 return array_key_exists($path, $this->resources);
71 }
72
73 protected function isNeedRaiseLocation(string $path, int $location): bool
74 {
75 return $location < $this->resources[$path][self::KEY_LOCATION];
76 }
77
82 public function addString(string $string): void
83 {
84 if ($string && !in_array($string, $this->strings, true))
85 {
86 $this->strings[] = $string;
87 }
88 }
89
94 public function getStrings(): array
95 {
96 return $this->strings;
97 }
98
103 public function remove(array|string $pathes): void
104 {
105 if (!is_array($pathes))
106 {
107 $pathes = [$pathes];
108 }
109
110 foreach ($pathes as $path)
111 {
112 $this->removeOnce($path);
113 }
114 }
115
116 protected function removeOnce(string $path): void
117 {
118 if ($this->isResourceAdded($path))
119 {
120 unset($this->resources[$path]);
121 }
122 }
123
130 {
131 return $this->getSliceByFilter(self::KEY_LOCATION, $location);
132 }
133
141 protected function getSliceByFilter($field, $value): ResourceCollection
142 {
143 $resourcesByFilter = new self();
144
145 foreach ($this->resources as $resource)
146 {
147 if (array_key_exists($field, $resource) && $resource[$field] === $value)
148 {
149 $resourcesByFilter->add(
150 $resource[self::KEY_PATH],
151 $resource[self::KEY_TYPE],
152 $resource[self::KEY_LOCATION]
153 );
154 }
155 }
156
157 return $resourcesByFilter;
158 }
159
164 public function getPathes(): array
165 {
166 return array_keys($this->resources);
167 }
168
173 public function getNormalized(): array
174 {
175 $this->sortByLocation();
176 $normalizedResources = [];
177
178 foreach ($this->resources as $resource)
179 {
180 if (!array_key_exists($resource[self::KEY_TYPE], $normalizedResources))
181 {
182 $normalizedResources[$resource[self::KEY_TYPE]] = [];
183 }
184 $normalizedResources[$resource[self::KEY_TYPE]][] = $resource[self::KEY_PATH];
185 }
186
187 return $normalizedResources;
188 }
189
190 protected function sortByLocation(): void
191 {
192 $columnLocation = array_column($this->resources, self::KEY_LOCATION);
193 $columnOrder = array_column($this->resources, self::KEY_ORDER);
194 array_multisort($columnLocation, $columnOrder, $this->resources);
195 }
196
201 public function isEmpty(): bool
202 {
203 return (count($this->resources) === 0) && (count($this->strings) === 0);
204 }
205}
$path
Определения access_edit.php:21
$type
Определения options.php:106
add(string $path, string $type, int $location)
Определения resourcecollection.php:49
isNeedRaiseLocation(string $path, int $location)
Определения resourcecollection.php:73
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$location
Определения options.php:2729