ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilSoapExceptionHandler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 class ilSoapExceptionHandler extends \Whoops\Handler\Handler
22 {
23  private function buildFaultString(): string
24  {
25  if (!defined('DEVMODE') || DEVMODE !== 1) {
26  return htmlspecialchars($this->getInspector()->getException()->getMessage());
27  }
28 
29  $fault_string = \Whoops\Exception\Formatter::formatExceptionPlain($this->getInspector());
30  $exception = $this->getInspector()->getException();
31  $previous = $exception->getPrevious();
32  while ($previous) {
33  $fault_string .= "\n\nCaused by\n" . $this->getSimpleExceptionOutput($previous);
34  $previous = $previous->getPrevious();
35  }
36 
37  return htmlspecialchars($fault_string);
38  }
39 
40  private function getSimpleExceptionOutput(Throwable $exception): string
41  {
42  return sprintf(
43  '%s: %s in file %s on line %d',
44  get_class($exception),
45  $exception->getMessage(),
46  $exception->getFile(),
47  $exception->getLine()
48  );
49  }
50 
51  public function handle(): ?int
52  {
53  echo $this->toXml();
54 
55  return \Whoops\Handler\Handler::QUIT;
56  }
57 
58  private function toXml(): string
59  {
60  $fault_code = htmlspecialchars((string) $this->getInspector()->getException()->getCode());
61  $fault_string = $this->buildFaultString();
62 
63  $xml = '<?xml version="1.0" encoding="UTF-8"?>';
64  $xml .= '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">';
65  $xml .= ' <SOAP-ENV:Body>';
66  $xml .= ' <SOAP-ENV:Fault>';
67  $xml .= ' <faultcode>' . $fault_code . '</faultcode>';
68  $xml .= ' <faultstring>' . $fault_string . '</faultstring>';
69  $xml .= ' </SOAP-ENV:Fault>';
70  $xml .= ' </SOAP-ENV:Body>';
71  $xml .= '</SOAP-ENV:Envelope>';
72 
73  return $xml;
74  }
75 }
getSimpleExceptionOutput(Throwable $exception)