ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
StartUpStep.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\LegalDocuments;
22
29use ilCtrl;
30use Closure;
31
33{
35 private readonly array $all;
36 private readonly Intercept $current;
37
38 public function __construct(private readonly ilCtrl $ctrl, Conductor $legal_documents)
39 {
40 $this->all = $legal_documents->intercepting();
41 $this->current = new LazyIntercept($this->findCurrent(...));
42 }
43
44 public function shouldStoreRequestTarget(): bool
45 {
46 return true;
47 }
48
49 public function shouldInterceptRequest(): bool
50 {
51 return $this->current->intercept();
52 }
53
54 public function execute(): void
55 {
56 $target = $this->current->target();
57 $this->ctrl->setParameterByClass($target->guiName(), 'id', $this->current->id());
58 $this->ctrl->redirectToURL($this->ctrl->getLinkTargetByClass($target->guiPath(), $target->command()));
59 }
60
61 public function isInFulfillment(): bool
62 {
63 return in_array(
64 strtolower($this->ctrl->getCmdClass() ?? ''),
65 $this->allInterceptingPaths(),
66 true
67 );
68 }
69
73 private function allInterceptingPaths(): array
74 {
75 return array_map(
76 fn($intercept) => strtolower($intercept->target()->guiName()),
77 array_filter($this->all, fn($i) => $i->intercept())
78 );
79 }
80
81 private function findCurrent(): Intercept
82 {
83 return $this->find(
84 fn($x) => $x->intercept(),
85 $this->all
86 )->except(
87 fn() => new Ok(new NullIntercept())
88 )->value();
89 }
90
98 private function find(Closure $predicate, array $array): Result
99 {
100 foreach ($array as $x) {
101 if ($predicate($x)) {
102 return new Ok($x);
103 }
104 }
105 return new Error('Not found.');
106 }
107}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
find(Closure $predicate, array $array)
@template A
Definition: StartUpStep.php:98
__construct(private readonly ilCtrl $ctrl, Conductor $legal_documents)
Definition: StartUpStep.php:38
Class ilCtrl provides processing control methods.
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29