Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
package.php
1<?php
2
4
11{
13 protected $list = [];
14 protected $onDemand = false;
15
21 public static function getOrderedTypeList()
22 {
23 return [
28 ];
29 }
30
36 public function __construct(array $assets = [])
37 {
38 foreach ($assets as $asset)
39 {
40 $this->addAsset($asset);
41 }
42 }
43
50 public function addAsset(Asset $item)
51 {
52 $this->list[] = $item;
53 return $this;
54 }
55
62 public function getAssets($type = null)
63 {
64 if ($type)
65 {
66 $list = [];
67 foreach ($this->list as $asset)
68 {
69 if ($asset->getType() !== $type)
70 {
71 continue;
72 }
73
74 $list[] = $asset;
75 }
76
77 return $list;
78 }
79
80 return $this->list;
81 }
82
89 public function onDemand()
90 {
91 $this->onDemand = true;
92 return $this;
93 }
94
100 public function isOnDemand()
101 {
102 return $this->onDemand;
103 }
104
111 public function toArray($type = null)
112 {
113 $result = [];
114 foreach ($this->list as $asset)
115 {
116 if ($type && $asset->getType() != $type)
117 {
118 continue;
119 }
120
121 $path = $asset->getUri();
122 if ($this->onDemand && !$path)
123 {
124 continue;
125 }
126
127 $content = $asset->getContent();
128 if (!$this->onDemand && !$content)
129 {
130 continue;
131 }
132
133 $result[] = [
134 'type' => $asset->getType(),
135 'path' => $path,
136 'content' => $content,
137 'cache' => true,
138 ];
139 }
140
141 return $result;
142 }
143}