Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
builder.php
1<?php
2
4
8
9
10abstract class Builder
11{
12 protected const TYPE_STANDART = 'STANDART';
13 protected const TYPE_WEBPACK = 'WEBPACK';
14
15 protected const PACKAGE_NAME = 'landing_assets';
16
20 protected $resources;
24 protected $normalizedResources = [];
29 protected $landingId = 0;
30
37 {
38 if ($resources instanceof ResourceCollection)
39 {
40 $this->resources = $resources;
41 }
42 else
43 {
44 throw new ArgumentTypeException($resources, 'ResourceCollection');
45 }
46 }
47
55 public static function createByType(ResourceCollection $resources, string $type): ?Builder
56 {
57 switch ($type)
58 {
60 return new StandartBuilder($resources);
61
63 return new WebpackBuilder($resources);
64
65 default:
66 throw new ArgumentException("Unknown landing asset builder type `$type`.");
67 }
68 }
69
74 public function attachToLanding(int $lid): void
75 {
76 $this->landingId = (int)$lid;
77 }
78
83 abstract public function setOutput();
84
85 abstract protected function normalizeResources();
86
87 protected function initResourcesAsJsExtension(array $resources, $extName = null): void
88 {
89 if (!$extName)
90 {
91 $extName = self::PACKAGE_NAME;
92 }
93 $extFullName = $extName . '_' . md5(serialize($resources));
94
95 $resources = array_merge($resources, [
96 'bundle_js' => $extFullName,
97 'bundle_css' => $extFullName,
98 'skip_core' => true,
99 ]);
101 \CJSCore::registerExt($extName, $resources);
102 \CJSCore::Init($extName);
103 }
104
108 protected function setStrings(): void
109 {
110 foreach ($this->resources->getStrings() as $string)
111 {
112 Main\Page\Asset::getInstance()->addString($string, false, Main\Page\AssetLocation::AFTER_JS);
113 }
114 }
115}
__construct(ResourceCollection $resources)
Definition builder.php:36
initResourcesAsJsExtension(array $resources, $extName=null)
Definition builder.php:87
static createByType(ResourceCollection $resources, string $type)
Definition builder.php:55