/** * 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; }
function init($name) { $a = App::getConf(); if (isset($a->db->{$name})) { $this->conf = $a->db->{$name}; } $this->db = new \Mysqli($this->conf->host, $this->conf->login, $this->conf->password, $this->conf->dbname); if ($this->db->connect_errno) { // echo $mysqli->connect_error.PHP_EOL; return false; } return true; }
<?php define('ROOT_PATH', dirname(__FILE__) . '/'); use Netwerwen\Test\VacancyRepository; use Netwerwen\Test\App; use Netwerwen\Test\VacancyExt; include_once 'autoloader.php'; require __DIR__ . '/vendor/autoload.php'; App::setConfFile('config.json'); $vr = new VacancyRepository(); /* $res = $vr->getData('res1'); var_dump($res); $res = $vr->getData('res3'); var_dump($res); $res = $vr->getData('http1'); if ($res === false) { echo "Error while get resorse, please check log\n"; } else { print_r($res); } // */ // $data = $vr->getData(); // print_r($data); // use Netwerwen\Test\Storage\Sphinx; // $sp = new Sphinx(); // $res = $sp->find('kasper'); //$res = $vr->getData('local','kasper');