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