ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
AbstractMediaWithPath.php
Go to the documentation of this file.
2
7abstract class AbstractMediaWithPath extends AbstractMedia
8{
9 public function getContent() : string
10 {
11 $content = parent::getContent();
12
13 // the version string is only appended if the content string is not
14 // a data uri, otherwise the data uri will behave incorrectly.
15 if (!$this->isContentDataUri($content)) {
16 if ($this->hasContentParameters($content)) {
17 return rtrim($content, "&") . "&version=" . $this->version;
18 } else {
19 return rtrim($content, "?") . "?version=" . $this->version;
20 }
21 }
22
23 return $content;
24 }
25
26 protected function isContentDataUri(string $content) : bool
27 {
28 // regex pattern matches if a string follows the data uri syntax.
29 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs#syntax
30
31 return (bool) preg_match('/^(data:)([a-z\/]*)((;base64)?)(,?)([A-z0-9=]*)$/', $content);
32 }
33
34 protected function hasContentParameters(string $content) : bool
35 {
36 return (strpos($content, "?") !== false);
37 }
38}
An exception for terminatinating execution or to throw for unit testing.