ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
StartUpStep.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\LegalDocuments;
22 
30 use ilCtrl;
33 use Closure;
34 use ilRepositoryGUI;
35 
37 {
39  private readonly array $all;
40  private readonly Intercept $current;
41 
42  public function __construct(private readonly ilCtrl $ctrl, Conductor $legal_documents)
43  {
44  $this->all = $legal_documents->intercepting();
45  $this->current = new LazyIntercept($this->findCurrent(...));
46  }
47 
48  public function shouldStoreRequestTarget(): bool
49  {
50  return true;
51  }
52 
53  public function shouldInterceptRequest(): bool
54  {
55  return $this->current->intercept();
56  }
57 
58  public function execute(): void
59  {
60  $target = $this->current->target();
61  $this->ctrl->setParameterByClass($target->guiName(), 'id', $this->current->id());
62  $this->ctrl->redirectToURL($this->ctrl->getLinkTargetByClass($target->guiPath(), $target->command()));
63  }
64 
65  public function isInFulfillment(): bool
66  {
67  return in_array(
68  strtolower($this->ctrl->getCmdClass()),
69  $this->allInterceptingPaths(),
70  true
71  );
72  }
73 
77  private function allInterceptingPaths(): array
78  {
79  return array_map(
80  fn($intercept) => strtolower($intercept->target()->guiName()),
81  array_filter($this->all, fn($i) => $i->intercept())
82  );
83  }
84 
85  private function findCurrent()
86  {
87  return $this->find(
88  fn($x) => $x->intercept(),
90  )->except(
91  fn() => new Ok(new NullIntercept())
92  )->value();
93  }
94 
95  private function find($predicate, $array)
96  {
97  foreach ($array as $x) {
98  if ($predicate($x)) {
99  return new Ok($x);
100  }
101  }
102  return new Error('Not found.');
103  }
104 }
__construct(private readonly ilCtrl $ctrl, Conductor $legal_documents)
Definition: StartUpStep.php:42
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:16