ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
Flow.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
31class Flow
32{
33 public function __construct(
34 private Services $http,
35 private \ilCtrlInterface $ctrl
36 ) {
37 }
38
39 public function ctrl(): \ilCtrlInterface
40 {
41 return $this->ctrl;
42 }
43
44 public function redirect(string $command, ?string $target_class = null): never
45 {
46 $target_class ??= $this->getCurrentClass();
47
48 $this->ctrl->redirectByClass($target_class, $command);
49 }
50
51 public function getHereAsFlow(): array
52 {
53 $call_history = $this->ctrl->getCallHistory();
54 return array_map(static fn(array $c): string => $c['cmdClass'], $call_history);
55 }
56
57 public function getParentAsURI(?string $cmd = null): URI
58 {
59 $this->ctrl->getCallHistory();
60 $command_classes = $this->getHereAsFlow();
61 // remove the last class
62 array_pop($command_classes);
63
64 return $this->getTargetURI($command_classes, $cmd);
65 }
66
67 public function getHereAsURI(?string $cmd = null): URI
68 {
69 $uri = new URI((string) $this->http->request()->getUri());
70 if ($cmd !== null) {
71 return $uri->withParameter('cmd', $cmd);
72 }
73 return $uri;
74 }
75
76 public function getTranslationAsURI(?string $command = null): URI
77 {
78 $classes = array_map(static fn(array $c): string => $c['cmdClass'], $this->ctrl->getCallHistory());
79
80 $classes[] = MultiLanguageGUI::class;
81
82 return $this->getTargetURI(MultiLanguageGUI::class, $command);
83 }
84
85 public function getURI(string $with_path): URI
86 {
87 return new URI(rtrim(ILIAS_HTTP_PATH, '/') . '/' . ltrim($with_path, '/'));
88 }
89
93 public function getLinkTarget(object $target_class, ?string $command = null): string
94 {
95 return $this->ctrl->getLinkTarget($target_class, $command);
96 }
97
98 public function getCurrentClass(): ?string
99 {
100 return $this->ctrl->getCmdClass();
101 }
102
107 public function getTargetByClass(array|string $target_class, ?string $command = null): string
108 {
109 return $this->ctrl->getLinkTargetByClass($target_class, $command);
110 }
111
112 public function getTargetURI(object|array|string $target_class, ?string $command = null): URI
113 {
114 if (is_object($target_class)) {
115 $target_class = $target_class::class;
116 }
117
118 return $this->getURI($this->getTargetByClass($target_class, $command));
119 }
120
121 public function getCommand(?string $fallback = null): string
122 {
123 $cmd = $this->ctrl->getCmd($fallback);
124 return empty($cmd) ? ($fallback ?? '') : $cmd;
125 }
126
127}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
getCommand(?string $fallback=null)
Definition: Flow.php:121
getTargetByClass(array|string $target_class, ?string $command=null)
Definition: Flow.php:107
getHereAsURI(?string $cmd=null)
Definition: Flow.php:67
getLinkTarget(object $target_class, ?string $command=null)
Definition: Flow.php:93
getTranslationAsURI(?string $command=null)
Definition: Flow.php:76
getURI(string $with_path)
Definition: Flow.php:85
redirect(string $command, ?string $target_class=null)
Definition: Flow.php:44
getTargetURI(object|array|string $target_class, ?string $command=null)
Definition: Flow.php:112
getParentAsURI(?string $cmd=null)
Definition: Flow.php:57
__construct(private Services $http, private \ilCtrlInterface $ctrl)
Definition: Flow.php:33
Class Services.
Definition: Services.php:38
$http
Definition: deliver.php:30
$c
Definition: deliver.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.