You are here

public function JsonFileResponse::__construct in Helper 8

Parameters

string $uri: The URI containing an encoded JSON string.

int $status: The status.

array $headers: The headers.

mixed $version: The version.

bool $reason: The reason.

File

src/Response/JsonFileResponse.php, line 31

Class

JsonFileResponse
A JSON PSR-7 response implementation.

Namespace

Drupal\helper\Response

Code

public function __construct($uri, $status = 200, array $headers = [], $version = '1.1', $reason = NULL) {
  if (!is_file($uri)) {
    throw new \InvalidArgumentException("URI {$uri} is not a file.");
  }
  if (!is_readable($uri)) {
    throw new \InvalidArgumentException("URI {$uri} is not readable.");
  }
  $body = fopen($uri, 'r');
  $headers += [
    'Content-Type' => 'application/json',
  ];
  parent::__construct($status, $headers, $body, $version, $reason);
}