ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
MetaContent.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
38
43{
44 public const MEDIA_SCREEN = "screen";
45
54 private array $meta_data = [];
55 private string $base_url = "";
56 private string $text_direction;
60 private array $version_parameter_filters = [];
61
65 public function __construct(
66 protected string $resource_version,
67 protected bool $append_resource_version = true,
68 protected bool $strip_queries = false,
69 protected bool $allow_external = true,
70 protected bool $allow_non_existing = false,
72 ) {
73 foreach ($version_parameter_filters as $filter) {
74 $this->version_parameter_filters[] = $filter;
75 }
76 $this->reset();
77 }
78
80 {
81 $this->version_parameter_filters[] = $filter;
82 $this->css->addVersionParameterFilter($filter);
83 $this->js->addVersionParameterFilter($filter);
84 }
85
86 public function reset(): void
87 {
88 $this->css = new CssCollection(
89 $this->resource_version,
90 $this->append_resource_version,
91 $this->strip_queries,
92 $this->allow_external,
93 $this->allow_non_existing,
94 $this->version_parameter_filters
95 );
96 $this->js = new JsCollection(
97 $this->resource_version,
98 $this->append_resource_version,
99 $this->strip_queries,
100 $this->allow_external,
101 $this->allow_non_existing,
102 $this->version_parameter_filters
103 );
104 $this->on_load_code = new OnLoadCodeCollection(
105 $this->resource_version,
106 false,
107 true,
108 false,
109 false
110 );
111 $this->inline_css = new InlineCssCollection(
112 $this->resource_version,
113 false,
114 true,
115 false,
116 false
117 );
118 $this->og_meta_data = null;
119 $this->meta_data = [];
120 }
121
122 public function addCss(string $path, string $media = self::MEDIA_SCREEN): void
123 {
124 $this->css->addItem(new Css($path, $this->resource_version, $media));
125 }
126
127 public function addJs(string $path, bool $add_version_number = false, int $batch = 2): void
128 {
129 $this->js->addItem(new Js($path, $this->resource_version, $add_version_number, $batch));
130 }
131
132 public function addInlineCss(string $content, string $media = self::MEDIA_SCREEN): void
133 {
134 $this->inline_css->addItem(new InlineCss($content, $this->resource_version, $media));
135 }
136
137 public function addOnloadCode(string $content, int $batch = 2): void
138 {
139 $this->on_load_code->addItem(new OnLoadCode($content, $this->resource_version, $batch));
140 }
141
143 {
144 $this->og_meta_data = $og_meta_data;
145 }
146
147 public function addMetaDatum(Tag $meta_data): void
148 {
149 if ($meta_data instanceof TagCollection || $meta_data instanceof OpenGraph\Tag) {
150 throw new \LogicException(
151 sprintf(
152 'Please use %s::addOpenGraphMetaDatum to add open-graph metadata.',
153 self::class
154 )
155 );
156 }
157
158 // keep user-defined keys unique, there should be no case where
159 // multiple of the same keys are required.
160 if ($meta_data instanceof UserDefined) {
161 $this->meta_data[$meta_data->getKey()] = $meta_data;
162 } else {
163 $this->meta_data[] = $meta_data;
164 }
165 }
166
168 {
169 return $this->inline_css;
170 }
171
173 {
174 return $this->on_load_code;
175 }
176
177 public function getJs(): JsCollection
178 {
179 return $this->js;
180 }
181
182 public function getCss(): CssCollection
183 {
184 return $this->css;
185 }
186
188 {
189 return $this->og_meta_data;
190 }
191
195 public function getMetaData(): array
196 {
197 return $this->meta_data;
198 }
199
200 public function setBaseURL(string $base_url): void
201 {
202 $this->base_url = $base_url;
203 }
204
205 public function getBaseURL(): string
206 {
207 return $this->base_url;
208 }
209
210 public function getTextDirection(): string
211 {
213 }
214
215 public function setTextDirection(string $text_direction): void
216 {
217 if (!in_array($text_direction, [Standard::LTR, Standard::RTL], true)) {
218 throw new \InvalidArgumentException('$text_direction MUST be Standard::LTR, or Standard::RTL');
219 }
220 $this->text_direction = $text_direction;
221 }
222}
addVersionParameterFilter(VersionParameterFilter $filter)
Definition: MetaContent.php:79
__construct(protected string $resource_version, protected bool $append_resource_version=true, protected bool $strip_queries=false, protected bool $allow_external=true, protected bool $allow_non_existing=false, array $version_parameter_filters=[],)
Definition: MetaContent.php:65
addJs(string $path, bool $add_version_number=false, int $batch=2)
addCss(string $path, string $media=self::MEDIA_SCREEN)
addInlineCss(string $content, string $media=self::MEDIA_SCREEN)
This describes the Page.
Definition: Standard.php:38
$path
Definition: ltiservices.php:30