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)) {
766 if ($this->get_parameters->has($parameter_name)) {
767 return $this->get_parameters->retrieve(
781 if ($this->post_parameters->has(
'table_top_cmd')) {
782 return $this->post_parameters->retrieve(
784 $this->
refinery->custom()->transformation(
function ($item): ?
string {
785 return is_array($item) ? key($item) :
null;
790 if ($this->post_parameters->has(
'select_cmd2')) {
791 return $this->post_parameters->has(
'selected_cmd2')
792 ? $this->post_parameters->retrieve(
'selected_cmd2', $this->
refinery->to()->string())
796 if ($this->post_parameters->has(
'select_cmd')) {
797 return $this->post_parameters->has(
'selected_cmd')
798 ? $this->post_parameters->retrieve(
'selected_cmd', $this->
refinery->to()->string())
811 if ($this->post_parameters->has(self::PARAM_CMD)) {
812 return $this->post_parameters->retrieve(
814 $this->
refinery->custom()->transformation(
815 static function ($value): ?
string {
816 if (!empty($value)) {
817 if (is_array($value)) {
822 return (
string) array_key_first($value);
825 return (
string) $value;
851 ?
string $a_cmd =
null,
852 ?
string $a_anchor =
null,
853 bool $is_async =
false,
854 bool $is_escaped =
false,
855 bool $is_post =
false 857 if (empty($a_class)) {
858 throw new ilCtrlException(__METHOD__ .
" was provided with an empty class or class-array.");
861 $is_array = is_array($a_class);
863 $path = $this->path_factory->find($this->context, $a_class);
864 if (
null !== ($exception =
$path->getException())) {
868 $base_class =
$path->getBaseClass();
869 if (
null === $base_class) {
870 throw new ilCtrlException(
"Cannot find a valid baseclass in the cid path '{$path->getCidPath()}'");
873 $target_url = $this->context->getTargetScript();
874 $target_url = $this->appendParameterString(
876 self::PARAM_BASE_CLASS,
877 urlencode($base_class),
881 $cmd_class = ($is_array) ?
882 $a_class[array_key_last($a_class)] :
887 if (
null !==
$path->getNextCid($base_class)) {
888 $target_url = $this->appendParameterString(
890 self::PARAM_CID_PATH,
895 $target_url = $this->appendParameterString(
897 self::PARAM_CMD_CLASS,
898 urlencode($cmd_class),
906 $target_url = $this->appendParameterString(
916 if (!empty($a_cmd)) {
917 $target_url = $this->appendParameterString(
919 ($is_post) ? self::PARAM_CMD_FALLBACK : self::PARAM_CMD,
927 foreach (
$path->getCidArray(SORT_ASC) as $cid) {
928 $class_name = $this->structure->getClassNameByCid($cid);
929 if (
null === $class_name) {
930 throw new ilCtrlException(
"Classname for cid '$cid' in current path cannot be found.");
942 if (!$this->
isCmdSecure($is_post, $cmd_class, $a_cmd)) {
943 $token = $this->token_repository->getToken();
944 $target_url = $this->appendParameterString(
946 self::PARAM_CSRF_TOKEN,
953 $target_url = $this->appendParameterString(
955 self::PARAM_CMD_MODE,
956 self::CMD_MODE_ASYNC,
961 if (!empty($a_anchor)) {
962 $target_url .=
"#$a_anchor";
974 private function modifyUrlWithPluginHooks(
string $target_url):
string 976 $ui_plugins = $this->component_factory->getActivePluginsInSlot(
"uihk");
977 foreach ($ui_plugins as $plugin_instance) {
980 $html = $plugin_instance
981 ->getUIClassInstance()
983 'components/ILIAS/Utilities',
985 [
"html" => $target_url]
989 $target_url = $plugin_instance
990 ->getUIClassInstance()
1012 if (
null === $cmd) {
1019 $obj_name = $this->structure->getObjNameByName($cmd_class);
1020 if (
null === $obj_name) {
1027 if (!is_a($obj_name, ilCtrlSecurityInterface::class,
true)) {
1034 return in_array($cmd, $this->structure->getSafeCommandsByName($cmd_class),
true);
1039 return !in_array($cmd, $this->structure->getUnsafeCommandsByName($cmd_class),
true);
1053 bool $is_escaped =
false 1056 if (!empty($class_parameters)) {
1057 foreach ($class_parameters as $key => $value) {
1058 $target_url = $this->appendParameterString(
1078 private function appendParameterString(
1080 string $parameter_name,
1082 bool $is_escaped =
false 1086 $value = $this->
refinery->kindlyTo()->string()->transform($value ??
'');
1088 if (
'' === $value) {
1093 $parsed_url = parse_url(str_replace(
'&',
'&', $url));
1095 $query_parameters = $this->query_parser->parseQueriesOfURL($parsed_url[
'query'] ??
'');
1098 $query_parameters[$parameter_name] = $value;
1100 $new_url = $parsed_url[
'path'] ?? $this->context->getTargetScript();
1102 $ampersand = ($is_escaped) ?
'&' :
'&';
1104 foreach ($query_parameters as $parameter => $parameter_value) {
1105 $new_url .= (strpos($new_url,
'?') !==
false) ?
1106 $ampersand .
"$parameter=$parameter_value" :
1107 "?$parameter=$parameter_value";
1120 $obj_name = $this->structure->getObjNameByName($class_name);
1122 $this->stacktrace[] = [
1123 self::PARAM_CMD_CLASS => $obj_name,
1124 self::PARAM_CMD_MODE => $cmd_mode,
1137 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.
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)