19declare(strict_types=1);
26use Psr\Http\Message\ServerRequestInterface;
27use GuzzleHttp\Psr7\Response;
53 protected ServerRequestInterface $server_request,
74 $a_base_class = $this->context->getBaseClass() ?? $a_base_class;
77 if (
null === $a_base_class) {
78 throw new ilCtrlException(__METHOD__ .
" was not given a baseclass and the request doesn't include one either.");
82 if (!$this->structure->isBaseClass($a_base_class)) {
83 throw new ilCtrlException(
"Provided class '$a_base_class' is not a baseclass");
88 $this->context->setBaseClass($a_base_class);
91 $obj_name = $this->structure->getObjNameByName($a_base_class);
100 $class_name = get_class($a_gui_object);
103 if (!method_exists($a_gui_object,
'executeCommand')) {
104 throw new ilCtrlException(
"$class_name doesn't implement executeCommand().");
107 $this->exec_object = $a_gui_object;
108 $this->
populateCall($class_name, self::CMD_MODE_PROCESS);
115 ->setCmdMode(self::CMD_MODE_PROCESS);
117 $this->subject->notify(ilCtrlEvent::COMMAND_CLASS_FORWARD, $class_name);
119 return $a_gui_object->executeCommand();
125 public function getHTML(
object $a_gui_object, ?array $a_parameters =
null): string
127 $class_name = get_class($a_gui_object);
130 if (!method_exists($a_gui_object,
'getHTML')) {
135 $isolated_context = $this->context;
138 $this->exec_object = $a_gui_object;
141 ->setCmdClass($class_name)
142 ->setCmdMode(self::CMD_MODE_HTML);
144 $html = (
null !== $a_parameters) ?
145 $a_gui_object->getHTML($a_parameters) :
146 $a_gui_object->getHTML();
148 $this->structure = $isolatad_structure;
149 $this->context = $isolated_context;
150 $this->exec_object = $isolated_object;
158 public function getCmd(?
string $fallback_command =
null): ?string
161 $this->subject->notify(ilCtrlEvent::COMMAND_DETERMINATION,
$command);
172 if (
null !== ($cmd_class = $this->context->getCmdClass())) {
173 return strtolower($this->structure->getObjNameByName($cmd_class));
184 if (
null === $a_gui_class &&
null === $this->exec_object) {
188 if (
null === $this->context->getPath()) {
192 $next_cid = $this->context->getPath()->getNextCid(
196 if (
null !== $next_cid) {
197 return strtolower($this->structure->getObjNameByCid($next_cid) ??
'');
216 if (!empty($a_parameter)) {
217 if (is_array($a_parameter)) {
218 foreach ($a_parameter as $parameter) {
219 $this->structure->setPermanentParameterByClass($a_class, $parameter);
222 $this->structure->setPermanentParameterByClass($a_class, $a_parameter);
230 public function setParameter(
object $a_gui_obj,
string $a_parameter, $a_value): void
240 $this->structure->setTemporaryParameterByClass($a_class, $a_parameter, $a_value);
256 if (
null === $this->structure->getClassCidByName($a_class)) {
257 throw new ilCtrlException(
"Cannot find provided class '$a_class' in the control structure.");
261 $permanent_parameters = $this->structure->getPermanentParametersByClass($a_class);
262 if (
null !== $permanent_parameters) {
263 foreach ($permanent_parameters as $parameter) {
268 $temporary_parameters = $this->structure->getTemporaryParametersByClass($a_class);
269 if (
null !== $temporary_parameters) {
272 foreach ($temporary_parameters as $key => $value) {
273 $parameters[$key] = $value;
296 $this->structure->removeTemporaryParametersByClass($a_class);
304 $this->structure->removeSingleParameterByClass($a_class, $a_parameter);
312 ?
string $a_cmd =
null,
313 ?
string $a_anchor =
null,
314 bool $is_async =
false,
315 bool $has_xml_style =
false
331 ?
string $a_cmd =
null,
332 ?
string $a_anchor =
null,
333 bool $is_async =
false,
334 bool $has_xml_style =
false
336 return $this->getTargetUrl(
350 ?
string $a_fallback_cmd =
null,
351 ?
string $a_anchor =
null,
352 bool $is_async =
false,
353 bool $has_xml_style =
false
355 return $this->getFormActionByClass(
356 $this->getClassByObject($a_gui_obj),
369 ?
string $a_fallback_cmd =
null,
370 ?
string $a_anchor =
null,
371 bool $is_async =
false,
372 bool $has_xml_style =
false
374 return $this->getTargetUrl(
389 ?
string $a_cmd =
null,
390 ?
string $a_anchor =
null,
391 bool $is_async =
false
393 $this->redirectByClass(
394 $this->getClassByObject($a_gui_obj),
406 ?
string $a_cmd =
null,
407 ?
string $a_anchor =
null,
408 bool $is_async =
false
410 $this->redirectToURL(
411 $this->getLinkTargetByClass(
426 if (defined(
"ILIAS_HTTP_PATH") &&
427 strpos($target_url,
"://") ===
false &&
428 strpos($target_url,
"/") !== 0
430 $target_url = ILIAS_HTTP_PATH .
"/" . $target_url;
435 $target_url = $this->modifyUrlWithPluginHooks($target_url);
442 if (
'application/json' === $this->server_request->getHeaderLine(
'Accept')) {
444 $body = Streams::ofString(
447 'redirect_url' => $target_url,
449 'message' =>
'called redirect after asynchronous file-upload request.',
454 }
catch (Throwable $exception) {
455 $body = Streams::ofString($exception->getMessage());
466 session_write_close();
469 $this->response_sender->sendResponse(
$response);
471 header(
"Location: $target_url");
472 if (
'application/json' === $this->server_request->getHeaderLine(
'Accept')) {
473 $content = (
null !==
$response->getBody()) ?
477 echo json_encode($content, JSON_THROW_ON_ERROR);
479 }
catch (Throwable $t) {
480 header(
"Location: $target_url");
481 echo $t->getMessage();
493 if (!empty($obj_type)) {
494 $this->context->setObjId($obj_id);
495 $this->context->setObjType($obj_type);
504 return $this->context->getObjId();
512 return $this->context->getObjType();
520 return $this->stacktrace;
528 $path = $this->structure->getRelativePathByName($a_class);
529 if (
null ===
$path) {
530 throw new ilCtrlException(
"Class '$a_class' cannot be found in the control structure.");
541 return $this->structure->getObjNameByName($a_class);
549 $path_info = pathinfo($a_class_path);
551 return substr($path_info[
'basename'], 6, -4);
559 $this->context->setTargetScript($a_target_script);
567 return $this->context->isAsync();
573 public function setReturn(
object $a_gui_obj, ?
string $a_cmd =
null): void
575 $this->setReturnByClass($this->getClassByObject($a_gui_obj), $a_cmd);
583 $this->structure->setReturnTargetByClass(
585 $this->getLinkTargetByClass(
595 public function returnToParent(
object $a_gui_obj, ?
string $a_anchor =
null): void
597 $class_name = $this->getClassByObject($a_gui_obj);
598 $target_url = $this->getParentReturnByClass($class_name);
601 $target_url = $this->appendParameterString(
603 self::PARAM_REDIRECT,
608 if (
null !== $a_anchor) {
609 $target_url .=
"#$a_anchor";
612 $this->redirectToURL($target_url);
620 return $this->getParentReturnByClass($this->getClassByObject($a_gui_obj));
628 $path = $this->path_factory->find($this->context, $a_class);
629 if (
null !==
$path->getCidPath()) {
630 foreach (
$path->getCidArray() as $cid) {
631 $current_class = $this->structure->getClassNameByCid($cid);
632 $return_target = $this->structure->getReturnTargetByClass($current_class);
633 if (
null !== $return_target) {
634 return $return_target;
647 return $this->context->getRedirectSource();
655 throw new ilCtrlException(__METHOD__ .
" is deprecated and must not be used.");
663 $class_cid = $this->structure->getClassCidByName($gui_class);
664 if (
null === $class_cid) {
669 $this->context->getPath()->getCidPath() ??
'',
679 if (
null === $this->context->getPath()->getCidPath()) {
684 foreach ($this->context->getPath()->getCidArray(SORT_ASC) as $cid) {
685 $class_paths[] = $this->structure->getObjNameByCid($cid);
696 $this->subject->attach($observer, $event);
704 $this->subject->detach($observer, $event);
710 $post_command = $this->getPostCommand();
711 $get_command = $this->getQueryParam(self::PARAM_CMD);
712 $table_command = $this->getTableCommand();
714 $is_post = (self::CMD_POST === $get_command);
721 $command = ($is_post) ?
722 $post_command ?? $table_command ?? $this->getQueryParam(self::PARAM_CMD_FALLBACK) :
727 $context_command = $this->context->getCmd();
728 if (
null !== $context_command && self::CMD_POST !== $context_command) {
729 $command = $context_command;
732 if (
null === $command) {
738 $cmd_class = $this->context->getCmdClass();
739 if (
null !== $cmd_class && !$this->isCmdSecure($is_post, $cmd_class, $command)) {
740 $stored_token = $this->token_repository->getToken();
741 $sent_token = $this->getQueryParam(self::PARAM_CSRF_TOKEN);
743 if (
null !== $sent_token && $stored_token->verifyWith($sent_token)) {
760 if ($this->get_parameters->has($parameter_name)) {
761 return $this->get_parameters->retrieve(
775 if ($this->post_parameters->has(
'table_top_cmd')) {
776 return $this->post_parameters->retrieve(
778 $this->
refinery->custom()->transformation(function ($item): ?
string {
779 return is_array($item) ? key($item) :
null;
784 if ($this->post_parameters->has(
'select_cmd2')) {
785 return $this->post_parameters->has(
'selected_cmd2')
786 ? $this->post_parameters->retrieve(
'selected_cmd2', $this->
refinery->to()->string())
790 if ($this->post_parameters->has(
'select_cmd')) {
791 return $this->post_parameters->has(
'selected_cmd')
792 ? $this->post_parameters->retrieve(
'selected_cmd', $this->
refinery->to()->string())
805 if ($this->post_parameters->has(self::PARAM_CMD)) {
806 return $this->post_parameters->retrieve(
808 $this->
refinery->custom()->transformation(
809 static function ($value): ?
string {
810 if (!empty($value)) {
811 if (is_array($value)) {
816 return (
string) array_key_first($value);
819 return (
string) $value;
845 ?
string $a_cmd =
null,
846 ?
string $a_anchor =
null,
847 bool $is_async =
false,
848 bool $is_escaped =
false,
849 bool $is_post =
false
851 if (empty($a_class)) {
852 throw new ilCtrlException(__METHOD__ .
" was provided with an empty class or class-array.");
855 $is_array = is_array($a_class);
857 $path = $this->path_factory->find($this->context, $a_class);
858 if (
null !== ($exception =
$path->getException())) {
862 $base_class =
$path->getBaseClass();
863 if (
null === $base_class) {
864 throw new ilCtrlException(
"Cannot find a valid baseclass in the cid path '{$path->getCidPath()}'");
867 $target_url = $this->context->getTargetScript();
868 $target_url = $this->appendParameterString(
870 self::PARAM_BASE_CLASS,
871 urlencode($base_class),
875 $cmd_class = ($is_array) ?
876 $a_class[array_key_last($a_class)] :
881 if (
null !==
$path->getNextCid($base_class)) {
882 $target_url = $this->appendParameterString(
884 self::PARAM_CID_PATH,
889 $target_url = $this->appendParameterString(
891 self::PARAM_CMD_CLASS,
892 urlencode($cmd_class),
900 $target_url = $this->appendParameterString(
910 if (!empty($a_cmd)) {
911 $target_url = $this->appendParameterString(
913 ($is_post) ? self::PARAM_CMD_FALLBACK : self::PARAM_CMD,
921 foreach (
$path->getCidArray(SORT_ASC) as $cid) {
922 $class_name = $this->structure->getClassNameByCid($cid);
923 if (
null === $class_name) {
924 throw new ilCtrlException(
"Classname for cid '$cid' in current path cannot be found.");
927 $target_url = $this->appendParameterStringsByClass(
936 if (!$this->isCmdSecure($is_post, $cmd_class, $a_cmd)) {
937 $token = $this->token_repository->getToken();
938 $target_url = $this->appendParameterString(
940 self::PARAM_CSRF_TOKEN,
947 $target_url = $this->appendParameterString(
949 self::PARAM_CMD_MODE,
950 self::CMD_MODE_ASYNC,
955 if (!empty($a_anchor)) {
956 $target_url .=
"#$a_anchor";
968 private function modifyUrlWithPluginHooks(
string $target_url): string
970 $ui_plugins = $this->component_factory->getActivePluginsInSlot(
"uihk");
971 foreach ($ui_plugins as $plugin_instance) {
974 $html = $plugin_instance
975 ->getUIClassInstance()
977 'components/ILIAS/Utilities',
979 [
"html" => $target_url]
983 $target_url = $plugin_instance
984 ->getUIClassInstance()
1002 private function isCmdSecure(
bool $is_post,
string $cmd_class, ?
string $cmd =
null): bool
1006 if (
null === $cmd) {
1013 $obj_name = $this->structure->getObjNameByName($cmd_class);
1014 if (
null === $obj_name) {
1021 if (!is_a($obj_name, ilCtrlSecurityInterface::class,
true)) {
1028 return in_array($cmd, $this->structure->getSafeCommandsByName($cmd_class),
true);
1033 return !in_array($cmd, $this->structure->getUnsafeCommandsByName($cmd_class),
true);
1047 bool $is_escaped =
false
1049 $class_parameters = $this->getParameterArrayByClass($class_name);
1050 if (!empty($class_parameters)) {
1051 foreach ($class_parameters as $key => $value) {
1052 $target_url = $this->appendParameterString(
1072 private function appendParameterString(
1074 string $parameter_name,
1076 bool $is_escaped =
false
1082 if (
'' === $value) {
1087 $parsed_url = parse_url(str_replace(
'&',
'&',
$url));
1089 $query_parameters = $this->query_parser->parseQueriesOfURL($parsed_url[
'query'] ??
'');
1092 $query_parameters[$parameter_name] = $value;
1094 $new_url = $parsed_url[
'path'] ?? $this->context->getTargetScript();
1096 $ampersand = ($is_escaped) ?
'&' :
'&';
1098 foreach ($query_parameters as $parameter => $parameter_value) {
1099 $new_url .= (strpos($new_url,
'?') !==
false) ?
1100 $ampersand .
"$parameter=$parameter_value" :
1101 "?$parameter=$parameter_value";
1114 $obj_name = $this->structure->getObjNameByName($class_name);
1116 $this->stacktrace[] = [
1117 self::PARAM_CMD_CLASS => $obj_name,
1118 self::PARAM_CMD_MODE => $cmd_mode,
1119 self::PARAM_CMD => $this->getDeterminedCommand(),
1131 return (is_object($object)) ? get_class($object) : $object;
$structure
TOTAL STRUCTURE.
Stream factory which enables the user to create streams without the knowledge of the concrete class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
getCurrentClassPath()
@inheritDoc
getParentReturn(object $a_gui_obj)
@inheritDoc
populateCall(string $class_name, string $cmd_mode)
Helper function that populates a call in the current stacktrace.
__construct(protected ilCtrlStructureInterface $structure, protected ilCtrlTokenRepositoryInterface $token_repository, protected ilCtrlPathFactoryInterface $path_factory, protected ilCtrlContextInterface $context, protected ResponseSenderStrategy $response_sender, protected ServerRequestInterface $server_request, protected RequestWrapper $post_parameters, protected RequestWrapper $get_parameters, protected Refinery $refinery, protected ilComponentFactory $component_factory, protected ilCtrlSubject $subject, protected ilCtrlQueryParserInterface $query_parser,)
getCallHistory()
@inheritDoc
getFormActionByClass( $a_class, ?string $a_fallback_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
redirectByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
setReturnByClass(string $a_class, ?string $a_cmd=null)
@inheritDoc
getClassForClasspath(string $a_class_path)
@inheritDoc
insertCtrlCalls($a_parent, $a_child, string $a_comp_prefix)
@inheritDoc
getPostCommand()
Returns the current $_POST command.
getContextObjId()
@inheritDoc
getFormAction(object $a_gui_obj, ?string $a_fallback_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
setContextObject(int $obj_id, string $obj_type)
@inheritDoc
saveParameterByClass(string $a_class, $a_parameter)
@inheritDoc
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
lookupClassPath(string $a_class)
@inheritDoc
getTargetUrl( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $is_escaped=false, bool $is_post=false)
Helper function that returns a target URL string.
getParameterArrayByClass(string $a_class)
@inheritDoc
redirectToURL(string $target_url)
@inheritDoc
getHTML(object $a_gui_object, ?array $a_parameters=null)
@inheritDoc
attachObserver(ilCtrlObserver $observer, ilCtrlEvent $event=ilCtrlEvent::ALL)
@inheritDoc
getQueryParam(string $parameter_name)
Returns a parameter with the given name from the current GET request.
callBaseClass(?string $a_base_class=null)
@inheritDoc
getNextClass($a_gui_class=null)
@inheritDoc
getRedirectSource()
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
detachObserver(ilCtrlObserver $observer, ilCtrlEvent $event=ilCtrlEvent::ALL)
@inheritDoc
clearParameters(object $a_gui_obj)
@inheritDoc
saveParameter(object $a_gui_obj, $a_parameter)
@inheritDoc
setTargetScript(string $a_target_script)
@inheritDoc
getContextObjType()
@inheritDoc
checkCurrentPathForClass(string $gui_class)
@inheritDoc
getClassByObject($object)
Helper function that returns the class name of a mixed (object or string) parameter.
clearParametersByClass(string $a_class)
@inheritDoc
getParentReturnByClass(string $a_class)
@inheritDoc
clearParameterByClass(string $a_class, string $a_parameter)
@inheritDoc
isCmdSecure(bool $is_post, string $cmd_class, ?string $cmd=null)
Returns whether a given command is considered safe or not.
appendParameterStringsByClass(string $class_name, string $target_url, bool $is_escaped=false)
Appends all parameters for a given class to the given URL.
returnToParent(object $a_gui_obj, ?string $a_anchor=null)
@inheritDoc
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
forwardCommand(object $a_gui_object)
@inheritDoc
getCmd(?string $fallback_command=null)
@inheritDoc
setParameterByClass(string $a_class, string $a_parameter, $a_value)
@inheritDoc
setReturn(object $a_gui_obj, ?string $a_cmd=null)
@inheritDoc
getParameterArray(object $a_gui_obj)
@inheritDoc
getLinkTargetByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
lookupOriginalClassName(string $a_class)
@inheritDoc
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@ ALL
event string being used if
Interface ResponseSenderStrategy.
Interface RequestWrapper.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))