/** * Returns core status info. * * @param string $core Name of the core to return the status for, or null * to return status for all cores. */ public function status($core = null) { $query = ["action" => "STATUS", "wt" => "json"]; if (isset($core)) { $query['core'] = $core; } $path = "admin/cores?" . http_build_query($query); $response = $this->get($path); $contents = $response->getBody()->getContents(); return Json::decode($contents, true); }
private function importFile(Client $client, $core, SplFileInfo $source, $output) { $output->writeln("Importing data from: <info>{$source}</info>"); $fp = fopen($source, 'r'); $path = "{$core}/update?" . http_build_query(['commit' => 'true', 'wt' => 'json']); $headers = ['Content-Type' => 'application/json']; $response = $client->post($path, $fp, $headers); $contents = $response->getBody()->getContents(); $reply = Json::decode($contents); if ($reply->responseHeader->status != 0) { throw new \Exception("Solr returned an error."); } $time = $reply->responseHeader->QTime; $output->writeln("Time taken: <comment>{$time} ms</comment>\n"); }
/** * @expectedException Exception * @expectedExceptionMessage Failed decoding JSON */ public function testDecodeError() { // Invalid JSON Json::decode('xxx'); }
/** * Pings the server to check it's there. * * @return array Decoded response from the Solr server. */ public function ping() { $path = implode('/', [$this->name, $this->pingHandler]); $path = "{$path}?wt=json"; $response = $this->client->get($path); $contents = $response->getBody()->getContents(); return Json::decode($contents, true); }