Merge pull request #6 from assertchris/php-5-3-compat

Downgraded Guzzle version
This commit is contained in:
Damian Mooyman 2015-03-05 14:11:11 +13:00
commit fb70c1dd50
2 changed files with 14 additions and 22 deletions

View File

@ -1,16 +1,10 @@
<?php <?php
use GuzzleHttp\Client; use Guzzle\Http\Client;
use GuzzleHttp\Exception\RequestException; use Guzzle\Http\Exception\RequestException;
class TikaRestClient extends Client { class TikaRestClient extends Client {
public function __construct($url) {
parent::__construct(array(
'base_url' => $url
));
}
/** /**
* Detect if the service is available * Detect if the service is available
* *
@ -19,7 +13,7 @@ class TikaRestClient extends Client {
public function isAvailable() { public function isAvailable() {
try { try {
return $this return $this
->get() ->get()->send()
->getStatusCode() == 200; ->getStatusCode() == 200;
} catch (RequestException $ex) { } catch (RequestException $ex) {
return false; return false;
@ -32,10 +26,10 @@ class TikaRestClient extends Client {
* @return float * @return float
*/ */
public function getVersion() { public function getVersion() {
$response = $this->get('version'); $response = $this->get('version')->send();
// Parse output // Parse output
if($response->getStatusCode() == 200 && if($response->getStatusCode() == 200 &&
preg_match('/Apache Tika (?<version>[\.\d]+)/', $response->getBody()->getContents(), $matches) preg_match('/Apache Tika (?<version>[\.\d]+)/', $response->getBody(), $matches)
) { ) {
return (float)$matches['version']; return (float)$matches['version'];
} }
@ -55,10 +49,9 @@ class TikaRestClient extends Client {
$response = $this->get( $response = $this->get(
'mime-types', 'mime-types',
array( array('Accept' => 'application/json')
'headers' => array("Accept" => "application/json") )->send();
)
);
return $this->mimes = $response->json(); return $this->mimes = $response->json();
} }
@ -71,12 +64,11 @@ class TikaRestClient extends Client {
public function tika($file) { public function tika($file) {
$response = $this->put( $response = $this->put(
'tika', 'tika',
array( array('Accept' => 'text/plain'),
'body' => file_get_contents($file), file_get_contents($file)
'headers' => array("Accept" => "text/plain") )->send();
)
); return $response->getBody(true);
return $response->getBody()->getContents();
} }
} }

View File

@ -19,7 +19,7 @@
"php": ">=5.3.2", "php": ">=5.3.2",
"composer/installers": "*", "composer/installers": "*",
"silverstripe/framework": "~3.1", "silverstripe/framework": "~3.1",
"guzzlehttp/guzzle": "~4.0" "guzzle/guzzle": "~3.9"
}, },
"require-dev": { "require-dev": {
"phpunit/PHPUnit": "~3.7@stable" "phpunit/PHPUnit": "~3.7@stable"