ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
CharacterFilter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28
32class CharacterFilter implements Filter
33{
34 public function __construct(
35 private Config $config
36 ) {
37 }
38
39 public function canUserIn(Action $action, Container $in): bool
40 {
41 return true;
42 }
43
44 public function canUserFor(Action $action, Entity $for): bool
45 {
46 return true;
47 }
48
49 public function filterEntity(Entity $entity): bool
50 {
51 return $this->checkName($entity->getName());
52 }
53
54 public function filterProxy(Proxy $proxy): bool
55 {
56 return $this->checkName($proxy->getName());
57 }
58
59 public function checkName(string $name): bool
60 {
61 foreach ($this->config->getInvalidStartCharacters() as $character) {
62 if (str_starts_with($name, (string) $character)) {
63 return false;
64 }
65 }
66 return !preg_match(
67 '/[' . preg_quote(implode('', $this->config->getIncompatibleCharacters()), '/') . ']/',
68 $name
69 );
70 }
71
72 public function canUserCreate(Type $type, Container $in): bool
73 {
74 return true;
75 }
76
77}
canUserFor(Action $action, Entity $for)
canUserIn(Action $action, Container $in)