diff options
| author | EoleDev <EoleDev@outlook.fr> | 2016-04-14 16:24:44 +0200 |
|---|---|---|
| committer | EoleDev <EoleDev@outlook.fr> | 2016-04-14 16:24:44 +0200 |
| commit | 24bb5fefbdf93ce0969b7f56cc46c459ebb82a95 (patch) | |
| tree | 531fc8b774c035040774234efba780a3d4fe9242 /server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri | |
| parent | 646af6fd4d14c5b5edb1372e5f68ed9bdc35b3d2 (diff) | |
Mise a jour et nettoyage depot
Diffstat (limited to 'server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri')
7 files changed, 0 insertions, 727 deletions
diff --git a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/AbstractRetriever.php b/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/AbstractRetriever.php deleted file mode 100644 index f924ad8..0000000 --- a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/AbstractRetriever.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php -/** - * JsonSchema - * @filesource - */ -namespace JsonSchema\Uri\Retrievers; - -/** - * AbstractRetriever implements the default shared behavior - * that all decendant Retrievers should inherit - * @author Steven Garcia <webwhammy@gmail.com> - */ -abstract class AbstractRetriever implements UriRetrieverInterface -{ - /** - * Media content type - * @var string - */ - protected $contentType; - - /** - * {@inheritDoc} - * @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::getContentType() - */ - public function getContentType() - { - return $this->contentType; - } -} diff --git a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/Curl.php b/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/Curl.php deleted file mode 100644 index cd8414f..0000000 --- a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/Curl.php +++ /dev/null @@ -1,79 +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\Validator; - -/** - * Tries to retrieve JSON schemas from a URI using cURL library - * - * @author Sander Coolen <sander@jibber.nl> - */ -class Curl extends AbstractRetriever -{ - protected $messageBody; - - public function __construct() - { - if (!function_exists('curl_init')) { - throw new \RuntimeException("cURL not installed"); - } - } - - /** - * {@inheritDoc} - * @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve() - */ - public function retrieve($uri) - { - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_URL, $uri); - curl_setopt($ch, CURLOPT_HEADER, true); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: ' . Validator::SCHEMA_MEDIA_TYPE)); - - $response = curl_exec($ch); - if (false === $response) { - throw new \JsonSchema\Exception\ResourceNotFoundException('JSON schema not found'); - } - - $this->fetchMessageBody($response); - $this->fetchContentType($response); - - curl_close($ch); - - return $this->messageBody; - } - - /** - * @param string $response cURL HTTP response - */ - private function fetchMessageBody($response) - { - preg_match("/(?:\r\n){2}(.*)$/ms", $response, $match); - $this->messageBody = $match[1]; - } - - /** - * @param string $response cURL HTTP response - * @return boolean Whether the Content-Type header was found or not - */ - protected function fetchContentType($response) - { - if (0 < preg_match("/Content-Type:(\V*)/ims", $response, $match)) { - $this->contentType = trim($match[1]); - - return true; - } - - return false; - } -}
\ No newline at end of file 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 100644 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]); - } - } -} diff --git a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/PredefinedArray.php b/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/PredefinedArray.php deleted file mode 100644 index 7652c42..0000000 --- a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/PredefinedArray.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -namespace JsonSchema\Uri\Retrievers; - -use JsonSchema\Validator; - -/** - * URI retrieved based on a predefined array of schemas - * - * @example - * - * $retriever = new PredefinedArray(array( - * 'http://acme.com/schemas/person#' => '{ ... }', - * 'http://acme.com/schemas/address#' => '{ ... }', - * )) - * - * $schema = $retriever->retrieve('http://acme.com/schemas/person#'); - */ -class PredefinedArray extends AbstractRetriever -{ - /** - * Contains schemas as URI => JSON - * @var array - */ - private $schemas; - - /** - * Constructor - * - * @param array $schemas - * @param string $contentType - */ - public function __construct(array $schemas, $contentType = Validator::SCHEMA_MEDIA_TYPE) - { - $this->schemas = $schemas; - $this->contentType = $contentType; - } - - /** - * {@inheritDoc} - * @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve() - */ - public function retrieve($uri) - { - if (!array_key_exists($uri, $this->schemas)) { - throw new \JsonSchema\Exception\ResourceNotFoundException(sprintf( - 'The JSON schema "%s" was not found.', - $uri - )); - } - - return $this->schemas[$uri]; - } -} diff --git a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/UriRetrieverInterface.php b/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/UriRetrieverInterface.php deleted file mode 100644 index c324998..0000000 --- a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/UriRetrieverInterface.php +++ /dev/null @@ -1,32 +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; - -/** - * Interface for URI retrievers - * - * @author Sander Coolen <sander@jibber.nl> - */ -interface UriRetrieverInterface -{ - /** - * Retrieve a schema from the specified URI - * @param string $uri URI that resolves to a JSON schema - * @throws \JsonSchema\Exception\ResourceNotFoundException - * @return mixed string|null - */ - public function retrieve($uri); - - /** - * Get media content type - * @return string - */ - public function getContentType(); -}
\ No newline at end of file diff --git a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriResolver.php b/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriResolver.php deleted file mode 100644 index 9784114..0000000 --- a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriResolver.php +++ /dev/null @@ -1,157 +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; - -use JsonSchema\Exception\UriResolverException; - -/** - * Resolves JSON Schema URIs - * - * @author Sander Coolen <sander@jibber.nl> - */ -class UriResolver -{ - /** - * Parses a URI into five main components - * - * @param string $uri - * @return array - */ - public function parse($uri) - { - preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match); - - $components = array(); - if (5 < count($match)) { - $components = array( - 'scheme' => $match[2], - 'authority' => $match[4], - 'path' => $match[5] - ); - } - if (7 < count($match)) { - $components['query'] = $match[7]; - } - if (9 < count($match)) { - $components['fragment'] = $match[9]; - } - - return $components; - } - - /** - * Builds a URI based on n array with the main components - * - * @param array $components - * @return string - */ - public function generate(array $components) - { - $uri = $components['scheme'] . '://' - . $components['authority'] - . $components['path']; - - if (array_key_exists('query', $components)) { - $uri .= $components['query']; - } - if (array_key_exists('fragment', $components)) { - $uri .= '#' . $components['fragment']; - } - - return $uri; - } - - /** - * Resolves a URI - * - * @param string $uri Absolute or relative - * @param string $baseUri Optional base URI - * @return string Absolute URI - */ - public function resolve($uri, $baseUri = null) - { - if ($uri == '') { - return $baseUri; - } - - $components = $this->parse($uri); - $path = $components['path']; - - if (! empty($components['scheme'])) { - return $uri; - } - $baseComponents = $this->parse($baseUri); - $basePath = $baseComponents['path']; - - $baseComponents['path'] = self::combineRelativePathWithBasePath($path, $basePath); - if (isset($components['fragment'])) { - $baseComponents['fragment'] = $components['fragment']; - } - - return $this->generate($baseComponents); - } - - /** - * Tries to glue a relative path onto an absolute one - * - * @param string $relativePath - * @param string $basePath - * @return string Merged path - * @throws UriResolverException - */ - public static function combineRelativePathWithBasePath($relativePath, $basePath) - { - $relativePath = self::normalizePath($relativePath); - if ($relativePath == '') { - return $basePath; - } - if ($relativePath{0} == '/') { - return $relativePath; - } - - $basePathSegments = explode('/', $basePath); - - preg_match('|^/?(\.\./(?:\./)*)*|', $relativePath, $match); - $numLevelUp = strlen($match[0]) /3 + 1; - if ($numLevelUp >= count($basePathSegments)) { - throw new UriResolverException(sprintf("Unable to resolve URI '%s' from base '%s'", $relativePath, $basePath)); - } - - $basePathSegments = array_slice($basePathSegments, 0, -$numLevelUp); - $path = preg_replace('|^/?(\.\./(\./)*)*|', '', $relativePath); - - return implode('/', $basePathSegments) . '/' . $path; - } - - /** - * Normalizes a URI path component by removing dot-slash and double slashes - * - * @param string $path - * @return string - */ - private static function normalizePath($path) - { - $path = preg_replace('|((?<!\.)\./)*|', '', $path); - $path = preg_replace('|//|', '/', $path); - - return $path; - } - - /** - * @param string $uri - * @return boolean - */ - public function isValid($uri) - { - $components = $this->parse($uri); - - return !empty($components); - } -} diff --git a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriRetriever.php b/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriRetriever.php deleted file mode 100644 index c723cd9..0000000 --- a/server/vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriRetriever.php +++ /dev/null @@ -1,289 +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; - -use JsonSchema\Uri\Retrievers\FileGetContents; -use JsonSchema\Uri\Retrievers\UriRetrieverInterface; -use JsonSchema\Validator; -use JsonSchema\Exception\InvalidSchemaMediaTypeException; -use JsonSchema\Exception\JsonDecodingException; -use JsonSchema\Exception\ResourceNotFoundException; - -/** - * Retrieves JSON Schema URIs - * - * @author Tyler Akins <fidian@rumkin.com> - */ -class UriRetriever -{ - /** - * @var null|UriRetrieverInterface - */ - protected $uriRetriever = null; - - /** - * @var array|object[] - * @see loadSchema - */ - private $schemaCache = array(); - - /** - * Guarantee the correct media type was encountered - * - * @param UriRetrieverInterface $uriRetriever - * @param string $uri - * @return bool|void - */ - public function confirmMediaType($uriRetriever, $uri) - { - $contentType = $uriRetriever->getContentType(); - - if (is_null($contentType)) { - // Well, we didn't get an invalid one - return; - } - - if (Validator::SCHEMA_MEDIA_TYPE === $contentType) { - return; - } - - if (substr($uri, 0, 23) == 'http://json-schema.org/') { - //HACK; they deliver broken content types - return true; - } - - throw new InvalidSchemaMediaTypeException(sprintf('Media type %s expected', Validator::SCHEMA_MEDIA_TYPE)); - } - - /** - * Get a URI Retriever - * - * If none is specified, sets a default FileGetContents retriever and - * returns that object. - * - * @return UriRetrieverInterface - */ - public function getUriRetriever() - { - if (is_null($this->uriRetriever)) { - $this->setUriRetriever(new FileGetContents); - } - - return $this->uriRetriever; - } - - /** - * Resolve a schema based on pointer - * - * URIs can have a fragment at the end in the format of - * #/path/to/object and we are to look up the 'path' property of - * the first object then the 'to' and 'object' properties. - * - * @param object $jsonSchema JSON Schema contents - * @param string $uri JSON Schema URI - * @return object JSON Schema after walking down the fragment pieces - * - * @throws ResourceNotFoundException - */ - public function resolvePointer($jsonSchema, $uri) - { - $resolver = new UriResolver(); - $parsed = $resolver->parse($uri); - if (empty($parsed['fragment'])) { - return $jsonSchema; - } - - $path = explode('/', $parsed['fragment']); - while ($path) { - $pathElement = array_shift($path); - if (! empty($pathElement)) { - $pathElement = str_replace('~1', '/', $pathElement); - $pathElement = str_replace('~0', '~', $pathElement); - if (! empty($jsonSchema->$pathElement)) { - $jsonSchema = $jsonSchema->$pathElement; - } else { - throw new ResourceNotFoundException( - 'Fragment "' . $parsed['fragment'] . '" not found' - . ' in ' . $uri - ); - } - - if (! is_object($jsonSchema)) { - throw new ResourceNotFoundException( - 'Fragment part "' . $pathElement . '" is no object ' - . ' in ' . $uri - ); - } - } - } - - return $jsonSchema; - } - - /** - * Retrieve a URI - * - * @param string $uri JSON Schema URI - * @param string|null $baseUri - * @return object JSON Schema contents - */ - public function retrieve($uri, $baseUri = null) - { - $resolver = new UriResolver(); - $resolvedUri = $fetchUri = $resolver->resolve($uri, $baseUri); - - //fetch URL without #fragment - $arParts = $resolver->parse($resolvedUri); - if (isset($arParts['fragment'])) { - unset($arParts['fragment']); - $fetchUri = $resolver->generate($arParts); - } - - $jsonSchema = $this->loadSchema($fetchUri); - - // Use the JSON pointer if specified - $jsonSchema = $this->resolvePointer($jsonSchema, $resolvedUri); - - if ($jsonSchema instanceof \stdClass) { - $jsonSchema->id = $resolvedUri; - } - - return $jsonSchema; - } - - /** - * Fetch a schema from the given URI, json-decode it and return it. - * Caches schema objects. - * - * @param string $fetchUri Absolute URI - * - * @return object JSON schema object - */ - protected function loadSchema($fetchUri) - { - if (isset($this->schemaCache[$fetchUri])) { - return $this->schemaCache[$fetchUri]; - } - - $uriRetriever = $this->getUriRetriever(); - $contents = $this->uriRetriever->retrieve($fetchUri); - $this->confirmMediaType($uriRetriever, $fetchUri); - $jsonSchema = json_decode($contents); - - if (JSON_ERROR_NONE < $error = json_last_error()) { - throw new JsonDecodingException($error); - } - - $this->schemaCache[$fetchUri] = $jsonSchema; - - return $jsonSchema; - } - - /** - * Set the URI Retriever - * - * @param UriRetrieverInterface $uriRetriever - * @return $this for chaining - */ - public function setUriRetriever(UriRetrieverInterface $uriRetriever) - { - $this->uriRetriever = $uriRetriever; - - return $this; - } - - /** - * Parses a URI into five main components - * - * @param string $uri - * @return array - */ - public function parse($uri) - { - preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match); - - $components = array(); - if (5 < count($match)) { - $components = array( - 'scheme' => $match[2], - 'authority' => $match[4], - 'path' => $match[5] - ); - } - - if (7 < count($match)) { - $components['query'] = $match[7]; - } - - if (9 < count($match)) { - $components['fragment'] = $match[9]; - } - - return $components; - } - - /** - * Builds a URI based on n array with the main components - * - * @param array $components - * @return string - */ - public function generate(array $components) - { - $uri = $components['scheme'] . '://' - . $components['authority'] - . $components['path']; - - if (array_key_exists('query', $components)) { - $uri .= $components['query']; - } - - if (array_key_exists('fragment', $components)) { - $uri .= $components['fragment']; - } - - return $uri; - } - - /** - * Resolves a URI - * - * @param string $uri Absolute or relative - * @param string $baseUri Optional base URI - * @return string - */ - public function resolve($uri, $baseUri = null) - { - $components = $this->parse($uri); - $path = $components['path']; - - if ((array_key_exists('scheme', $components)) && ('http' === $components['scheme'])) { - return $uri; - } - - $baseComponents = $this->parse($baseUri); - $basePath = $baseComponents['path']; - - $baseComponents['path'] = UriResolver::combineRelativePathWithBasePath($path, $basePath); - - return $this->generate($baseComponents); - } - - /** - * @param string $uri - * @return boolean - */ - public function isValid($uri) - { - $components = $this->parse($uri); - - return !empty($components); - } -} |
