Skip to content
This repository was archived by the owner on Jan 29, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/EntryPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class EntryPoint

protected $client;

/**
* @var string Default content type
*/
protected static $content_type = 'application/hal+json';

/**
* @var Resource
*/
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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;
}
}