ILIAS  release_7 Revision v7.30-3-g800a261c036
class.Server.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
7use \Psr\Http\Message;
15
21class Server
22{
26 protected $log;
30 protected $page_gui;
31
35 protected $ui;
36
37
41 protected $request;
42
46 public function __construct(
48 \ILIAS\DI\UIServices $ui,
49 Message\ServerRequestInterface $request
50 ) {
51 $this->request = $request;
52 $this->ui = $ui;
53 $this->page_gui = $page_gui;
54 $this->log = \ilLoggerFactory::getLogger('copg');
55 }
56
60 public function reply()
61 {
62 $this->log->debug("Start replying...");
63 $query = $this->request->getQueryParams();
64
65 try {
66 if (is_array($_POST) && count($_POST) > 0) {
67 $body = $this->request->getParsedBody();
68 } else {
69 $body = json_decode($this->request->getBody()->getContents(), true);
70 }
71 if (isset($query["component"])) {
72 $action_handler = $this->getActionHandlerForQuery($query);
73 $response = $action_handler->handle($query);
74 } else {
75 //sleep(5);
76 $action_handler = $this->getActionHandlerForCommand($query, $body);
77 $response = $action_handler->handle($query, $body);
78 }
79 } catch (Exception $e) {
80 $data = new \stdClass();
81 $this->log->error($e->getMessage()."\n".$e->getTraceAsString());
82 $data->error = $e->getMessage();
83 if (defined('DEVMODE') && DEVMODE) {
84 $data->error.= "<br><br>".nl2br($e->getTraceAsString());
85 }
87 }
88
89 $this->log->debug("... sending response");
90 $response->send();
91 }
92
98 protected function getActionHandlerForQuery($query)
99 {
100 $handler = null;
101
102 switch ($query["component"]) {
103 case "Page":
104 $handler = new Page\PageQueryActionHandler($this->page_gui);
105 break;
106 }
107
108 if ($handler === null) {
109 throw new Exception("Unknown Action " . ((string) $query));
110 }
111 return $handler;
112 }
113
119 protected function getActionHandlerForCommand($query, $body)
120 {
121 $handler = null;
122
123 switch ($body["component"]) {
124 case "Paragraph":
125 $handler = new Paragraph\ParagraphCommandActionHandler($this->page_gui);
126 break;
127 case "Page":
128 $handler = new Page\PageCommandActionHandler($this->page_gui);
129 break;
130 case "Grid":
131 $handler = new Grid\GridCommandActionHandler($this->page_gui);
132 break;
133 case "Section":
134 $handler = new Section\SectionCommandActionHandler($this->page_gui);
135 break;
136 case "MediaObject":
137 $handler = new MediaObject\MediaObjectCommandActionHandler($this->page_gui);
138 break;
139 case "Table":
140 $handler = new Table\TableCommandActionHandler($this->page_gui);
141 break;
142 }
143
144 if ($handler === null) {
145 throw new Exception("Unknown component " . ((string) $body["component"]));
146 }
147 return $handler;
148 }
149}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Page editor json server.
__construct(\ilPageObjectGUI $page_gui, \ILIAS\DI\UIServices $ui, Message\ServerRequestInterface $request)
Constructor.
getActionHandlerForQuery($query)
Get action handler for query.
getActionHandlerForCommand($query, $body)
Get action handler for query.
static getLogger($a_component_id)
Get component logger.
Class ilPageObjectGUI.
Class HTTPServicesTest.
Class ChatMainBarProvider \MainMenu\Provider.
$query
$response
$data
Definition: storeScorm.php:23
ui()
Definition: ui.php:5