Completed
Push — develop ( 32764c...cb3cfa )
by
unknown
20:26
created
justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/PredefinedArray.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -18,39 +18,39 @@
 block discarded – undo
18 18
  */
19 19
 class PredefinedArray extends AbstractRetriever
20 20
 {
21
-    /**
22
-     * Contains schemas as URI => JSON
23
-     *
24
-     * @var array
25
-     */
26
-    private $schemas;
21
+	/**
22
+	 * Contains schemas as URI => JSON
23
+	 *
24
+	 * @var array
25
+	 */
26
+	private $schemas;
27 27
 
28
-    /**
29
-     * Constructor
30
-     *
31
-     * @param array  $schemas
32
-     * @param string $contentType
33
-     */
34
-    public function __construct(array $schemas, $contentType = Validator::SCHEMA_MEDIA_TYPE)
35
-    {
36
-        $this->schemas     = $schemas;
37
-        $this->contentType = $contentType;
38
-    }
28
+	/**
29
+	 * Constructor
30
+	 *
31
+	 * @param array  $schemas
32
+	 * @param string $contentType
33
+	 */
34
+	public function __construct(array $schemas, $contentType = Validator::SCHEMA_MEDIA_TYPE)
35
+	{
36
+		$this->schemas     = $schemas;
37
+		$this->contentType = $contentType;
38
+	}
39 39
 
40
-    /**
41
-     * {@inheritdoc}
42
-     *
43
-     * @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve()
44
-     */
45
-    public function retrieve($uri)
46
-    {
47
-        if (!array_key_exists($uri, $this->schemas)) {
48
-            throw new \JsonSchema\Exception\ResourceNotFoundException(sprintf(
49
-                'The JSON schema "%s" was not found.',
50
-                $uri
51
-            ));
52
-        }
40
+	/**
41
+	 * {@inheritdoc}
42
+	 *
43
+	 * @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve()
44
+	 */
45
+	public function retrieve($uri)
46
+	{
47
+		if (!array_key_exists($uri, $this->schemas)) {
48
+			throw new \JsonSchema\Exception\ResourceNotFoundException(sprintf(
49
+				'The JSON schema "%s" was not found.',
50
+				$uri
51
+			));
52
+		}
53 53
 
54
-        return $this->schemas[$uri];
55
-    }
54
+		return $this->schemas[$uri];
55
+	}
56 56
 }
Please login to merge, or discard this patch.
justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/FileGetContents.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -18,76 +18,76 @@
 block discarded – undo
18 18
  */
19 19
 class FileGetContents extends AbstractRetriever
20 20
 {
21
-    protected $messageBody;
21
+	protected $messageBody;
22 22
 
23
-    /**
24
-     * {@inheritdoc}
25
-     *
26
-     * @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve()
27
-     */
28
-    public function retrieve($uri)
29
-    {
30
-        $errorMessage = null;
31
-        set_error_handler(function ($errno, $errstr) use (&$errorMessage) {
32
-            $errorMessage = $errstr;
33
-        });
34
-        $response = file_get_contents($uri);
35
-        restore_error_handler();
23
+	/**
24
+	 * {@inheritdoc}
25
+	 *
26
+	 * @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve()
27
+	 */
28
+	public function retrieve($uri)
29
+	{
30
+		$errorMessage = null;
31
+		set_error_handler(function ($errno, $errstr) use (&$errorMessage) {
32
+			$errorMessage = $errstr;
33
+		});
34
+		$response = file_get_contents($uri);
35
+		restore_error_handler();
36 36
 
37
-        if ($errorMessage) {
38
-            throw new ResourceNotFoundException($errorMessage);
39
-        }
37
+		if ($errorMessage) {
38
+			throw new ResourceNotFoundException($errorMessage);
39
+		}
40 40
 
41
-        if (false === $response) {
42
-            throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
43
-        }
41
+		if (false === $response) {
42
+			throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
43
+		}
44 44
 
45
-        if ($response == ''
46
-            && substr($uri, 0, 7) == 'file://' && substr($uri, -1) == '/'
47
-        ) {
48
-            throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
49
-        }
45
+		if ($response == ''
46
+			&& substr($uri, 0, 7) == 'file://' && substr($uri, -1) == '/'
47
+		) {
48
+			throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
49
+		}
50 50
 
51
-        $this->messageBody = $response;
52
-        if (!empty($http_response_header)) {
53
-            // $http_response_header cannot be tested, because it's defined in the method's local scope
54
-            // See http://php.net/manual/en/reserved.variables.httpresponseheader.php for more info.
55
-            $this->fetchContentType($http_response_header); // @codeCoverageIgnore
56
-        } else {                                            // @codeCoverageIgnore
57
-            // Could be a "file://" url or something else - fake up the response
58
-            $this->contentType = null;
59
-        }
51
+		$this->messageBody = $response;
52
+		if (!empty($http_response_header)) {
53
+			// $http_response_header cannot be tested, because it's defined in the method's local scope
54
+			// See http://php.net/manual/en/reserved.variables.httpresponseheader.php for more info.
55
+			$this->fetchContentType($http_response_header); // @codeCoverageIgnore
56
+		} else {                                            // @codeCoverageIgnore
57
+			// Could be a "file://" url or something else - fake up the response
58
+			$this->contentType = null;
59
+		}
60 60
 
61
-        return $this->messageBody;
62
-    }
61
+		return $this->messageBody;
62
+	}
63 63
 
64
-    /**
65
-     * @param array $headers HTTP Response Headers
66
-     *
67
-     * @return bool Whether the Content-Type header was found or not
68
-     */
69
-    private function fetchContentType(array $headers)
70
-    {
71
-        foreach ($headers as $header) {
72
-            if ($this->contentType = self::getContentTypeMatchInHeader($header)) {
73
-                return true;
74
-            }
75
-        }
64
+	/**
65
+	 * @param array $headers HTTP Response Headers
66
+	 *
67
+	 * @return bool Whether the Content-Type header was found or not
68
+	 */
69
+	private function fetchContentType(array $headers)
70
+	{
71
+		foreach ($headers as $header) {
72
+			if ($this->contentType = self::getContentTypeMatchInHeader($header)) {
73
+				return true;
74
+			}
75
+		}
76 76
 
77
-        return false;
78
-    }
77
+		return false;
78
+	}
79 79
 
80
-    /**
81
-     * @param string $header
82
-     *
83
-     * @return string|null
84
-     */
85
-    protected static function getContentTypeMatchInHeader($header)
86
-    {
87
-        if (0 < preg_match("/Content-Type:(\V*)/ims", $header, $match)) {
88
-            return trim($match[1]);
89
-        }
80
+	/**
81
+	 * @param string $header
82
+	 *
83
+	 * @return string|null
84
+	 */
85
+	protected static function getContentTypeMatchInHeader($header)
86
+	{
87
+		if (0 < preg_match("/Content-Type:(\V*)/ims", $header, $match)) {
88
+			return trim($match[1]);
89
+		}
90 90
 
91
-        return null;
92
-    }
91
+		return null;
92
+	}
93 93
 }
Please login to merge, or discard this patch.
json-schema/src/JsonSchema/Uri/Retrievers/UriRetrieverInterface.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -16,21 +16,21 @@
 block discarded – undo
16 16
  */
17 17
 interface UriRetrieverInterface
18 18
 {
19
-    /**
20
-     * Retrieve a schema from the specified URI
21
-     *
22
-     * @param string $uri URI that resolves to a JSON schema
23
-     *
24
-     * @throws \JsonSchema\Exception\ResourceNotFoundException
25
-     *
26
-     * @return mixed string|null
27
-     */
28
-    public function retrieve($uri);
19
+	/**
20
+	 * Retrieve a schema from the specified URI
21
+	 *
22
+	 * @param string $uri URI that resolves to a JSON schema
23
+	 *
24
+	 * @throws \JsonSchema\Exception\ResourceNotFoundException
25
+	 *
26
+	 * @return mixed string|null
27
+	 */
28
+	public function retrieve($uri);
29 29
 
30
-    /**
31
-     * Get media content type
32
-     *
33
-     * @return string
34
-     */
35
-    public function getContentType();
30
+	/**
31
+	 * Get media content type
32
+	 *
33
+	 * @return string
34
+	 */
35
+	public function getContentType();
36 36
 }
Please login to merge, or discard this patch.
vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriResolver.php 1 patch
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -19,157 +19,157 @@
 block discarded – undo
19 19
  */
20 20
 class UriResolver implements UriResolverInterface
21 21
 {
22
-    /**
23
-     * Parses a URI into five main components
24
-     *
25
-     * @param string $uri
26
-     *
27
-     * @return array
28
-     */
29
-    public function parse($uri)
30
-    {
31
-        preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match);
32
-
33
-        $components = array();
34
-        if (5 < count($match)) {
35
-            $components =  array(
36
-                'scheme'    => $match[2],
37
-                'authority' => $match[4],
38
-                'path'      => $match[5]
39
-            );
40
-        }
41
-        if (7 < count($match)) {
42
-            $components['query'] = $match[7];
43
-        }
44
-        if (9 < count($match)) {
45
-            $components['fragment'] = $match[9];
46
-        }
47
-
48
-        return $components;
49
-    }
50
-
51
-    /**
52
-     * Builds a URI based on n array with the main components
53
-     *
54
-     * @param array $components
55
-     *
56
-     * @return string
57
-     */
58
-    public function generate(array $components)
59
-    {
60
-        $uri = $components['scheme'] . '://'
61
-             . $components['authority']
62
-             . $components['path'];
63
-
64
-        if (array_key_exists('query', $components) && strlen($components['query'])) {
65
-            $uri .= '?' . $components['query'];
66
-        }
67
-        if (array_key_exists('fragment', $components)) {
68
-            $uri .= '#' . $components['fragment'];
69
-        }
70
-
71
-        return $uri;
72
-    }
73
-
74
-    /**
75
-     * {@inheritdoc}
76
-     */
77
-    public function resolve($uri, $baseUri = null)
78
-    {
79
-        // treat non-uri base as local file path
80
-        if (
81
-            !is_null($baseUri) &&
82
-            !filter_var($baseUri, \FILTER_VALIDATE_URL) &&
83
-            !preg_match('|^[^/]+://|u', $baseUri)
84
-        ) {
85
-            if (is_file($baseUri)) {
86
-                $baseUri = 'file://' . realpath($baseUri);
87
-            } elseif (is_dir($baseUri)) {
88
-                $baseUri = 'file://' . realpath($baseUri) . '/';
89
-            } else {
90
-                $baseUri = 'file://' . getcwd() . '/' . $baseUri;
91
-            }
92
-        }
93
-
94
-        if ($uri == '') {
95
-            return $baseUri;
96
-        }
97
-
98
-        $components = $this->parse($uri);
99
-        $path = $components['path'];
100
-
101
-        if (!empty($components['scheme'])) {
102
-            return $uri;
103
-        }
104
-        $baseComponents = $this->parse($baseUri);
105
-        $basePath = $baseComponents['path'];
106
-
107
-        $baseComponents['path'] = self::combineRelativePathWithBasePath($path, $basePath);
108
-        if (isset($components['fragment'])) {
109
-            $baseComponents['fragment'] = $components['fragment'];
110
-        }
111
-
112
-        return $this->generate($baseComponents);
113
-    }
114
-
115
-    /**
116
-     * Tries to glue a relative path onto an absolute one
117
-     *
118
-     * @param string $relativePath
119
-     * @param string $basePath
120
-     *
121
-     * @throws UriResolverException
122
-     *
123
-     * @return string Merged path
124
-     */
125
-    public static function combineRelativePathWithBasePath($relativePath, $basePath)
126
-    {
127
-        $relativePath = self::normalizePath($relativePath);
128
-        if ($relativePath == '') {
129
-            return $basePath;
130
-        }
131
-        if ($relativePath[0] == '/') {
132
-            return $relativePath;
133
-        }
134
-
135
-        $basePathSegments = explode('/', $basePath);
136
-
137
-        preg_match('|^/?(\.\./(?:\./)*)*|', $relativePath, $match);
138
-        $numLevelUp = strlen($match[0]) /3 + 1;
139
-        if ($numLevelUp >= count($basePathSegments)) {
140
-            throw new UriResolverException(sprintf("Unable to resolve URI '%s' from base '%s'", $relativePath, $basePath));
141
-        }
142
-
143
-        $basePathSegments = array_slice($basePathSegments, 0, -$numLevelUp);
144
-        $path = preg_replace('|^/?(\.\./(\./)*)*|', '', $relativePath);
145
-
146
-        return implode('/', $basePathSegments) . '/' . $path;
147
-    }
148
-
149
-    /**
150
-     * Normalizes a URI path component by removing dot-slash and double slashes
151
-     *
152
-     * @param string $path
153
-     *
154
-     * @return string
155
-     */
156
-    private static function normalizePath($path)
157
-    {
158
-        $path = preg_replace('|((?<!\.)\./)*|', '', $path);
159
-        $path = preg_replace('|//|', '/', $path);
160
-
161
-        return $path;
162
-    }
163
-
164
-    /**
165
-     * @param string $uri
166
-     *
167
-     * @return bool
168
-     */
169
-    public function isValid($uri)
170
-    {
171
-        $components = $this->parse($uri);
172
-
173
-        return !empty($components);
174
-    }
22
+	/**
23
+	 * Parses a URI into five main components
24
+	 *
25
+	 * @param string $uri
26
+	 *
27
+	 * @return array
28
+	 */
29
+	public function parse($uri)
30
+	{
31
+		preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match);
32
+
33
+		$components = array();
34
+		if (5 < count($match)) {
35
+			$components =  array(
36
+				'scheme'    => $match[2],
37
+				'authority' => $match[4],
38
+				'path'      => $match[5]
39
+			);
40
+		}
41
+		if (7 < count($match)) {
42
+			$components['query'] = $match[7];
43
+		}
44
+		if (9 < count($match)) {
45
+			$components['fragment'] = $match[9];
46
+		}
47
+
48
+		return $components;
49
+	}
50
+
51
+	/**
52
+	 * Builds a URI based on n array with the main components
53
+	 *
54
+	 * @param array $components
55
+	 *
56
+	 * @return string
57
+	 */
58
+	public function generate(array $components)
59
+	{
60
+		$uri = $components['scheme'] . '://'
61
+			 . $components['authority']
62
+			 . $components['path'];
63
+
64
+		if (array_key_exists('query', $components) && strlen($components['query'])) {
65
+			$uri .= '?' . $components['query'];
66
+		}
67
+		if (array_key_exists('fragment', $components)) {
68
+			$uri .= '#' . $components['fragment'];
69
+		}
70
+
71
+		return $uri;
72
+	}
73
+
74
+	/**
75
+	 * {@inheritdoc}
76
+	 */
77
+	public function resolve($uri, $baseUri = null)
78
+	{
79
+		// treat non-uri base as local file path
80
+		if (
81
+			!is_null($baseUri) &&
82
+			!filter_var($baseUri, \FILTER_VALIDATE_URL) &&
83
+			!preg_match('|^[^/]+://|u', $baseUri)
84
+		) {
85
+			if (is_file($baseUri)) {
86
+				$baseUri = 'file://' . realpath($baseUri);
87
+			} elseif (is_dir($baseUri)) {
88
+				$baseUri = 'file://' . realpath($baseUri) . '/';
89
+			} else {
90
+				$baseUri = 'file://' . getcwd() . '/' . $baseUri;
91
+			}
92
+		}
93
+
94
+		if ($uri == '') {
95
+			return $baseUri;
96
+		}
97
+
98
+		$components = $this->parse($uri);
99
+		$path = $components['path'];
100
+
101
+		if (!empty($components['scheme'])) {
102
+			return $uri;
103
+		}
104
+		$baseComponents = $this->parse($baseUri);
105
+		$basePath = $baseComponents['path'];
106
+
107
+		$baseComponents['path'] = self::combineRelativePathWithBasePath($path, $basePath);
108
+		if (isset($components['fragment'])) {
109
+			$baseComponents['fragment'] = $components['fragment'];
110
+		}
111
+
112
+		return $this->generate($baseComponents);
113
+	}
114
+
115
+	/**
116
+	 * Tries to glue a relative path onto an absolute one
117
+	 *
118
+	 * @param string $relativePath
119
+	 * @param string $basePath
120
+	 *
121
+	 * @throws UriResolverException
122
+	 *
123
+	 * @return string Merged path
124
+	 */
125
+	public static function combineRelativePathWithBasePath($relativePath, $basePath)
126
+	{
127
+		$relativePath = self::normalizePath($relativePath);
128
+		if ($relativePath == '') {
129
+			return $basePath;
130
+		}
131
+		if ($relativePath[0] == '/') {
132
+			return $relativePath;
133
+		}
134
+
135
+		$basePathSegments = explode('/', $basePath);
136
+
137
+		preg_match('|^/?(\.\./(?:\./)*)*|', $relativePath, $match);
138
+		$numLevelUp = strlen($match[0]) /3 + 1;
139
+		if ($numLevelUp >= count($basePathSegments)) {
140
+			throw new UriResolverException(sprintf("Unable to resolve URI '%s' from base '%s'", $relativePath, $basePath));
141
+		}
142
+
143
+		$basePathSegments = array_slice($basePathSegments, 0, -$numLevelUp);
144
+		$path = preg_replace('|^/?(\.\./(\./)*)*|', '', $relativePath);
145
+
146
+		return implode('/', $basePathSegments) . '/' . $path;
147
+	}
148
+
149
+	/**
150
+	 * Normalizes a URI path component by removing dot-slash and double slashes
151
+	 *
152
+	 * @param string $path
153
+	 *
154
+	 * @return string
155
+	 */
156
+	private static function normalizePath($path)
157
+	{
158
+		$path = preg_replace('|((?<!\.)\./)*|', '', $path);
159
+		$path = preg_replace('|//|', '/', $path);
160
+
161
+		return $path;
162
+	}
163
+
164
+	/**
165
+	 * @param string $uri
166
+	 *
167
+	 * @return bool
168
+	 */
169
+	public function isValid($uri)
170
+	{
171
+		$components = $this->parse($uri);
172
+
173
+		return !empty($components);
174
+	}
175 175
 }
Please login to merge, or discard this patch.
vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriRetriever.php 1 patch
Indentation   +322 added lines, -322 removed lines patch added patch discarded remove patch
@@ -24,326 +24,326 @@
 block discarded – undo
24 24
  */
25 25
 class UriRetriever implements BaseUriRetrieverInterface
26 26
 {
27
-    /**
28
-     * @var array Map of URL translations
29
-     */
30
-    protected $translationMap = array(
31
-        // use local copies of the spec schemas
32
-        '|^https?://json-schema.org/draft-(0[34])/schema#?|' => 'package://dist/schema/json-schema-draft-$1.json'
33
-    );
34
-
35
-    /**
36
-     * @var array A list of endpoints for media type check exclusion
37
-     */
38
-    protected $allowedInvalidContentTypeEndpoints = array(
39
-        'http://json-schema.org/',
40
-        'https://json-schema.org/'
41
-    );
42
-
43
-    /**
44
-     * @var null|UriRetrieverInterface
45
-     */
46
-    protected $uriRetriever = null;
47
-
48
-    /**
49
-     * @var array|object[]
50
-     *
51
-     * @see loadSchema
52
-     */
53
-    private $schemaCache = array();
54
-
55
-    /**
56
-     * Adds an endpoint to the media type validation exclusion list
57
-     *
58
-     * @param string $endpoint
59
-     */
60
-    public function addInvalidContentTypeEndpoint($endpoint)
61
-    {
62
-        $this->allowedInvalidContentTypeEndpoints[] = $endpoint;
63
-    }
64
-
65
-    /**
66
-     * Guarantee the correct media type was encountered
67
-     *
68
-     * @param UriRetrieverInterface $uriRetriever
69
-     * @param string                $uri
70
-     *
71
-     * @return bool|void
72
-     */
73
-    public function confirmMediaType($uriRetriever, $uri)
74
-    {
75
-        $contentType = $uriRetriever->getContentType();
76
-
77
-        if (is_null($contentType)) {
78
-            // Well, we didn't get an invalid one
79
-            return;
80
-        }
81
-
82
-        if (in_array($contentType, array(Validator::SCHEMA_MEDIA_TYPE, 'application/json'))) {
83
-            return;
84
-        }
85
-
86
-        foreach ($this->allowedInvalidContentTypeEndpoints as $endpoint) {
87
-            if (strpos($uri, $endpoint) === 0) {
88
-                return true;
89
-            }
90
-        }
91
-
92
-        throw new InvalidSchemaMediaTypeException(sprintf('Media type %s expected', Validator::SCHEMA_MEDIA_TYPE));
93
-    }
94
-
95
-    /**
96
-     * Get a URI Retriever
97
-     *
98
-     * If none is specified, sets a default FileGetContents retriever and
99
-     * returns that object.
100
-     *
101
-     * @return UriRetrieverInterface
102
-     */
103
-    public function getUriRetriever()
104
-    {
105
-        if (is_null($this->uriRetriever)) {
106
-            $this->setUriRetriever(new FileGetContents());
107
-        }
108
-
109
-        return $this->uriRetriever;
110
-    }
111
-
112
-    /**
113
-     * Resolve a schema based on pointer
114
-     *
115
-     * URIs can have a fragment at the end in the format of
116
-     * #/path/to/object and we are to look up the 'path' property of
117
-     * the first object then the 'to' and 'object' properties.
118
-     *
119
-     * @param object $jsonSchema JSON Schema contents
120
-     * @param string $uri        JSON Schema URI
121
-     *
122
-     * @throws ResourceNotFoundException
123
-     *
124
-     * @return object JSON Schema after walking down the fragment pieces
125
-     */
126
-    public function resolvePointer($jsonSchema, $uri)
127
-    {
128
-        $resolver = new UriResolver();
129
-        $parsed = $resolver->parse($uri);
130
-        if (empty($parsed['fragment'])) {
131
-            return $jsonSchema;
132
-        }
133
-
134
-        $path = explode('/', $parsed['fragment']);
135
-        while ($path) {
136
-            $pathElement = array_shift($path);
137
-            if (!empty($pathElement)) {
138
-                $pathElement = str_replace('~1', '/', $pathElement);
139
-                $pathElement = str_replace('~0', '~', $pathElement);
140
-                if (!empty($jsonSchema->$pathElement)) {
141
-                    $jsonSchema = $jsonSchema->$pathElement;
142
-                } else {
143
-                    throw new ResourceNotFoundException(
144
-                        'Fragment "' . $parsed['fragment'] . '" not found'
145
-                        . ' in ' . $uri
146
-                    );
147
-                }
148
-
149
-                if (!is_object($jsonSchema)) {
150
-                    throw new ResourceNotFoundException(
151
-                        'Fragment part "' . $pathElement . '" is no object '
152
-                        . ' in ' . $uri
153
-                    );
154
-                }
155
-            }
156
-        }
157
-
158
-        return $jsonSchema;
159
-    }
160
-
161
-    /**
162
-     * {@inheritdoc}
163
-     */
164
-    public function retrieve($uri, $baseUri = null, $translate = true)
165
-    {
166
-        $resolver = new UriResolver();
167
-        $resolvedUri = $fetchUri = $resolver->resolve($uri, $baseUri);
168
-
169
-        //fetch URL without #fragment
170
-        $arParts = $resolver->parse($resolvedUri);
171
-        if (isset($arParts['fragment'])) {
172
-            unset($arParts['fragment']);
173
-            $fetchUri = $resolver->generate($arParts);
174
-        }
175
-
176
-        // apply URI translations
177
-        if ($translate) {
178
-            $fetchUri = $this->translate($fetchUri);
179
-        }
180
-
181
-        $jsonSchema = $this->loadSchema($fetchUri);
182
-
183
-        // Use the JSON pointer if specified
184
-        $jsonSchema = $this->resolvePointer($jsonSchema, $resolvedUri);
185
-
186
-        if ($jsonSchema instanceof \stdClass) {
187
-            $jsonSchema->id = $resolvedUri;
188
-        }
189
-
190
-        return $jsonSchema;
191
-    }
192
-
193
-    /**
194
-     * Fetch a schema from the given URI, json-decode it and return it.
195
-     * Caches schema objects.
196
-     *
197
-     * @param string $fetchUri Absolute URI
198
-     *
199
-     * @return object JSON schema object
200
-     */
201
-    protected function loadSchema($fetchUri)
202
-    {
203
-        if (isset($this->schemaCache[$fetchUri])) {
204
-            return $this->schemaCache[$fetchUri];
205
-        }
206
-
207
-        $uriRetriever = $this->getUriRetriever();
208
-        $contents = $this->uriRetriever->retrieve($fetchUri);
209
-        $this->confirmMediaType($uriRetriever, $fetchUri);
210
-        $jsonSchema = json_decode($contents);
211
-
212
-        if (JSON_ERROR_NONE < $error = json_last_error()) {
213
-            throw new JsonDecodingException($error);
214
-        }
215
-
216
-        $this->schemaCache[$fetchUri] = $jsonSchema;
217
-
218
-        return $jsonSchema;
219
-    }
220
-
221
-    /**
222
-     * Set the URI Retriever
223
-     *
224
-     * @param UriRetrieverInterface $uriRetriever
225
-     *
226
-     * @return $this for chaining
227
-     */
228
-    public function setUriRetriever(UriRetrieverInterface $uriRetriever)
229
-    {
230
-        $this->uriRetriever = $uriRetriever;
231
-
232
-        return $this;
233
-    }
234
-
235
-    /**
236
-     * Parses a URI into five main components
237
-     *
238
-     * @param string $uri
239
-     *
240
-     * @return array
241
-     */
242
-    public function parse($uri)
243
-    {
244
-        preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match);
245
-
246
-        $components = array();
247
-        if (5 < count($match)) {
248
-            $components =  array(
249
-                'scheme'    => $match[2],
250
-                'authority' => $match[4],
251
-                'path'      => $match[5]
252
-            );
253
-        }
254
-
255
-        if (7 < count($match)) {
256
-            $components['query'] = $match[7];
257
-        }
258
-
259
-        if (9 < count($match)) {
260
-            $components['fragment'] = $match[9];
261
-        }
262
-
263
-        return $components;
264
-    }
265
-
266
-    /**
267
-     * Builds a URI based on n array with the main components
268
-     *
269
-     * @param array $components
270
-     *
271
-     * @return string
272
-     */
273
-    public function generate(array $components)
274
-    {
275
-        $uri = $components['scheme'] . '://'
276
-             . $components['authority']
277
-             . $components['path'];
278
-
279
-        if (array_key_exists('query', $components)) {
280
-            $uri .= $components['query'];
281
-        }
282
-
283
-        if (array_key_exists('fragment', $components)) {
284
-            $uri .= $components['fragment'];
285
-        }
286
-
287
-        return $uri;
288
-    }
289
-
290
-    /**
291
-     * Resolves a URI
292
-     *
293
-     * @param string $uri     Absolute or relative
294
-     * @param string $baseUri Optional base URI
295
-     *
296
-     * @return string
297
-     */
298
-    public function resolve($uri, $baseUri = null)
299
-    {
300
-        $components = $this->parse($uri);
301
-        $path = $components['path'];
302
-
303
-        if ((array_key_exists('scheme', $components)) && ('http' === $components['scheme'])) {
304
-            return $uri;
305
-        }
306
-
307
-        $baseComponents = $this->parse($baseUri);
308
-        $basePath = $baseComponents['path'];
309
-
310
-        $baseComponents['path'] = UriResolver::combineRelativePathWithBasePath($path, $basePath);
311
-
312
-        return $this->generate($baseComponents);
313
-    }
314
-
315
-    /**
316
-     * @param string $uri
317
-     *
318
-     * @return bool
319
-     */
320
-    public function isValid($uri)
321
-    {
322
-        $components = $this->parse($uri);
323
-
324
-        return !empty($components);
325
-    }
326
-
327
-    /**
328
-     * Set a URL translation rule
329
-     */
330
-    public function setTranslation($from, $to)
331
-    {
332
-        $this->translationMap[$from] = $to;
333
-    }
334
-
335
-    /**
336
-     * Apply URI translation rules
337
-     */
338
-    public function translate($uri)
339
-    {
340
-        foreach ($this->translationMap as $from => $to) {
341
-            $uri = preg_replace($from, $to, $uri);
342
-        }
343
-
344
-        // translate references to local files within the json-schema package
345
-        $uri = preg_replace('|^package://|', sprintf('file://%s/', realpath(__DIR__ . '/../../..')), $uri);
346
-
347
-        return $uri;
348
-    }
27
+	/**
28
+	 * @var array Map of URL translations
29
+	 */
30
+	protected $translationMap = array(
31
+		// use local copies of the spec schemas
32
+		'|^https?://json-schema.org/draft-(0[34])/schema#?|' => 'package://dist/schema/json-schema-draft-$1.json'
33
+	);
34
+
35
+	/**
36
+	 * @var array A list of endpoints for media type check exclusion
37
+	 */
38
+	protected $allowedInvalidContentTypeEndpoints = array(
39
+		'http://json-schema.org/',
40
+		'https://json-schema.org/'
41
+	);
42
+
43
+	/**
44
+	 * @var null|UriRetrieverInterface
45
+	 */
46
+	protected $uriRetriever = null;
47
+
48
+	/**
49
+	 * @var array|object[]
50
+	 *
51
+	 * @see loadSchema
52
+	 */
53
+	private $schemaCache = array();
54
+
55
+	/**
56
+	 * Adds an endpoint to the media type validation exclusion list
57
+	 *
58
+	 * @param string $endpoint
59
+	 */
60
+	public function addInvalidContentTypeEndpoint($endpoint)
61
+	{
62
+		$this->allowedInvalidContentTypeEndpoints[] = $endpoint;
63
+	}
64
+
65
+	/**
66
+	 * Guarantee the correct media type was encountered
67
+	 *
68
+	 * @param UriRetrieverInterface $uriRetriever
69
+	 * @param string                $uri
70
+	 *
71
+	 * @return bool|void
72
+	 */
73
+	public function confirmMediaType($uriRetriever, $uri)
74
+	{
75
+		$contentType = $uriRetriever->getContentType();
76
+
77
+		if (is_null($contentType)) {
78
+			// Well, we didn't get an invalid one
79
+			return;
80
+		}
81
+
82
+		if (in_array($contentType, array(Validator::SCHEMA_MEDIA_TYPE, 'application/json'))) {
83
+			return;
84
+		}
85
+
86
+		foreach ($this->allowedInvalidContentTypeEndpoints as $endpoint) {
87
+			if (strpos($uri, $endpoint) === 0) {
88
+				return true;
89
+			}
90
+		}
91
+
92
+		throw new InvalidSchemaMediaTypeException(sprintf('Media type %s expected', Validator::SCHEMA_MEDIA_TYPE));
93
+	}
94
+
95
+	/**
96
+	 * Get a URI Retriever
97
+	 *
98
+	 * If none is specified, sets a default FileGetContents retriever and
99
+	 * returns that object.
100
+	 *
101
+	 * @return UriRetrieverInterface
102
+	 */
103
+	public function getUriRetriever()
104
+	{
105
+		if (is_null($this->uriRetriever)) {
106
+			$this->setUriRetriever(new FileGetContents());
107
+		}
108
+
109
+		return $this->uriRetriever;
110
+	}
111
+
112
+	/**
113
+	 * Resolve a schema based on pointer
114
+	 *
115
+	 * URIs can have a fragment at the end in the format of
116
+	 * #/path/to/object and we are to look up the 'path' property of
117
+	 * the first object then the 'to' and 'object' properties.
118
+	 *
119
+	 * @param object $jsonSchema JSON Schema contents
120
+	 * @param string $uri        JSON Schema URI
121
+	 *
122
+	 * @throws ResourceNotFoundException
123
+	 *
124
+	 * @return object JSON Schema after walking down the fragment pieces
125
+	 */
126
+	public function resolvePointer($jsonSchema, $uri)
127
+	{
128
+		$resolver = new UriResolver();
129
+		$parsed = $resolver->parse($uri);
130
+		if (empty($parsed['fragment'])) {
131
+			return $jsonSchema;
132
+		}
133
+
134
+		$path = explode('/', $parsed['fragment']);
135
+		while ($path) {
136
+			$pathElement = array_shift($path);
137
+			if (!empty($pathElement)) {
138
+				$pathElement = str_replace('~1', '/', $pathElement);
139
+				$pathElement = str_replace('~0', '~', $pathElement);
140
+				if (!empty($jsonSchema->$pathElement)) {
141
+					$jsonSchema = $jsonSchema->$pathElement;
142
+				} else {
143
+					throw new ResourceNotFoundException(
144
+						'Fragment "' . $parsed['fragment'] . '" not found'
145
+						. ' in ' . $uri
146
+					);
147
+				}
148
+
149
+				if (!is_object($jsonSchema)) {
150
+					throw new ResourceNotFoundException(
151
+						'Fragment part "' . $pathElement . '" is no object '
152
+						. ' in ' . $uri
153
+					);
154
+				}
155
+			}
156
+		}
157
+
158
+		return $jsonSchema;
159
+	}
160
+
161
+	/**
162
+	 * {@inheritdoc}
163
+	 */
164
+	public function retrieve($uri, $baseUri = null, $translate = true)
165
+	{
166
+		$resolver = new UriResolver();
167
+		$resolvedUri = $fetchUri = $resolver->resolve($uri, $baseUri);
168
+
169
+		//fetch URL without #fragment
170
+		$arParts = $resolver->parse($resolvedUri);
171
+		if (isset($arParts['fragment'])) {
172
+			unset($arParts['fragment']);
173
+			$fetchUri = $resolver->generate($arParts);
174
+		}
175
+
176
+		// apply URI translations
177
+		if ($translate) {
178
+			$fetchUri = $this->translate($fetchUri);
179
+		}
180
+
181
+		$jsonSchema = $this->loadSchema($fetchUri);
182
+
183
+		// Use the JSON pointer if specified
184
+		$jsonSchema = $this->resolvePointer($jsonSchema, $resolvedUri);
185
+
186
+		if ($jsonSchema instanceof \stdClass) {
187
+			$jsonSchema->id = $resolvedUri;
188
+		}
189
+
190
+		return $jsonSchema;
191
+	}
192
+
193
+	/**
194
+	 * Fetch a schema from the given URI, json-decode it and return it.
195
+	 * Caches schema objects.
196
+	 *
197
+	 * @param string $fetchUri Absolute URI
198
+	 *
199
+	 * @return object JSON schema object
200
+	 */
201
+	protected function loadSchema($fetchUri)
202
+	{
203
+		if (isset($this->schemaCache[$fetchUri])) {
204
+			return $this->schemaCache[$fetchUri];
205
+		}
206
+
207
+		$uriRetriever = $this->getUriRetriever();
208
+		$contents = $this->uriRetriever->retrieve($fetchUri);
209
+		$this->confirmMediaType($uriRetriever, $fetchUri);
210
+		$jsonSchema = json_decode($contents);
211
+
212
+		if (JSON_ERROR_NONE < $error = json_last_error()) {
213
+			throw new JsonDecodingException($error);
214
+		}
215
+
216
+		$this->schemaCache[$fetchUri] = $jsonSchema;
217
+
218
+		return $jsonSchema;
219
+	}
220
+
221
+	/**
222
+	 * Set the URI Retriever
223
+	 *
224
+	 * @param UriRetrieverInterface $uriRetriever
225
+	 *
226
+	 * @return $this for chaining
227
+	 */
228
+	public function setUriRetriever(UriRetrieverInterface $uriRetriever)
229
+	{
230
+		$this->uriRetriever = $uriRetriever;
231
+
232
+		return $this;
233
+	}
234
+
235
+	/**
236
+	 * Parses a URI into five main components
237
+	 *
238
+	 * @param string $uri
239
+	 *
240
+	 * @return array
241
+	 */
242
+	public function parse($uri)
243
+	{
244
+		preg_match('|^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?|', $uri, $match);
245
+
246
+		$components = array();
247
+		if (5 < count($match)) {
248
+			$components =  array(
249
+				'scheme'    => $match[2],
250
+				'authority' => $match[4],
251
+				'path'      => $match[5]
252
+			);
253
+		}
254
+
255
+		if (7 < count($match)) {
256
+			$components['query'] = $match[7];
257
+		}
258
+
259
+		if (9 < count($match)) {
260
+			$components['fragment'] = $match[9];
261
+		}
262
+
263
+		return $components;
264
+	}
265
+
266
+	/**
267
+	 * Builds a URI based on n array with the main components
268
+	 *
269
+	 * @param array $components
270
+	 *
271
+	 * @return string
272
+	 */
273
+	public function generate(array $components)
274
+	{
275
+		$uri = $components['scheme'] . '://'
276
+			 . $components['authority']
277
+			 . $components['path'];
278
+
279
+		if (array_key_exists('query', $components)) {
280
+			$uri .= $components['query'];
281
+		}
282
+
283
+		if (array_key_exists('fragment', $components)) {
284
+			$uri .= $components['fragment'];
285
+		}
286
+
287
+		return $uri;
288
+	}
289
+
290
+	/**
291
+	 * Resolves a URI
292
+	 *
293
+	 * @param string $uri     Absolute or relative
294
+	 * @param string $baseUri Optional base URI
295
+	 *
296
+	 * @return string
297
+	 */
298
+	public function resolve($uri, $baseUri = null)
299
+	{
300
+		$components = $this->parse($uri);
301
+		$path = $components['path'];
302
+
303
+		if ((array_key_exists('scheme', $components)) && ('http' === $components['scheme'])) {
304
+			return $uri;
305
+		}
306
+
307
+		$baseComponents = $this->parse($baseUri);
308
+		$basePath = $baseComponents['path'];
309
+
310
+		$baseComponents['path'] = UriResolver::combineRelativePathWithBasePath($path, $basePath);
311
+
312
+		return $this->generate($baseComponents);
313
+	}
314
+
315
+	/**
316
+	 * @param string $uri
317
+	 *
318
+	 * @return bool
319
+	 */
320
+	public function isValid($uri)
321
+	{
322
+		$components = $this->parse($uri);
323
+
324
+		return !empty($components);
325
+	}
326
+
327
+	/**
328
+	 * Set a URL translation rule
329
+	 */
330
+	public function setTranslation($from, $to)
331
+	{
332
+		$this->translationMap[$from] = $to;
333
+	}
334
+
335
+	/**
336
+	 * Apply URI translation rules
337
+	 */
338
+	public function translate($uri)
339
+	{
340
+		foreach ($this->translationMap as $from => $to) {
341
+			$uri = preg_replace($from, $to, $uri);
342
+		}
343
+
344
+		// translate references to local files within the json-schema package
345
+		$uri = preg_replace('|^package://|', sprintf('file://%s/', realpath(__DIR__ . '/../../..')), $uri);
346
+
347
+		return $uri;
348
+	}
349 349
 }
Please login to merge, or discard this patch.
vendor/justinrainbow/json-schema/src/JsonSchema/Iterator/ObjectIterator.php 1 patch
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -16,134 +16,134 @@
 block discarded – undo
16 16
  */
17 17
 class ObjectIterator implements \Iterator, \Countable
18 18
 {
19
-    /** @var object */
20
-    private $object;
21
-
22
-    /** @var int */
23
-    private $position = 0;
24
-
25
-    /** @var array */
26
-    private $data = array();
27
-
28
-    /** @var bool */
29
-    private $initialized = false;
30
-
31
-    /**
32
-     * @param object $object
33
-     */
34
-    public function __construct($object)
35
-    {
36
-        $this->object = $object;
37
-    }
38
-
39
-    /**
40
-     * {@inheritdoc}
41
-     */
42
-    public function current()
43
-    {
44
-        $this->initialize();
45
-
46
-        return $this->data[$this->position];
47
-    }
48
-
49
-    /**
50
-     * {@inheritdoc}
51
-     */
52
-    public function next()
53
-    {
54
-        $this->initialize();
55
-        $this->position++;
56
-    }
57
-
58
-    /**
59
-     * {@inheritdoc}
60
-     */
61
-    public function key()
62
-    {
63
-        $this->initialize();
64
-
65
-        return $this->position;
66
-    }
67
-
68
-    /**
69
-     * {@inheritdoc}
70
-     */
71
-    public function valid()
72
-    {
73
-        $this->initialize();
74
-
75
-        return isset($this->data[$this->position]);
76
-    }
77
-
78
-    /**
79
-     * {@inheritdoc}
80
-     */
81
-    public function rewind()
82
-    {
83
-        $this->initialize();
84
-        $this->position = 0;
85
-    }
86
-
87
-    /**
88
-     * {@inheritdoc}
89
-     */
90
-    public function count()
91
-    {
92
-        $this->initialize();
93
-
94
-        return count($this->data);
95
-    }
96
-
97
-    /**
98
-     * Initializer
99
-     */
100
-    private function initialize()
101
-    {
102
-        if (!$this->initialized) {
103
-            $this->data = $this->buildDataFromObject($this->object);
104
-            $this->initialized = true;
105
-        }
106
-    }
107
-
108
-    /**
109
-     * @param object $object
110
-     *
111
-     * @return array
112
-     */
113
-    private function buildDataFromObject($object)
114
-    {
115
-        $result = array();
116
-
117
-        $stack = new \SplStack();
118
-        $stack->push($object);
119
-
120
-        while (!$stack->isEmpty()) {
121
-            $current = $stack->pop();
122
-            if (is_object($current)) {
123
-                array_push($result, $current);
124
-            }
125
-
126
-            foreach ($this->getDataFromItem($current) as $propertyName => $propertyValue) {
127
-                if (is_object($propertyValue) || is_array($propertyValue)) {
128
-                    $stack->push($propertyValue);
129
-                }
130
-            }
131
-        }
132
-
133
-        return $result;
134
-    }
135
-
136
-    /**
137
-     * @param object|array $item
138
-     *
139
-     * @return array
140
-     */
141
-    private function getDataFromItem($item)
142
-    {
143
-        if (!is_object($item) && !is_array($item)) {
144
-            return array();
145
-        }
146
-
147
-        return is_object($item) ? get_object_vars($item) : $item;
148
-    }
19
+	/** @var object */
20
+	private $object;
21
+
22
+	/** @var int */
23
+	private $position = 0;
24
+
25
+	/** @var array */
26
+	private $data = array();
27
+
28
+	/** @var bool */
29
+	private $initialized = false;
30
+
31
+	/**
32
+	 * @param object $object
33
+	 */
34
+	public function __construct($object)
35
+	{
36
+		$this->object = $object;
37
+	}
38
+
39
+	/**
40
+	 * {@inheritdoc}
41
+	 */
42
+	public function current()
43
+	{
44
+		$this->initialize();
45
+
46
+		return $this->data[$this->position];
47
+	}
48
+
49
+	/**
50
+	 * {@inheritdoc}
51
+	 */
52
+	public function next()
53
+	{
54
+		$this->initialize();
55
+		$this->position++;
56
+	}
57
+
58
+	/**
59
+	 * {@inheritdoc}
60
+	 */
61
+	public function key()
62
+	{
63
+		$this->initialize();
64
+
65
+		return $this->position;
66
+	}
67
+
68
+	/**
69
+	 * {@inheritdoc}
70
+	 */
71
+	public function valid()
72
+	{
73
+		$this->initialize();
74
+
75
+		return isset($this->data[$this->position]);
76
+	}
77
+
78
+	/**
79
+	 * {@inheritdoc}
80
+	 */
81
+	public function rewind()
82
+	{
83
+		$this->initialize();
84
+		$this->position = 0;
85
+	}
86
+
87
+	/**
88
+	 * {@inheritdoc}
89
+	 */
90
+	public function count()
91
+	{
92
+		$this->initialize();
93
+
94
+		return count($this->data);
95
+	}
96
+
97
+	/**
98
+	 * Initializer
99
+	 */
100
+	private function initialize()
101
+	{
102
+		if (!$this->initialized) {
103
+			$this->data = $this->buildDataFromObject($this->object);
104
+			$this->initialized = true;
105
+		}
106
+	}
107
+
108
+	/**
109
+	 * @param object $object
110
+	 *
111
+	 * @return array
112
+	 */
113
+	private function buildDataFromObject($object)
114
+	{
115
+		$result = array();
116
+
117
+		$stack = new \SplStack();
118
+		$stack->push($object);
119
+
120
+		while (!$stack->isEmpty()) {
121
+			$current = $stack->pop();
122
+			if (is_object($current)) {
123
+				array_push($result, $current);
124
+			}
125
+
126
+			foreach ($this->getDataFromItem($current) as $propertyName => $propertyValue) {
127
+				if (is_object($propertyValue) || is_array($propertyValue)) {
128
+					$stack->push($propertyValue);
129
+				}
130
+			}
131
+		}
132
+
133
+		return $result;
134
+	}
135
+
136
+	/**
137
+	 * @param object|array $item
138
+	 *
139
+	 * @return array
140
+	 */
141
+	private function getDataFromItem($item)
142
+	{
143
+		if (!is_object($item) && !is_array($item)) {
144
+			return array();
145
+		}
146
+
147
+		return is_object($item) ? get_object_vars($item) : $item;
148
+	}
149 149
 }
Please login to merge, or discard this patch.
vendor/justinrainbow/json-schema/src/JsonSchema/Rfc3339.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -4,27 +4,27 @@
 block discarded – undo
4 4
 
5 5
 class Rfc3339
6 6
 {
7
-    const REGEX = '/^(\d{4}-\d{2}-\d{2}[T ]{1}\d{2}:\d{2}:\d{2})(\.\d+)?(Z|([+-]\d{2}):?(\d{2}))$/';
7
+	const REGEX = '/^(\d{4}-\d{2}-\d{2}[T ]{1}\d{2}:\d{2}:\d{2})(\.\d+)?(Z|([+-]\d{2}):?(\d{2}))$/';
8 8
 
9
-    /**
10
-     * Try creating a DateTime instance
11
-     *
12
-     * @param string $string
13
-     *
14
-     * @return \DateTime|null
15
-     */
16
-    public static function createFromString($string)
17
-    {
18
-        if (!preg_match(self::REGEX, strtoupper($string), $matches)) {
19
-            return null;
20
-        }
9
+	/**
10
+	 * Try creating a DateTime instance
11
+	 *
12
+	 * @param string $string
13
+	 *
14
+	 * @return \DateTime|null
15
+	 */
16
+	public static function createFromString($string)
17
+	{
18
+		if (!preg_match(self::REGEX, strtoupper($string), $matches)) {
19
+			return null;
20
+		}
21 21
 
22
-        $dateAndTime = $matches[1];
23
-        $microseconds = $matches[2] ?: '.000000';
24
-        $timeZone = 'Z' !== $matches[3] ? $matches[4] . ':' . $matches[5] : '+00:00';
25
-        $dateFormat = strpos($dateAndTime, 'T') === false ? 'Y-m-d H:i:s.uP' : 'Y-m-d\TH:i:s.uP';
26
-        $dateTime = \DateTime::createFromFormat($dateFormat, $dateAndTime . $microseconds . $timeZone, new \DateTimeZone('UTC'));
22
+		$dateAndTime = $matches[1];
23
+		$microseconds = $matches[2] ?: '.000000';
24
+		$timeZone = 'Z' !== $matches[3] ? $matches[4] . ':' . $matches[5] : '+00:00';
25
+		$dateFormat = strpos($dateAndTime, 'T') === false ? 'Y-m-d H:i:s.uP' : 'Y-m-d\TH:i:s.uP';
26
+		$dateTime = \DateTime::createFromFormat($dateFormat, $dateAndTime . $microseconds . $timeZone, new \DateTimeZone('UTC'));
27 27
 
28
-        return $dateTime ?: null;
29
-    }
28
+		return $dateTime ?: null;
29
+	}
30 30
 }
Please login to merge, or discard this patch.
vendor/justinrainbow/json-schema/src/JsonSchema/SchemaStorage.php 1 patch
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -10,160 +10,160 @@
 block discarded – undo
10 10
 
11 11
 class SchemaStorage implements SchemaStorageInterface
12 12
 {
13
-    const INTERNAL_PROVIDED_SCHEMA_URI = 'internal://provided-schema/';
14
-
15
-    protected $uriRetriever;
16
-    protected $uriResolver;
17
-    protected $schemas = array();
18
-
19
-    public function __construct(
20
-        UriRetrieverInterface $uriRetriever = null,
21
-        UriResolverInterface $uriResolver = null
22
-    ) {
23
-        $this->uriRetriever = $uriRetriever ?: new UriRetriever();
24
-        $this->uriResolver = $uriResolver ?: new UriResolver();
25
-    }
26
-
27
-    /**
28
-     * @return UriRetrieverInterface
29
-     */
30
-    public function getUriRetriever()
31
-    {
32
-        return $this->uriRetriever;
33
-    }
34
-
35
-    /**
36
-     * @return UriResolverInterface
37
-     */
38
-    public function getUriResolver()
39
-    {
40
-        return $this->uriResolver;
41
-    }
42
-
43
-    /**
44
-     * {@inheritdoc}
45
-     */
46
-    public function addSchema($id, $schema = null)
47
-    {
48
-        if (is_null($schema) && $id !== self::INTERNAL_PROVIDED_SCHEMA_URI) {
49
-            // if the schema was user-provided to Validator and is still null, then assume this is
50
-            // what the user intended, as there's no way for us to retrieve anything else. User-supplied
51
-            // schemas do not have an associated URI when passed via Validator::validate().
52
-            $schema = $this->uriRetriever->retrieve($id);
53
-        }
54
-
55
-        // cast array schemas to object
56
-        if (is_array($schema)) {
57
-            $schema = BaseConstraint::arrayToObjectRecursive($schema);
58
-        }
59
-
60
-        // workaround for bug in draft-03 & draft-04 meta-schemas (id & $ref defined with incorrect format)
61
-        // see https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/177#issuecomment-293051367
62
-        if (is_object($schema) && property_exists($schema, 'id')) {
63
-            if ($schema->id == 'http://json-schema.org/draft-04/schema#') {
64
-                $schema->properties->id->format = 'uri-reference';
65
-            } elseif ($schema->id == 'http://json-schema.org/draft-03/schema#') {
66
-                $schema->properties->id->format = 'uri-reference';
67
-                $schema->properties->{'$ref'}->format = 'uri-reference';
68
-            }
69
-        }
70
-
71
-        // resolve references
72
-        $this->expandRefs($schema, $id);
73
-
74
-        $this->schemas[$id] = $schema;
75
-    }
76
-
77
-    /**
78
-     * Recursively resolve all references against the provided base
79
-     *
80
-     * @param mixed  $schema
81
-     * @param string $base
82
-     */
83
-    private function expandRefs(&$schema, $base = null)
84
-    {
85
-        if (!is_object($schema)) {
86
-            if (is_array($schema)) {
87
-                foreach ($schema as &$member) {
88
-                    $this->expandRefs($member, $base);
89
-                }
90
-            }
91
-
92
-            return;
93
-        }
94
-
95
-        if (property_exists($schema, 'id') && is_string($schema->id) && $base != $schema->id) {
96
-            $base = $this->uriResolver->resolve($schema->id, $base);
97
-        }
98
-
99
-        if (property_exists($schema, '$ref') && is_string($schema->{'$ref'})) {
100
-            $refPointer = new JsonPointer($this->uriResolver->resolve($schema->{'$ref'}, $base));
101
-            $schema->{'$ref'} = (string) $refPointer;
102
-        }
103
-
104
-        foreach ($schema as &$member) {
105
-            $this->expandRefs($member, $base);
106
-        }
107
-    }
108
-
109
-    /**
110
-     * {@inheritdoc}
111
-     */
112
-    public function getSchema($id)
113
-    {
114
-        if (!array_key_exists($id, $this->schemas)) {
115
-            $this->addSchema($id);
116
-        }
117
-
118
-        return $this->schemas[$id];
119
-    }
120
-
121
-    /**
122
-     * {@inheritdoc}
123
-     */
124
-    public function resolveRef($ref)
125
-    {
126
-        $jsonPointer = new JsonPointer($ref);
127
-
128
-        // resolve filename for pointer
129
-        $fileName = $jsonPointer->getFilename();
130
-        if (!strlen($fileName)) {
131
-            throw new UnresolvableJsonPointerException(sprintf(
132
-                "Could not resolve fragment '%s': no file is defined",
133
-                $jsonPointer->getPropertyPathAsString()
134
-            ));
135
-        }
136
-
137
-        // get & process the schema
138
-        $refSchema = $this->getSchema($fileName);
139
-        foreach ($jsonPointer->getPropertyPaths() as $path) {
140
-            if (is_object($refSchema) && property_exists($refSchema, $path)) {
141
-                $refSchema = $this->resolveRefSchema($refSchema->{$path});
142
-            } elseif (is_array($refSchema) && array_key_exists($path, $refSchema)) {
143
-                $refSchema = $this->resolveRefSchema($refSchema[$path]);
144
-            } else {
145
-                throw new UnresolvableJsonPointerException(sprintf(
146
-                    'File: %s is found, but could not resolve fragment: %s',
147
-                    $jsonPointer->getFilename(),
148
-                    $jsonPointer->getPropertyPathAsString()
149
-                ));
150
-            }
151
-        }
152
-
153
-        return $refSchema;
154
-    }
155
-
156
-    /**
157
-     * {@inheritdoc}
158
-     */
159
-    public function resolveRefSchema($refSchema)
160
-    {
161
-        if (is_object($refSchema) && property_exists($refSchema, '$ref') && is_string($refSchema->{'$ref'})) {
162
-            $newSchema = $this->resolveRef($refSchema->{'$ref'});
163
-            $refSchema = (object) (get_object_vars($refSchema) + get_object_vars($newSchema));
164
-            unset($refSchema->{'$ref'});
165
-        }
166
-
167
-        return $refSchema;
168
-    }
13
+	const INTERNAL_PROVIDED_SCHEMA_URI = 'internal://provided-schema/';
14
+
15
+	protected $uriRetriever;
16
+	protected $uriResolver;
17
+	protected $schemas = array();
18
+
19
+	public function __construct(
20
+		UriRetrieverInterface $uriRetriever = null,
21
+		UriResolverInterface $uriResolver = null
22
+	) {
23
+		$this->uriRetriever = $uriRetriever ?: new UriRetriever();
24
+		$this->uriResolver = $uriResolver ?: new UriResolver();
25
+	}
26
+
27
+	/**
28
+	 * @return UriRetrieverInterface
29
+	 */
30
+	public function getUriRetriever()
31
+	{
32
+		return $this->uriRetriever;
33
+	}
34
+
35
+	/**
36
+	 * @return UriResolverInterface
37
+	 */
38
+	public function getUriResolver()
39
+	{
40
+		return $this->uriResolver;
41
+	}
42
+
43
+	/**
44
+	 * {@inheritdoc}
45
+	 */
46
+	public function addSchema($id, $schema = null)
47
+	{
48
+		if (is_null($schema) && $id !== self::INTERNAL_PROVIDED_SCHEMA_URI) {
49
+			// if the schema was user-provided to Validator and is still null, then assume this is
50
+			// what the user intended, as there's no way for us to retrieve anything else. User-supplied
51
+			// schemas do not have an associated URI when passed via Validator::validate().
52
+			$schema = $this->uriRetriever->retrieve($id);
53
+		}
54
+
55
+		// cast array schemas to object
56
+		if (is_array($schema)) {
57
+			$schema = BaseConstraint::arrayToObjectRecursive($schema);
58
+		}
59
+
60
+		// workaround for bug in draft-03 & draft-04 meta-schemas (id & $ref defined with incorrect format)
61
+		// see https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/177#issuecomment-293051367
62
+		if (is_object($schema) && property_exists($schema, 'id')) {
63
+			if ($schema->id == 'http://json-schema.org/draft-04/schema#') {
64
+				$schema->properties->id->format = 'uri-reference';
65
+			} elseif ($schema->id == 'http://json-schema.org/draft-03/schema#') {
66
+				$schema->properties->id->format = 'uri-reference';
67
+				$schema->properties->{'$ref'}->format = 'uri-reference';
68
+			}
69
+		}
70
+
71
+		// resolve references
72
+		$this->expandRefs($schema, $id);
73
+
74
+		$this->schemas[$id] = $schema;
75
+	}
76
+
77
+	/**
78
+	 * Recursively resolve all references against the provided base
79
+	 *
80
+	 * @param mixed  $schema
81
+	 * @param string $base
82
+	 */
83
+	private function expandRefs(&$schema, $base = null)
84
+	{
85
+		if (!is_object($schema)) {
86
+			if (is_array($schema)) {
87
+				foreach ($schema as &$member) {
88
+					$this->expandRefs($member, $base);
89
+				}
90
+			}
91
+
92
+			return;
93
+		}
94
+
95
+		if (property_exists($schema, 'id') && is_string($schema->id) && $base != $schema->id) {
96
+			$base = $this->uriResolver->resolve($schema->id, $base);
97
+		}
98
+
99
+		if (property_exists($schema, '$ref') && is_string($schema->{'$ref'})) {
100
+			$refPointer = new JsonPointer($this->uriResolver->resolve($schema->{'$ref'}, $base));
101
+			$schema->{'$ref'} = (string) $refPointer;
102
+		}
103
+
104
+		foreach ($schema as &$member) {
105
+			$this->expandRefs($member, $base);
106
+		}
107
+	}
108
+
109
+	/**
110
+	 * {@inheritdoc}
111
+	 */
112
+	public function getSchema($id)
113
+	{
114
+		if (!array_key_exists($id, $this->schemas)) {
115
+			$this->addSchema($id);
116
+		}
117
+
118
+		return $this->schemas[$id];
119
+	}
120
+
121
+	/**
122
+	 * {@inheritdoc}
123
+	 */
124
+	public function resolveRef($ref)
125
+	{
126
+		$jsonPointer = new JsonPointer($ref);
127
+
128
+		// resolve filename for pointer
129
+		$fileName = $jsonPointer->getFilename();
130
+		if (!strlen($fileName)) {
131
+			throw new UnresolvableJsonPointerException(sprintf(
132
+				"Could not resolve fragment '%s': no file is defined",
133
+				$jsonPointer->getPropertyPathAsString()
134
+			));
135
+		}
136
+
137
+		// get & process the schema
138
+		$refSchema = $this->getSchema($fileName);
139
+		foreach ($jsonPointer->getPropertyPaths() as $path) {
140
+			if (is_object($refSchema) && property_exists($refSchema, $path)) {
141
+				$refSchema = $this->resolveRefSchema($refSchema->{$path});
142
+			} elseif (is_array($refSchema) && array_key_exists($path, $refSchema)) {
143
+				$refSchema = $this->resolveRefSchema($refSchema[$path]);
144
+			} else {
145
+				throw new UnresolvableJsonPointerException(sprintf(
146
+					'File: %s is found, but could not resolve fragment: %s',
147
+					$jsonPointer->getFilename(),
148
+					$jsonPointer->getPropertyPathAsString()
149
+				));
150
+			}
151
+		}
152
+
153
+		return $refSchema;
154
+	}
155
+
156
+	/**
157
+	 * {@inheritdoc}
158
+	 */
159
+	public function resolveRefSchema($refSchema)
160
+	{
161
+		if (is_object($refSchema) && property_exists($refSchema, '$ref') && is_string($refSchema->{'$ref'})) {
162
+			$newSchema = $this->resolveRef($refSchema->{'$ref'});
163
+			$refSchema = (object) (get_object_vars($refSchema) + get_object_vars($newSchema));
164
+			unset($refSchema->{'$ref'});
165
+		}
166
+
167
+		return $refSchema;
168
+	}
169 169
 }
Please login to merge, or discard this patch.
vendor/nikic/php-parser/lib/PhpParser/Node/Name/Relative.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -4,47 +4,47 @@
 block discarded – undo
4 4
 
5 5
 class Relative extends \PhpParser\Node\Name
6 6
 {
7
-    /**
8
-     * Checks whether the name is unqualified. (E.g. Name)
9
-     *
10
-     * @return bool Whether the name is unqualified
11
-     */
12
-    public function isUnqualified() : bool {
13
-        return false;
14
-    }
7
+	/**
8
+	 * Checks whether the name is unqualified. (E.g. Name)
9
+	 *
10
+	 * @return bool Whether the name is unqualified
11
+	 */
12
+	public function isUnqualified() : bool {
13
+		return false;
14
+	}
15 15
 
16
-    /**
17
-     * Checks whether the name is qualified. (E.g. Name\Name)
18
-     *
19
-     * @return bool Whether the name is qualified
20
-     */
21
-    public function isQualified() : bool {
22
-        return false;
23
-    }
16
+	/**
17
+	 * Checks whether the name is qualified. (E.g. Name\Name)
18
+	 *
19
+	 * @return bool Whether the name is qualified
20
+	 */
21
+	public function isQualified() : bool {
22
+		return false;
23
+	}
24 24
 
25
-    /**
26
-     * Checks whether the name is fully qualified. (E.g. \Name)
27
-     *
28
-     * @return bool Whether the name is fully qualified
29
-     */
30
-    public function isFullyQualified() : bool {
31
-        return false;
32
-    }
25
+	/**
26
+	 * Checks whether the name is fully qualified. (E.g. \Name)
27
+	 *
28
+	 * @return bool Whether the name is fully qualified
29
+	 */
30
+	public function isFullyQualified() : bool {
31
+		return false;
32
+	}
33 33
 
34
-    /**
35
-     * Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name)
36
-     *
37
-     * @return bool Whether the name is relative
38
-     */
39
-    public function isRelative() : bool {
40
-        return true;
41
-    }
34
+	/**
35
+	 * Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name)
36
+	 *
37
+	 * @return bool Whether the name is relative
38
+	 */
39
+	public function isRelative() : bool {
40
+		return true;
41
+	}
42 42
 
43
-    public function toCodeString() : string {
44
-        return 'namespace\\' . $this->toString();
45
-    }
43
+	public function toCodeString() : string {
44
+		return 'namespace\\' . $this->toString();
45
+	}
46 46
     
47
-    public function getType() : string {
48
-        return 'Name_Relative';
49
-    }
47
+	public function getType() : string {
48
+		return 'Name_Relative';
49
+	}
50 50
 }
Please login to merge, or discard this patch.