From aebb874b92b4f83b334b957c0293a75a90d9fb36 Mon Sep 17 00:00:00 2001 From: Florian Wagner Date: Wed, 10 Aug 2016 17:20:47 +0200 Subject: [PATCH] Made the mime type configureable. It was causing issues with pure "application/json" i.e. --- lib/EntryPoint.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/EntryPoint.php b/lib/EntryPoint.php index 6b4e8dc..c7c1246 100644 --- a/lib/EntryPoint.php +++ b/lib/EntryPoint.php @@ -22,6 +22,11 @@ class EntryPoint protected $client; + /** + * @var string Default content type + */ + protected static $content_type = 'application/hal+json'; + /** * @var Resource */ @@ -51,7 +56,7 @@ public function __construct($url, HttpClientInterface $client, array $headers = */ public static function parse(HttpResponse $response, HttpClientInterface $client) { - if (substr($response->getHeader('Content-Type'), 0, 20) !== 'application/hal+json') { + if (substr($response->getHeader('Content-Type'), 0, 20) !== self::$content_type ) { throw new \RuntimeException('Invalid content type'); } @@ -91,4 +96,20 @@ protected function initialize() $this->resource = static::parse($this->client->get($this->url), $this->client); } + + /** + * Set the default content type to check in parse method + * + * @param $content_type + * @return bool + * @todo Check if string is a valid content type + */ + public static function setDefaultContentType ($content_type) + { + if ($content_type){ + self::$content_type = $content_type; + return true; + } + return false; + } }