ILIAS  release_8 Revision v8.24
class.ilMathJaxServer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
28
33 {
34 $this->config = $config;
35 }
36
43 public function call(array $options): string
44 {
45 $curl = curl_init($this->config->getServerAddress());
46 curl_setopt($curl, CURLOPT_HEADER, false);
47 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
48 curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
49 curl_setopt($curl, CURLOPT_POST, true);
50 curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($options, JSON_THROW_ON_ERROR));
51 curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getServerTimeout());
52
53 $response = (string) curl_exec($curl);
54 $status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
55 curl_close($curl);
56
57 if ($status !== 200) {
58 $lines = explode("\n", $response);
59 if (isset($lines[1])) {
60 throw new ilMathJaxException($lines[1]);
61 }
62 throw new ilMathJaxException('curl server call failed');
63 }
64 return $response;
65 }
66}
Global Mathjax configuration.
Class for calling theMathJax server The server calls use cURL, if the extension is loaded,...
ilMathJaxConfig $config
call(array $options)
Call the mathjax server.
__construct(ilMathJaxConfig $config)
Constructor.
$response