ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
trait.ilObjFileSecureString.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\ResourceStorage\Preloader\SecureString;
20
26{
27 use SecureString;
28
29 protected function extractSuffixFromFilename(string $filename): string
30 {
31 if (!preg_match('/^(.+?)(?<!\s)\.([^.]*$|$)/', $filename, $matches)) {
32 return '';
33 }
34 return $this->secure($matches[2]);
35 }
36
37 protected function stripSuffix(string $title, ?string $suffix = null): string
38 {
39 $suffix ??= $this->extractSuffixFromFilename($title);
40
41 if ($suffix !== null && ($length = strrpos($title, "." . $suffix)) > 0) {
42 $title = substr($title, 0, $length);
43 }
44
45 return $this->secure($title);
46 }
47
48 protected function ensureSuffix(string $title, ?string $suffix = null): string
49 {
50 $title = $this->stripSuffix($title, $suffix);
51 $suffix ??= $this->extractSuffixFromFilename($title);
52
53 if ($suffix !== null && strrpos((string) $title, "." . $suffix) === false) {
54 $title .= "." . $suffix;
55 }
56
57 return $this->secure(rtrim((string) $title, "."));
58 }
59
60 protected function ensureSuffixInBrackets(string $title, ?string $suffix = null): string
61 {
62 $title = $this->stripSuffix($title, $suffix);
63 $suffix ??= $this->extractSuffixFromFilename($title);
64
65 if ($suffix !== null && strrpos((string) $title, "." . $suffix) === false) {
66 $title .= " (" . $suffix . ")";
67 }
68
69 return $this->secure($title);
70 }
71}
$filename
Definition: buildRTE.php:78
ensureSuffixInBrackets(string $title, ?string $suffix=null)
trait ilObjFileSecureString
Trait ilObjFileSecureString.
stripSuffix(string $title, ?string $suffix=null)
ensureSuffix(string $title, ?string $suffix=null)
extractSuffixFromFilename(string $filename)