19 declare(strict_types=1);
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')) {
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 if (
null !== $this->command && $command === $this->command) {
167 $this->subject->notify(ilCtrlEvent::COMMAND_DETERMINATION, $command);
170 return $command ??
'';
178 if (
null !== ($cmd_class = $this->context->getCmdClass())) {
179 return strtolower($this->structure->getObjNameByName($cmd_class));
190 if (
null === $a_gui_class &&
null === $this->exec_object) {
194 if (
null === $this->context->getPath()) {
198 $next_cid = $this->context->getPath()->getNextCid(
202 if (
null !== $next_cid) {
203 return strtolower($this->structure->getObjNameByCid($next_cid) ??
'');
222 if (!empty($a_parameter)) {
223 if (is_array($a_parameter)) {
224 foreach ($a_parameter as $parameter) {
225 $this->structure->setPermanentParameterByClass($a_class, $parameter);
228 $this->structure->setPermanentParameterByClass($a_class, $a_parameter);
236 public function setParameter(
object $a_gui_obj,
string $a_parameter, $a_value): void
246 $this->structure->setTemporaryParameterByClass($a_class, $a_parameter, $a_value);
262 if (
null === $this->structure->getClassCidByName($a_class)) {
263 throw new ilCtrlException(
"Cannot find provided class '$a_class' in the control structure.");
267 $permanent_parameters = $this->structure->getPermanentParametersByClass($a_class);
268 if (
null !== $permanent_parameters) {
269 foreach ($permanent_parameters as $parameter) {
274 $temporary_parameters = $this->structure->getTemporaryParametersByClass($a_class);
275 if (
null !== $temporary_parameters) {
278 foreach ($temporary_parameters as $key => $value) {
279 $parameters[$key] = $value;
302 $this->structure->removeTemporaryParametersByClass($a_class);
310 $this->structure->removeSingleParameterByClass($a_class, $a_parameter);
318 ?
string $a_cmd =
null,
319 ?
string $a_anchor =
null,
320 bool $is_async =
false,
321 bool $has_xml_style =
false 337 ?
string $a_cmd =
null,
338 ?
string $a_anchor =
null,
339 bool $is_async =
false,
340 bool $has_xml_style =
false 356 ?
string $a_fallback_cmd =
null,
357 ?
string $a_anchor =
null,
358 bool $is_async =
false,
359 bool $has_xml_style =
false 375 ?
string $a_fallback_cmd =
null,
376 ?
string $a_anchor =
null,
377 bool $is_async =
false,
378 bool $has_xml_style =
false 395 ?
string $a_cmd =
null,
396 ?
string $a_anchor =
null,
397 bool $is_async =
false 412 ?
string $a_cmd =
null,
413 ?
string $a_anchor =
null,
414 bool $is_async =
false 432 if (defined(
"ILIAS_HTTP_PATH") &&
433 strpos($target_url,
"://") ===
false &&
434 strpos($target_url,
"/") !== 0
436 $target_url = ILIAS_HTTP_PATH .
"/" . $target_url;
441 $target_url = $this->modifyUrlWithPluginHooks($target_url);
448 if (
'application/json' === $this->server_request->getHeaderLine(
'Accept')) {
450 $body = Streams::ofString(
453 'redirect_url' => $target_url,
455 'message' =>
'called redirect after asynchronous file-upload request.',
461 $body = Streams::ofString($exception->getMessage());
472 session_write_close();
475 $this->response_sender->sendResponse(
$response);
477 header(
"Location: $target_url");
478 if (
'application/json' === $this->server_request->getHeaderLine(
'Accept')) {
483 echo json_encode($content, JSON_THROW_ON_ERROR);
486 header(
"Location: $target_url");
487 echo $t->getMessage();
499 if (!empty($obj_type)) {
500 $this->context->setObjId($obj_id);
501 $this->context->setObjType($obj_type);
510 return $this->context->getObjId();
518 return $this->context->getObjType();
534 $path = $this->structure->getRelativePathByName($a_class);
536 throw new ilCtrlException(
"Class '$a_class' cannot be found in the control structure.");
547 return $this->structure->getObjNameByName($a_class);
555 $path_info = pathinfo($a_class_path);
557 return substr($path_info[
'basename'], 6, -4);
565 $this->context->setTargetScript($a_target_script);
573 return $this->context->isAsync();
589 $this->structure->setReturnTargetByClass(
607 $target_url = $this->appendParameterString(
609 self::PARAM_REDIRECT,
614 if (
null !== $a_anchor) {
615 $target_url .=
"#$a_anchor";
634 $path = $this->path_factory->find($this->context, $a_class);
636 foreach (
$path->getCidArray() as $cid) {
637 $current_class = $this->structure->getClassNameByCid($cid);
638 $return_target = $this->structure->getReturnTargetByClass($current_class);
639 if (
null !== $return_target) {
640 return $return_target;
653 return $this->context->getRedirectSource();
661 throw new ilCtrlException(__METHOD__ .
" is deprecated and must not be used.");
669 $class_cid = $this->structure->getClassCidByName($gui_class);
670 if (
null === $class_cid) {
675 $this->context->getPath()->getCidPath() ??
'',
685 if (
null === $this->context->getPath()->getCidPath()) {
690 foreach ($this->context->getPath()->getCidArray(SORT_ASC) as $cid) {
691 $class_paths[] = $this->structure->getObjNameByCid($cid);
702 $this->subject->attach($observer, $event);
710 $this->subject->detach($observer, $event);
720 $is_post = (self::CMD_POST === $get_command);
727 $command = ($is_post) ?
728 $post_command ?? $table_command ?? $this->
getQueryParam(self::PARAM_CMD_FALLBACK) :
733 $context_command = $this->context->getCmd();
734 if (
null !== $context_command && self::CMD_POST !== $context_command) {
735 $command = $context_command;
738 if (
null === $command) {
744 $cmd_class = $this->context->getCmdClass();
745 if (
null !== $cmd_class && !$this->
isCmdSecure($is_post, $cmd_class, $command)) {
746 $stored_token = $this->token_repository->getToken();
749 if (
null !== $sent_token && $stored_token->verifyWith($sent_token)) {
765 if ($this->get_parameters->has($parameter_name)) {
766 return $this->get_parameters->retrieve(
780 if ($this->post_parameters->has(
'table_top_cmd')) {
781 return $this->post_parameters->retrieve(
783 $this->
refinery->custom()->transformation(
function ($item): ?
string {
784 return is_array($item) ? key($item) :
null;
789 if ($this->post_parameters->has(
'select_cmd2')) {
790 return $this->post_parameters->has(
'selected_cmd2')
791 ? $this->post_parameters->retrieve(
'selected_cmd2', $this->
refinery->to()->string())
795 if ($this->post_parameters->has(
'select_cmd')) {
796 return $this->post_parameters->has(
'selected_cmd')
797 ? $this->post_parameters->retrieve(
'selected_cmd', $this->
refinery->to()->string())
810 if ($this->post_parameters->has(self::PARAM_CMD)) {
811 return $this->post_parameters->retrieve(
813 $this->
refinery->custom()->transformation(
814 static function ($value): ?
string {
815 if (!empty($value)) {
816 if (is_array($value)) {
821 return (
string) array_key_first($value);
824 return (
string) $value;
850 ?
string $a_cmd =
null,
851 ?
string $a_anchor =
null,
852 bool $is_async =
false,
853 bool $is_escaped =
false,
854 bool $is_post =
false 856 if (empty($a_class)) {
857 throw new ilCtrlException(__METHOD__ .
" was provided with an empty class or class-array.");
860 $is_array = is_array($a_class);
862 $path = $this->path_factory->find($this->context, $a_class);
863 if (
null !== ($exception =
$path->getException())) {
867 $base_class =
$path->getBaseClass();
868 if (
null === $base_class) {
869 throw new ilCtrlException(
"Cannot find a valid baseclass in the cid path '{$path->getCidPath()}'");
872 $target_url = $this->context->getTargetScript();
873 $target_url = $this->appendParameterString(
875 self::PARAM_BASE_CLASS,
876 urlencode($base_class),
880 $cmd_class = ($is_array) ?
881 $a_class[array_key_last($a_class)] :
886 if (
null !==
$path->getNextCid($base_class)) {
887 $target_url = $this->appendParameterString(
889 self::PARAM_CID_PATH,
894 $target_url = $this->appendParameterString(
896 self::PARAM_CMD_CLASS,
897 urlencode($cmd_class),
905 $target_url = $this->appendParameterString(
915 if (!empty($a_cmd)) {
916 $target_url = $this->appendParameterString(
918 ($is_post) ? self::PARAM_CMD_FALLBACK : self::PARAM_CMD,
926 foreach (
$path->getCidArray(SORT_ASC) as $cid) {
927 $class_name = $this->structure->getClassNameByCid($cid);
928 if (
null === $class_name) {
929 throw new ilCtrlException(
"Classname for cid '$cid' in current path cannot be found.");
941 if (!$this->
isCmdSecure($is_post, $cmd_class, $a_cmd)) {
942 $token = $this->token_repository->getToken();
943 $target_url = $this->appendParameterString(
945 self::PARAM_CSRF_TOKEN,
952 $target_url = $this->appendParameterString(
954 self::PARAM_CMD_MODE,
955 self::CMD_MODE_ASYNC,
960 if (!empty($a_anchor)) {
961 $target_url .=
"#$a_anchor";
973 private function modifyUrlWithPluginHooks(
string $target_url):
string 975 $ui_plugins = $this->component_factory->getActivePluginsInSlot(
"uihk");
976 foreach ($ui_plugins as $plugin_instance) {
979 $html = $plugin_instance
980 ->getUIClassInstance()
982 'components/ILIAS/Utilities',
984 [
"html" => $target_url]
988 $target_url = $plugin_instance
989 ->getUIClassInstance()
1011 if (
null === $cmd) {
1018 $obj_name = $this->structure->getObjNameByName($cmd_class);
1019 if (
null === $obj_name) {
1026 if (!is_a($obj_name, ilCtrlSecurityInterface::class,
true)) {
1033 return in_array($cmd, $this->structure->getSafeCommandsByName($cmd_class),
true);
1038 return !in_array($cmd, $this->structure->getUnsafeCommandsByName($cmd_class),
true);
1052 bool $is_escaped =
false 1055 if (!empty($class_parameters)) {
1056 foreach ($class_parameters as $key => $value) {
1057 $target_url = $this->appendParameterString(
1077 private function appendParameterString(
1079 string $parameter_name,
1081 bool $is_escaped =
false 1085 $value = $this->
refinery->kindlyTo()->string()->transform($value ??
'');
1087 if (
'' === $value) {
1092 $parsed_url = parse_url(str_replace(
'&',
'&', $url));
1094 $query_parameters = $this->query_parser->parseQueriesOfURL($parsed_url[
'query'] ??
'');
1097 $query_parameters[$parameter_name] = $value;
1099 $new_url = $parsed_url[
'path'] ?? $this->context->getTargetScript();
1101 $ampersand = ($is_escaped) ?
'&' :
'&';
1103 foreach ($query_parameters as $parameter => $parameter_value) {
1104 $new_url .= (strpos($new_url,
'?') !==
false) ?
1105 $ampersand .
"$parameter=$parameter_value" :
1106 "?$parameter=$parameter_value";
1119 $obj_name = $this->structure->getObjNameByName($class_name);
1121 $this->stacktrace[] = [
1122 self::PARAM_CMD_CLASS => $obj_name,
1123 self::PARAM_CMD_MODE => $cmd_mode,
1136 return (is_object($object)) ? get_class($object) : $object;
getPostCommand()
Returns the current $_POST command.
getFormAction(object $a_gui_obj, ?string $a_fallback_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
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.
getClassByObject($object)
Helper function that returns the class name of a mixed (object or string) parameter.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCmd(?string $fallback_command=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
insertCtrlCalls($a_parent, $a_child, string $a_comp_prefix)
checkCurrentPathForClass(string $gui_class)
lookupOriginalClassName(string $a_class)
setParameterByClass(string $a_class, string $a_parameter, $a_value)
clearParameterByClass(string $a_class, string $a_parameter)
redirectByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
forwardCommand(object $a_gui_object)
event string being used if
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
isCmdSecure(bool $is_post, string $cmd_class, ?string $cmd=null)
Returns whether a given command is considered safe or not.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getClassForClasspath(string $a_class_path)
getParentReturn(object $a_gui_obj)
getNextClass($a_gui_class=null)
getQueryParam(string $parameter_name)
Returns a parameter with the given name from the current GET request.
setReturnByClass(string $a_class, ?string $a_cmd=null)
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
__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,)
setReturn(object $a_gui_obj, ?string $a_cmd=null)
clearParameters(object $a_gui_obj)
appendParameterStringsByClass(string $class_name, string $target_url, bool $is_escaped=false)
Appends all parameters for a given class to the given URL.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$structure
TOTAL STRUCTURE.
Interface ResponseSenderStrategy.
lookupClassPath(string $a_class)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
clearParametersByClass(string $a_class)
getParentReturnByClass(string $a_class)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
detachObserver(ilCtrlObserver $observer, ilCtrlEvent $event=ilCtrlEvent::ALL)
getParameterArrayByClass(string $a_class)
setTargetScript(string $a_target_script)
getHTML(object $a_gui_object, ?array $a_parameters=null)
saveParameter(object $a_gui_obj, $a_parameter)
getParameterArray(object $a_gui_obj)
getFormActionByClass( $a_class, ?string $a_fallback_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
saveParameterByClass(string $a_class, $a_parameter)
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
redirectToURL(string $target_url)
attachObserver(ilCtrlObserver $observer, ilCtrlEvent $event=ilCtrlEvent::ALL)
returnToParent(object $a_gui_obj, ?string $a_anchor=null)
populateCall(string $class_name, string $cmd_mode)
Helper function that populates a call in the current stacktrace.
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContextObject(int $obj_id, string $obj_type)
callBaseClass(?string $a_base_class=null)
getLinkTargetByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)