ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
HelpScreenIdObserver.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
26
27 private const SCREEN_SEPARATOR = '/';
28 private const COMMAND_SEPARATOR = '/';
29 private array $map;
30 protected array $clean_name_stack = [];
31 protected ?string $command = null;
32
33 public function __construct()
34 {
35 $this->map = [];
36 //$this->map = include \ilHelpBuildScreenIdMapObjective::PATH();
37 }
38
39 public function getId(): string
40 {
41 return self::class;
42 }
43
44 public function update(\ilCtrlEvent $event, ?string $data): void
45 {
46 match ($event) {
47 \ilCtrlEvent::COMMAND_CLASS_FORWARD => $this->addLatestCommandClass($data),
48 \ilCtrlEvent::COMMAND_DETERMINATION => $this->setLatestCommand($data),
49 };
50 }
51
52 public function getScreenId(): string
53 {
54 return implode(
55 self::SCREEN_SEPARATOR,
56 $this->clean_name_stack
57 ) . ($this->command !== null ? self::COMMAND_SEPARATOR . $this->command : '');
58 }
59
60 protected function addLatestCommandClass(?string $class): void
61 {
62 if (null === $class) {
63 return;
64 }
65
66 $clean_class_name = $this->cleanClassName($class);
67 $last_stack_entry = (($stack_size = count($this->clean_name_stack)) > 0) ?
68 $this->clean_name_stack[($stack_size - 1)] :
69 null;
70
71 if ($last_stack_entry !== $clean_class_name) {
72 $this->clean_name_stack[] = $clean_class_name;
73 }
74 }
75
76 protected function setLatestCommand(?string $command): void
77 {
78 if (null !== $command) {
79 $this->command = $this->cleanCommandName($command);
80 }
81 }
82
83 protected function cleanClassName(string $classname): ?string
84 {
85 // check for attributes in artifact
86 if (isset($this->map[$classname])) {
87 return $this->map[$classname];
88 }
89
90 // This is the fallback for classes which do not have a screen id attribute yet.
91 return $this->classNameToScreenId($classname);
92 }
93
94 protected function cleanCommandName(string $command): string
95 {
96 return $this->snakeToCamel($command);
97 }
98}
getId()
Unique identifier of the implementing event-listener.
ilCtrlEvent
classNameToScreenId(string $classname)