ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
IconAbstractRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\File\Icon;
22
24
29{
31
32 public function __construct()
33 {
34 global $DIC;
35 $this->refinery = $DIC->refinery();
36 }
37
38 final public function turnSuffixesArrayIntoString(array $a_suffixes): string
39 {
40 return implode(", ", $a_suffixes);
41 }
42
46 final public function turnSuffixesStringIntoArray(string $a_suffixes): array
47 {
48 $a_suffixes = preg_replace('/\s+/', '', $a_suffixes);
49 return explode(",", (string) $a_suffixes);
50 }
51
52 final public function hasSuffixInputOnlyAllowedCharacters(array $a_suffixes): bool
53 {
54 $suffixes_string = $this->turnSuffixesArrayIntoString($a_suffixes);
55 $matches = preg_match("/^[a-zA-Z0-9\,\s]+$/", $suffixes_string);
56 return $this->refinery->kindlyTo()->bool()->transform($matches);
57 }
58
59 final public function hasSuffixInputNoDuplicatesToItsOwnEntries(array $a_suffixes): bool
60 {
61 return count($a_suffixes) === count(array_unique($a_suffixes));
62 }
63
64 final public function causesNoActiveSuffixesConflict(
65 array $a_future_suffixes,
66 bool $a_future_activation_state,
67 Icon $a_current_icon
68 ): bool {
69 //if the icon is not going to be activated there can be no suffix conflict with other icons
70 if (!$a_future_activation_state) {
71 return true;
72 }
73
74 $existing_icons = $this->getIcons();
75 //remove current icon from existing icon array to prevent validation errors when updating an existing icon
76 if (!$a_current_icon instanceof NullIcon) {
77 unset($existing_icons[$a_current_icon->getRid()]);
78 }
79
80 $duplicate_suffixes = [];
81 foreach ($existing_icons as $existing_icon) {
82 //skip deactivated icons as having multiple icon entries for the same suffix is allowed, the restriction is that only one can be activated
83 if (!$existing_icon->isActive()) {
84 continue;
85 }
86 $duplicate_suffixes = array_merge(
87 $duplicate_suffixes,
88 array_intersect($a_future_suffixes, $existing_icon->getSuffixes())
89 );
90 }
91
92 return $duplicate_suffixes === [];
93 }
94}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
causesNoActiveSuffixesConflict(array $a_future_suffixes, bool $a_future_activation_state, Icon $a_current_icon)
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26