ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Factory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\Data\Meta\Html\Tag as HTMLTag;
27use DateTimeImmutable;
28
33{
34 public function audio(URI $audio_url, string $mime_type): Audio
35 {
36 return new Audio($audio_url, $mime_type);
37 }
38
39 public function image(
40 URI $image_url,
41 string $mime_type,
42 ?string $aria_label = null,
43 ?int $width = null,
44 ?int $height = null,
45 ): Image {
46 return new Image($image_url, $mime_type, $aria_label, $width, $height);
47 }
48
49 public function video(
50 URI $video_url,
51 string $mime_type,
52 ?int $width = null,
53 ?int $height = null,
54 ): Video {
55 return new Video($video_url, $mime_type, $width, $height);
56 }
57
63 public function website(
64 URI $canonical_url,
65 Image $image,
66 string $object_title,
67 ?string $website_name = null,
68 ?string $description = null,
69 ?string $default_locale = null,
70 array $alternative_locales = [],
71 array $additional_resources = [],
72 ): TagCollection {
74 new Text('og:type', 'website'),
75 new Text('og:title', $object_title),
76 new Link('og:url', $canonical_url),
77 $image,
78 (null !== $website_name) ? new Text('og:site_title', $website_name) : new NullTag(),
79 (null !== $description) ? new Text('og:description', $description) : new NullTag(),
80 (null !== $default_locale) ? new Text('og:locale', $default_locale) : new NullTag(),
81 $this->getAlternativeLocalesTag($alternative_locales),
82 ($this->checkAdditionalResources($additional_resources)) ? new TagCollection(
83 ...$additional_resources
84 ) : new NullTag(),
85 );
86 }
87
91 protected function getAlternativeLocalesTag(array $locales): HTMLTag
92 {
93 if (empty($locales)) {
94 return new NullTag();
95 }
96
97 $alternative_language_tags = [];
98 foreach ($locales as $locale) {
99 $alternative_language_tags[] = new Text('og:locale:alternative', $locale);
100 }
101
102 return new TagCollection(...$alternative_language_tags);
103 }
104
105 protected function checkAdditionalResources(array $resources): bool
106 {
107 foreach ($resources as $resource) {
108 if (!$resource instanceof Resource) {
109 throw new \LogicException(
110 sprintf(
111 "Expected array of %s but received %s.",
112 Resource::class,
113 get_class($resource)
114 )
115 );
116 }
117 }
118
119 return true;
120 }
121}
image(URI $image_url, string $mime_type, ?string $aria_label=null, ?int $width=null, ?int $height=null,)
Definition: Factory.php:39
getAlternativeLocalesTag(array $locales)
Definition: Factory.php:91
audio(URI $audio_url, string $mime_type)
Definition: Factory.php:34
video(URI $video_url, string $mime_type, ?int $width=null, ?int $height=null,)
Definition: Factory.php:49
website(URI $canonical_url, Image $image, string $object_title, ?string $website_name=null, ?string $description=null, ?string $default_locale=null, array $alternative_locales=[], array $additional_resources=[],)
Definition: Factory.php:63
checkAdditionalResources(array $resources)
Definition: Factory.php:105
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$resources
Definition: ltiservices.php:68