ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
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['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...