ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $request = $this->http->request()->getUri();
88 return new URI($request->getScheme() . '://' . $request->getHost() . '/' . ltrim($with_path, '/'));
89 }
90
94 public function getLinkTarget(object $target_class, ?string $command = null): string
95 {
96 return $this->ctrl->getLinkTarget($target_class, $command);
97 }
98
99 public function getCurrentClass(): ?string
100 {
101 return $this->ctrl->getCmdClass();
102 }
103
108 public function getTargetByClass(array|string $target_class, ?string $command = null): string
109 {
110 return $this->ctrl->getLinkTargetByClass($target_class, $command);
111 }
112
113 public function getTargetURI(object|array|string $target_class, ?string $command = null): URI
114 {
115 if (is_object($target_class)) {
116 $target_class = $target_class::class;
117 }
118
119 return $this->getURI($this->getTargetByClass($target_class, $command));
120 }
121
122 public function getCommand(?string $fallback = null): string
123 {
124 $cmd = $this->ctrl->getCmd($fallback);
125 return empty($cmd) ? ($fallback ?? '') : $cmd;
126 }
127
128}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
getCommand(?string $fallback=null)
Definition: Flow.php:122
getTargetByClass(array|string $target_class, ?string $command=null)
Definition: Flow.php:108
getHereAsURI(?string $cmd=null)
Definition: Flow.php:67
getLinkTarget(object $target_class, ?string $command=null)
Definition: Flow.php:94
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:113
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.