summaryrefslogtreecommitdiff
path: root/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/FileGetContents.php
diff options
context:
space:
mode:
authorLoic GUEGAN <loic@Manzerbredes.home>2016-04-16 19:10:27 +0200
committerLoic GUEGAN <loic@Manzerbredes.home>2016-04-16 19:10:27 +0200
commita3ff4d243e2ac37d4516ae56ff86985eadc00eb8 (patch)
tree32e71c42855cc46d95d9c6b74ad2c145eb9ec7eb /server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/FileGetContents.php
parent396c90f921c30de2d15d2ce52d5d1beabf8eb52d (diff)
parent31d2d0c158ad4daa3dde7a905f3c2e312c194f2e (diff)
Test
Diffstat (limited to 'server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/FileGetContents.php')
-rwxr-xr-xserver/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/FileGetContents.php87
1 files changed, 0 insertions, 87 deletions
diff --git a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/FileGetContents.php b/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/FileGetContents.php
deleted file mode 100755
index bc43de6..0000000
--- a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/FileGetContents.php
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php
-
-/*
- * This file is part of the JsonSchema package.
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace JsonSchema\Uri\Retrievers;
-
-use JsonSchema\Exception\ResourceNotFoundException;
-use JsonSchema\Validator;
-
-/**
- * Tries to retrieve JSON schemas from a URI using file_get_contents()
- *
- * @author Sander Coolen <sander@jibber.nl>
- */
-class FileGetContents extends AbstractRetriever
-{
- protected $messageBody;
-
- /**
- * {@inheritDoc}
- * @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve()
- */
- public function retrieve($uri)
- {
- $context = stream_context_create(array(
- 'http' => array(
- 'method' => 'GET',
- 'header' => "Accept: " . Validator::SCHEMA_MEDIA_TYPE
- )));
-
- set_error_handler(function() use ($uri) {
- throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
- });
- $response = file_get_contents($uri);
- restore_error_handler();
-
- if (false === $response) {
- throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
- }
- if ($response == ''
- && substr($uri, 0, 7) == 'file://' && substr($uri, -1) == '/'
- ) {
- throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
- }
-
- $this->messageBody = $response;
- if (! empty($http_response_header)) {
- $this->fetchContentType($http_response_header);
- } else {
- // Could be a "file://" url or something else - fake up the response
- $this->contentType = null;
- }
-
- return $this->messageBody;
- }
-
- /**
- * @param array $headers HTTP Response Headers
- * @return boolean Whether the Content-Type header was found or not
- */
- private function fetchContentType(array $headers)
- {
- foreach ($headers as $header) {
- if ($this->contentType = self::getContentTypeMatchInHeader($header)) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * @param string $header
- * @return string|null
- */
- protected static function getContentTypeMatchInHeader($header)
- {
- if (0 < preg_match("/Content-Type:(\V*)/ims", $header, $match)) {
- return trim($match[1]);
- }
- }
-}