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