/** * Get data from source * * @param mixed $options some options for source * * @return string some data, whitch web server returns */ public function getData($options = null) { if ($this->isAvailable()) { if ($curl = $this->init()) { App::log()->addDebug('GET ' . $this->conf->url); //Settings of curl curl_setopt($curl, CURLOPT_URL, $this->conf->url); curl_setopt($curl, CURLOPT_PORT, $this->conf->port); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // use POST method curl_setopt($curl, CURLOPT_POST, true); // send JSON data curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($options)); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $out = curl_exec($curl); // if something wrong returning FALSE if (curl_errno($curl)) { App::log()->addError('Http error: ' . curl_error($curl)); return false; } $httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($httpcode != 200) { $this->isavailable = false; App::log()->addError('Http finished with code: ' . $httpcode); throw new SourceException('Server error ' . $httpcode, 2); } return $out; } else { $this->isavailable = false; App::log()->addError('Curl initialize error'); throw new SourceException('Can\'t initialize CURL', 1); } } return false; }