ILIAS  release_8 Revision v8.24
class.Server.php
Go to the documentation of this file.
1<?php
2
20
21use Psr\Http\Message;
29
35class Server
36{
37 protected \ilPageObjectGUI $page_gui;
38 protected \ILIAS\DI\UIServices $ui;
39 protected Message\ServerRequestInterface $request;
40 protected \ilLogger $log;
41
42 public function __construct(
44 \ILIAS\DI\UIServices $ui,
45 Message\ServerRequestInterface $request
46 ) {
47 $this->request = $request;
48 $this->ui = $ui;
49 $this->page_gui = $page_gui;
50 $this->log = \ilLoggerFactory::getLogger('copg');
51 }
52
53 public function reply(): void
54 {
55 $this->log->debug("Start replying...");
56 $query = $this->request->getQueryParams();
57 $post = $this->request->getParsedBody();
58
59 try {
60 if (isset($post) && is_array($post) && count($post) > 0) {
61 $body = $post;
62 } else {
63 $body = json_decode($this->request->getBody()->getContents(), true);
64 }
65 if (isset($query["component"])) {
66 $action_handler = $this->getActionHandlerForQuery($query);
67 $response = $action_handler->handle($query);
68 } else {
69 //sleep(5);
70 $action_handler = $this->getActionHandlerForCommand($query, $body);
71 $response = $action_handler->handle($query, $body);
72 }
73 } catch (Exception $e) {
74 $data = new \stdClass();
75 $this->log->error($e->getMessage() . "\n" . $e->getTraceAsString());
76 $data->error = $e->getMessage();
77 if (defined('DEVMODE') && DEVMODE) {
78 $data->error .= "<br><br>" . nl2br($e->getTraceAsString());
79 }
81 }
82
83 $this->log->debug("... sending response");
84 $response->send();
85 }
86
87 protected function getActionHandlerForQuery(
88 array $query
90 $handler = null;
91
92 switch ($query["component"]) {
93 case "Page":
94 $handler = new Page\PageQueryActionHandler($this->page_gui);
95 break;
96 }
97
98 if ($handler === null) {
99 throw new Exception("Unknown Component " . ((string) $query["component"]));
100 }
101 return $handler;
102 }
103
104 protected function getActionHandlerForCommand(
105 array $query,
106 array $body
108 $handler = null;
109
110 switch ($body["component"]) {
111 case "Paragraph":
112 $handler = new Paragraph\ParagraphCommandActionHandler($this->page_gui);
113 break;
114 case "Page":
115 $handler = new Page\PageCommandActionHandler($this->page_gui);
116 break;
117 case "Grid":
118 $handler = new Grid\GridCommandActionHandler($this->page_gui);
119 break;
120 case "Section":
121 $handler = new Section\SectionCommandActionHandler($this->page_gui);
122 break;
123 case "MediaObject":
124 $handler = new MediaObject\MediaObjectCommandActionHandler($this->page_gui);
125 break;
126 case "Table":
127 $handler = new Table\TableCommandActionHandler($this->page_gui);
128 break;
129 }
130
131 if ($handler === null) {
132 throw new Exception("Unknown component " . ((string) $body["component"]));
133 }
134 return $handler;
135 }
136}
Page editor json server.
__construct(\ilPageObjectGUI $page_gui, \ILIAS\DI\UIServices $ui, Message\ServerRequestInterface $request)
getActionHandlerForCommand(array $query, array $body)
Message ServerRequestInterface $request
static getLogger(string $a_component_id)
Get component logger.
Class ilPageObjectGUI.
$post
Definition: ltitoken.php:49
Class HTTPServicesTest.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
$query
$response