ILIAS  release_7 Revision v7.30-3-g800a261c036
AbstractMediaWithPath.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28{
29 public function getContent() : string
30 {
31 $content = parent::getContent();
32
33 // the version string is only appended if the content string is not
34 // a data uri, otherwise the data uri will behave incorrectly.
35 if (!$this->isContentDataUri($content)) {
36 if ($this->hasContentParameters($content)) {
37 return rtrim($content, "&") . "&version=" . $this->version;
38 } else {
39 return rtrim($content, "?") . "?version=" . $this->version;
40 }
41 }
42
43 return $content;
44 }
45
46 protected function isContentDataUri(string $content) : bool
47 {
48 // regex pattern matches if a string follows the data uri syntax.
49 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs#syntax
50
51 return (bool) preg_match('/^(data:)([a-z\/]*)((;base64)?)(,?)([A-z0-9=\/\+]*)$/', $content);
52 }
53
54 protected function hasContentParameters(string $content) : bool
55 {
56 return (strpos($content, "?") !== false);
57 }
58}
An exception for terminatinating execution or to throw for unit testing.