ILIAS  release_8 Revision v8.24
ilMathJaxServer Class Reference

Class for calling theMathJax server The server calls use cURL, if the extension is loaded, otherwise allow_url_fopen must be set in the php.ini. More...

+ Collaboration diagram for ilMathJaxServer:

Public Member Functions

 __construct (ilMathJaxConfig $config)
 Constructor. More...
 
 call (array $options)
 Call the mathjax server. More...
 

Protected Attributes

ilMathJaxConfig $config
 

Detailed Description

Class for calling theMathJax server The server calls use cURL, if the extension is loaded, otherwise allow_url_fopen must be set in the php.ini.

Definition at line 25 of file class.ilMathJaxServer.php.

Constructor & Destructor Documentation

◆ __construct()

ilMathJaxServer::__construct ( ilMathJaxConfig  $config)

Constructor.

Definition at line 32 of file class.ilMathJaxServer.php.

33 {
34 $this->config = $config;
35 }
ilMathJaxConfig $config

References $config.

Member Function Documentation

◆ call()

ilMathJaxServer::call ( array  $options)

Call the mathjax server.

Parameters
array$optionswill be sent json encoded to the server
Returns
string
Exceptions
ilMathJaxException

Definition at line 43 of file class.ilMathJaxServer.php.

43 : 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 }
$response

References $response.

Field Documentation

◆ $config

ilMathJaxConfig ilMathJaxServer::$config
protected

Definition at line 27 of file class.ilMathJaxServer.php.

Referenced by __construct().


The documentation for this class was generated from the following file: