18declare(strict_types=1);
25use Psr\Http\Message\ServerRequestInterface;
26use GuzzleHttp\Psr7\Response;
160 $a_base_class = $this->context->getBaseClass() ?? $a_base_class;
163 if (
null === $a_base_class) {
164 throw new ilCtrlException(__METHOD__ .
" was not given a baseclass and the request doesn't include one either.");
168 if (!$this->structure->isBaseClass($a_base_class)) {
169 throw new ilCtrlException(
"Provided class '$a_base_class' is not a baseclass");
174 $this->context->setBaseClass($a_base_class);
177 $obj_name = $this->structure->getObjNameByName($a_base_class);
186 $class_name = get_class($a_gui_object);
189 if (!method_exists($a_gui_object,
'executeCommand')) {
190 throw new ilCtrlException(
"$class_name doesn't implement executeCommand().");
193 $this->exec_object = $a_gui_object;
194 $this->
populateCall($class_name, self::CMD_MODE_PROCESS);
201 ->setCmdMode(self::CMD_MODE_PROCESS);
203 return $a_gui_object->executeCommand();
209 public function getHTML(
object $a_gui_object, array $a_parameters =
null): string
211 $class_name = get_class($a_gui_object);
213 if (!method_exists($a_gui_object,
'getHTML')) {
221 $this->exec_object = $a_gui_object;
224 ->setCmdClass($class_name)
225 ->setCmdMode(self::CMD_MODE_HTML);
227 $html = (
null !== $a_parameters) ?
228 $a_gui_object->getHTML($a_parameters) :
229 $a_gui_object->getHTML();
231 $this->structure = $isolatad_structure;
232 $this->context = $isolated_context;
233 $this->exec_object = $isolated_object;
241 public function getCmd(
string $fallback_command =
null): ?string
248 $is_post = (self::CMD_POST === $get_command);
255 $command = ($is_post) ?
256 $post_command ?? $table_command ?? $this->
getQueryParam(self::PARAM_CMD_FALLBACK) :
261 $context_command = $this->context->getCmd();
262 if (
null !== $context_command && self::CMD_POST !== $context_command) {
263 $command = $context_command;
266 if (
null !== $command) {
269 $cmd_class = $this->context->getCmdClass();
271 if (
null !== $cmd_class && !$this->
isCmdSecure($is_post, $cmd_class, $command)) {
272 $stored_token = $this->token_repository->getToken();
275 if (
null !== $sent_token && $stored_token->verifyWith($sent_token)) {
278 return $fallback_command ??
'';
283 return $fallback_command ??
'';
289 public function setCmd(?
string $a_cmd): void
291 if (!empty($a_cmd)) {
292 $this->context->setCmd($a_cmd);
294 $this->context->setCmd(
null);
303 if (
null !== ($cmd_class = $this->context->getCmdClass())) {
304 return strtolower($this->structure->getObjNameByName($cmd_class));
315 if (!empty($a_cmd_class)) {
316 $this->context->setCmdClass($a_cmd_class);
318 $this->context->setCmdClass(
null);
327 if (
null === $a_gui_class &&
null === $this->exec_object) {
331 if (
null === $this->context->getPath()) {
335 $next_cid = $this->context->getPath()->getNextCid(
339 if (
null !== $next_cid) {
340 return strtolower($this->structure->getObjNameByCid($next_cid) ??
'');
359 if (!empty($a_parameter)) {
360 if (is_array($a_parameter)) {
361 foreach ($a_parameter as $parameter) {
362 $this->structure->setPermanentParameterByClass($a_class, $parameter);
365 $this->structure->setPermanentParameterByClass($a_class, $a_parameter);
373 public function setParameter(
object $a_gui_obj,
string $a_parameter, $a_value): void
383 $this->structure->setTemporaryParameterByClass($a_class, $a_parameter, $a_value);
399 if (
null === $this->structure->getClassCidByName($a_class)) {
400 throw new ilCtrlException(
"Cannot find provided class '$a_class' in the control structure.");
404 $permanent_parameters = $this->structure->getPermanentParametersByClass($a_class);
405 if (
null !== $permanent_parameters) {
406 foreach ($permanent_parameters as $parameter) {
411 $temporary_parameters = $this->structure->getTemporaryParametersByClass($a_class);
412 if (
null !== $temporary_parameters) {
415 foreach ($temporary_parameters as
$key => $value) {
416 $parameters[
$key] = $value;
439 $this->structure->removeTemporaryParametersByClass($a_class);
447 $this->structure->removeSingleParameterByClass($a_class, $a_parameter);
455 string $a_cmd =
null,
456 string $a_anchor =
null,
457 bool $is_async =
false,
458 bool $has_xml_style =
false
474 string $a_cmd =
null,
475 string $a_anchor =
null,
476 bool $is_async =
false,
477 bool $has_xml_style =
false
479 return $this->getTargetUrl(
493 string $a_fallback_cmd =
null,
494 string $a_anchor =
null,
495 bool $is_async =
false,
496 bool $has_xml_style =
false
498 return $this->getFormActionByClass(
499 $this->getClassByObject($a_gui_obj),
512 string $a_fallback_cmd =
null,
513 string $a_anchor =
null,
514 bool $is_async =
false,
515 bool $has_xml_style =
false
517 return $this->getTargetUrl(
532 string $a_cmd =
null,
533 string $a_anchor =
null,
534 bool $is_async =
false
536 $this->redirectByClass(
537 $this->getClassByObject($a_gui_obj),
549 string $a_cmd =
null,
550 string $a_anchor =
null,
551 bool $is_async =
false
553 $this->redirectToURL(
554 $this->getLinkTargetByClass(
569 if (defined(
"ILIAS_HTTP_PATH") &&
570 strpos($target_url,
"://") ===
false &&
571 strpos($target_url,
"/") !== 0
573 $target_url = ILIAS_HTTP_PATH .
"/" . $target_url;
578 $target_url = $this->modifyUrlWithPluginHooks($target_url);
585 if (
'application/json' === $this->server_request->getHeaderLine(
'Accept')) {
587 $body = Streams::ofString(
590 'redirect_url' => $target_url,
592 'message' =>
'called redirect after asynchronous file-upload request.',
597 }
catch (Throwable $exception) {
598 $body = Streams::ofString($exception->getMessage());
609 session_write_close();
612 $this->response_sender->sendResponse(
$response);
614 header(
"Location: $target_url");
615 if (
'application/json' === $this->server_request->getHeaderLine(
'Accept')) {
616 $content = (
null !==
$response->getBody()) ?
620 echo json_encode($content, JSON_THROW_ON_ERROR);
622 }
catch (Throwable $t) {
623 header(
"Location: $target_url");
624 echo $t->getMessage();
636 if (!empty($obj_type)) {
637 $this->context->setObjId($obj_id);
638 $this->context->setObjType($obj_type);
647 return $this->context->getObjId();
655 return $this->context->getObjType();
663 return $this->stacktrace;
671 $path = $this->structure->getRelativePathByName($a_class);
672 if (
null ===
$path) {
673 throw new ilCtrlException(
"Class '$a_class' cannot be found in the control structure.");
684 return $this->structure->getObjNameByName($a_class);
692 $path_info = pathinfo($a_class_path);
694 return substr($path_info[
'basename'], 6, -4);
702 $this->context->setTargetScript($a_target_script);
710 return $this->context->isAsync();
716 public function setReturn(
object $a_gui_obj,
string $a_cmd =
null): void
718 $this->setReturnByClass($this->getClassByObject($a_gui_obj), $a_cmd);
726 $this->structure->setReturnTargetByClass(
728 $this->getLinkTargetByClass(
740 $class_name = $this->getClassByObject($a_gui_obj);
741 $target_url = $this->getParentReturnByClass($class_name);
744 $target_url = $this->appendParameterString(
746 self::PARAM_REDIRECT,
751 if (
null !== $a_anchor) {
752 $target_url .=
"#$a_anchor";
755 $this->redirectToURL($target_url);
763 return $this->getParentReturnByClass($this->getClassByObject($a_gui_obj));
771 $path = $this->path_factory->find($this->context, $a_class);
772 if (
null !==
$path->getCidPath()) {
773 foreach (
$path->getCidArray() as $cid) {
774 $current_class = $this->structure->getClassNameByCid($cid);
775 $return_target = $this->structure->getReturnTargetByClass($current_class);
776 if (
null !== $return_target) {
777 return $return_target;
790 return $this->context->getRedirectSource();
798 throw new ilCtrlException(__METHOD__ .
" is deprecated and must not be used.");
806 $class_cid = $this->structure->getClassCidByName($gui_class);
807 if (
null === $class_cid) {
812 $this->context->getPath()->getCidPath() ??
'',
822 if (
null === $this->context->getPath()->getCidPath()) {
827 foreach ($this->context->getPath()->getCidArray(SORT_ASC) as $cid) {
828 $class_paths[] = $this->structure->getObjNameByCid($cid);
842 if ($this->get_parameters->has($parameter_name)) {
843 return $this->get_parameters->retrieve(
857 if ($this->post_parameters->has(
'table_top_cmd')) {
858 return $this->post_parameters->retrieve(
861 return is_array($item) ? key($item) :
null;
866 if ($this->post_parameters->has(
'select_cmd2')) {
867 return $this->post_parameters->has(
'selected_cmd2')
868 ? $this->post_parameters->retrieve(
'selected_cmd2', $this->
refinery->to()->string())
872 if ($this->post_parameters->has(
'select_cmd')) {
873 return $this->post_parameters->has(
'selected_cmd')
874 ? $this->post_parameters->retrieve(
'selected_cmd', $this->
refinery->to()->string())
887 if ($this->post_parameters->has(self::PARAM_CMD)) {
888 return $this->post_parameters->retrieve(
890 $this->
refinery->custom()->transformation(
892 if (!empty($value)) {
893 if (is_array($value)) {
898 return (
string) array_key_first($value);
901 return (
string) $value;
927 string $a_cmd =
null,
928 string $a_anchor =
null,
929 bool $is_async =
false,
930 bool $is_escaped =
false,
931 bool $is_post =
false
933 if (empty($a_class)) {
934 throw new ilCtrlException(__METHOD__ .
" was provided with an empty class or class-array.");
937 $is_array = is_array($a_class);
939 $path = $this->path_factory->find($this->context, $a_class);
940 if (
null !== ($exception =
$path->getException())) {
944 $base_class =
$path->getBaseClass();
945 if (
null === $base_class) {
946 throw new ilCtrlException(
"Cannot find a valid baseclass in the cid path '{$path->getCidPath()}'");
949 $target_url = $this->context->getTargetScript();
950 $target_url = $this->appendParameterString(
952 self::PARAM_BASE_CLASS,
953 urlencode($base_class),
957 $cmd_class = ($is_array) ?
958 $a_class[array_key_last($a_class)] :
963 if (
null !==
$path->getNextCid($base_class)) {
964 $target_url = $this->appendParameterString(
966 self::PARAM_CID_PATH,
971 $target_url = $this->appendParameterString(
973 self::PARAM_CMD_CLASS,
974 urlencode($cmd_class),
982 $target_url = $this->appendParameterString(
992 if (!empty($a_cmd)) {
993 $target_url = $this->appendParameterString(
995 ($is_post) ? self::PARAM_CMD_FALLBACK : self::PARAM_CMD,
1003 foreach (
$path->getCidArray(SORT_ASC) as $cid) {
1004 $class_name = $this->structure->getClassNameByCid($cid);
1005 if (
null === $class_name) {
1006 throw new ilCtrlException(
"Classname for cid '$cid' in current path cannot be found.");
1009 $target_url = $this->appendParameterStringsByClass(
1018 if (!$this->isCmdSecure($is_post, $cmd_class, $a_cmd)) {
1019 $token = $this->token_repository->getToken();
1020 $target_url = $this->appendParameterString(
1022 self::PARAM_CSRF_TOKEN,
1029 $target_url = $this->appendParameterString(
1031 self::PARAM_CMD_MODE,
1032 self::CMD_MODE_ASYNC,
1037 if (!empty($a_anchor)) {
1038 $target_url .=
"#$a_anchor";
1050 private function modifyUrlWithPluginHooks(
string $target_url): string
1052 $ui_plugins = $this->component_factory->getActivePluginsInSlot(
"uihk");
1053 foreach ($ui_plugins as $plugin_instance) {
1056 $html = $plugin_instance
1057 ->getUIClassInstance()
1059 'Services/Utilities',
1061 [
"html" => $target_url]
1065 $target_url = $plugin_instance
1066 ->getUIClassInstance()
1084 private function isCmdSecure(
bool $is_post,
string $cmd_class,
string $cmd =
null): bool
1088 if (
null === $cmd) {
1095 $obj_name = $this->structure->getObjNameByName($cmd_class);
1096 if (
null === $obj_name) {
1103 if (!is_a($obj_name, ilCtrlSecurityInterface::class,
true)) {
1110 return in_array($cmd, $this->structure->getSafeCommandsByName($cmd_class),
true);
1115 return !in_array($cmd, $this->structure->getUnsafeCommandsByName($cmd_class),
true);
1129 bool $is_escaped =
false
1131 $class_parameters = $this->getParameterArrayByClass($class_name);
1132 if (!empty($class_parameters)) {
1133 foreach ($class_parameters as
$key => $value) {
1134 $target_url = $this->appendParameterString(
1154 private function appendParameterString(
1156 string $parameter_name,
1158 bool $is_escaped =
false
1162 $value = $this->
refinery->kindlyTo()->string()->transform($value ??
'');
1164 if (
'' === $value) {
1169 $parsed_url = parse_url(str_replace(
'&',
'&',
$url));
1171 $query_parameters = $this->query_parser->parseQueriesOfURL($parsed_url[
'query'] ??
'');
1174 $query_parameters[$parameter_name] = $value;
1176 $new_url = $parsed_url[
'path'] ?? $this->context->getTargetScript();
1178 $ampersand = ($is_escaped) ?
'&' :
'&';
1180 foreach ($query_parameters as $parameter => $parameter_value) {
1181 $new_url .= (strpos($new_url,
'?') !==
false) ?
1182 $ampersand .
"$parameter=$parameter_value" :
1183 "?$parameter=$parameter_value";
1196 $obj_name = $this->structure->getObjNameByName($class_name);
1198 $this->stacktrace[] = [
1199 self::PARAM_CMD_CLASS => $obj_name,
1200 self::PARAM_CMD_MODE => $cmd_mode,
1201 self::PARAM_CMD => $this->getCmd(),
1213 return (is_object($object)) ? get_class($object) : $object;
static return function(ContainerConfigurator $containerConfigurator)
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.
getCallHistory()
@inheritDoc
isCmdSecure(bool $is_post, string $cmd_class, string $cmd=null)
Returns whether a given command is considered safe or not.
setCmdClass($a_cmd_class)
@inheritDoc
getClassForClasspath(string $a_class_path)
@inheritDoc
insertCtrlCalls($a_parent, $a_child, string $a_comp_prefix)
@inheritDoc
getPostCommand()
Returns the current $_POST command.
setCmd(?string $a_cmd)
@inheritDoc
getContextObjId()
@inheritDoc
getHTML(object $a_gui_object, array $a_parameters=null)
@inheritDoc
setContextObject(int $obj_id, string $obj_type)
@inheritDoc
saveParameterByClass(string $a_class, $a_parameter)
@inheritDoc
getLinkTargetByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
lookupClassPath(string $a_class)
@inheritDoc
getParameterArrayByClass(string $a_class)
@inheritDoc
RequestWrapper $get_parameters
redirectToURL(string $target_url)
@inheritDoc
setReturnByClass(string $a_class, string $a_cmd=null)
@inheritDoc
ilComponentFactory $component_factory
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
ResponseSenderStrategy $response_sender
getQueryParam(string $parameter_name)
Returns a parameter with the given name from the current GET request.
ilCtrlContextInterface $context
returnToParent(object $a_gui_obj, string $a_anchor=null)
@inheritDoc
getFormActionByClass( $a_class, string $a_fallback_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
getNextClass($a_gui_class=null)
@inheritDoc
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
getRedirectSource()
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
RequestWrapper $post_parameters
setReturn(object $a_gui_obj, string $a_cmd=null)
@inheritDoc
clearParameters(object $a_gui_obj)
@inheritDoc
saveParameter(object $a_gui_obj, $a_parameter)
@inheritDoc
setTargetScript(string $a_target_script)
@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.
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
ilCtrlQueryParserInterface $query_parser
getParentReturnByClass(string $a_class)
@inheritDoc
clearParameterByClass(string $a_class, string $a_parameter)
@inheritDoc
ServerRequestInterface $server_request
getCmd(string $fallback_command=null)
@inheritDoc
appendParameterStringsByClass(string $class_name, string $target_url, bool $is_escaped=false)
Appends all parameters for a given class to the given URL.
ilCtrlStructureInterface $structure
ilCtrlTokenRepositoryInterface $token_repository
ilCtrlPathFactoryInterface $path_factory
__construct(ilCtrlStructureInterface $structure, ilCtrlTokenRepositoryInterface $token_repository, ilCtrlPathFactoryInterface $path_factory, ilCtrlContextInterface $context, ResponseSenderStrategy $response_sender, ServerRequestInterface $server_request, RequestWrapper $post_parameters, RequestWrapper $get_parameters, Refinery $refinery, ilComponentFactory $component_factory, ilCtrlQueryParserInterface $query_parser)
ilCtrl Constructor
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@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
forwardCommand(object $a_gui_object)
@inheritDoc
setParameterByClass(string $a_class, string $a_parameter, $a_value)
@inheritDoc
getParameterArray(object $a_gui_obj)
@inheritDoc
callBaseClass(string $a_base_class=null)
@inheritDoc
lookupOriginalClassName(string $a_class)
@inheritDoc
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
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...
Interface ilCtrlPathFactoryInterface describes the ilCtrl Path factory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilCtrlTokenRepositoryInterface describes an ilCtrl token.