ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.Server.php
Go to the documentation of this file.
1 <?php
2 
20 
35 
41 class Server
42 {
43  protected \ilPageObjectGUI $page_gui;
44  protected \ILIAS\DI\UIServices $ui;
45  protected Message\ServerRequestInterface $request;
46  protected \ilLogger $log;
47 
48  public function __construct(
49  \ilPageObjectGUI $page_gui,
50  \ILIAS\DI\UIServices $ui,
51  Message\ServerRequestInterface $request
52  ) {
53  $this->request = $request;
54  $this->ui = $ui;
55  $this->page_gui = $page_gui;
56  $this->log = \ilLoggerFactory::getLogger('copg');
57  }
58 
59  public function reply(): void
60  {
61  $this->log->debug("Start replying...");
62  $query = $this->request->getQueryParams();
63  $post = $this->request->getParsedBody();
64 
65  try {
66  if (isset($post) && is_array($post) && count($post) > 0) {
67  $body = $post;
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  }
86  $response = new Response($data);
87  }
88 
89  $this->log->debug("... sending response");
90  $response->send();
91  }
92 
93  protected function getActionHandlerForQuery(
94  array $query
96  $handler = null;
97 
98  switch ($query["component"]) {
99  case "Page":
100  $handler = new \ILIAS\COPage\Page\PageQueryActionHandler($this->page_gui, $query["pc_id"] ?? "");
101  break;
102  case "InteractiveImage":
103  $handler = new \ILIAS\COPage\PC\InteractiveImage\InteractiveImageQueryActionHandler($this->page_gui, $query["pc_id"] ?? "");
104  break;
105  }
106 
107  if ($handler === null) {
108  throw new Exception("Unknown Component " . ((string) $query["component"]));
109  }
110  return $handler;
111  }
112 
113  protected function getActionHandlerForCommand(
114  array $query,
115  array $body
117  $handler = null;
118 
119  switch ($body["component"]) {
120  case "Paragraph":
121  $handler = new ParagraphCommandActionHandler($this->page_gui);
122  break;
123  case "Page":
124  $handler = new PageCommandActionHandler($this->page_gui);
125  break;
126  case "Grid":
127  $handler = new GridCommandActionHandler($this->page_gui);
128  break;
129  case "Tabs":
130  $handler = new TabsCommandActionHandler($this->page_gui);
131  break;
132  case "Section":
133  $handler = new SectionCommandActionHandler($this->page_gui);
134  break;
135  case "MediaObject":
136  $handler = new MediaObjectCommandActionHandler($this->page_gui);
137  break;
138  case "Table":
139  case "DataTable":
140  $handler = new TableCommandActionHandler($this->page_gui);
141  break;
142  case "Resources":
143  $handler = new ResourcesCommandActionHandler($this->page_gui);
144  break;
145  case "SourceCode":
146  $handler = new SourceCodeCommandActionHandler($this->page_gui);
147  break;
148  case "InteractiveImage":
149  $handler = new InteractiveImageCommandActionHandler($this->page_gui);
150  break;
151  case "LayoutTemplate":
152  $handler = new LayoutTemplateCommandActionHandler($this->page_gui);
153  break;
154  case "PlaceHolder":
155  $handler = new PlaceHolderCommandActionHandler($this->page_gui);
156  break;
157  }
158 
159  if ($handler === null) {
160  throw new Exception("Unknown component " . ((string) $body["component"]));
161  }
162  return $handler;
163  }
164 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
getActionHandlerForCommand(array $query, array $body)
Interface Observer Contains several chained tasks and infos about them.
Class ilPageObjectGUI.
$response
Definition: xapitoken.php:93
__construct(\ilPageObjectGUI $page_gui, \ILIAS\DI\UIServices $ui, Message\ServerRequestInterface $request)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Page editor json server.
Class HTTPServicesTest.
Message ServerRequestInterface $request
$handler
Definition: oai.php:29
$post
Definition: ltitoken.php:46