14
14
15
15
/**
16
16
* Tries to retrieve JSON schemas from a URI using file_get_contents()
17
- *
18
- * @author Sander Coolen <[email protected] >
17
+ *
18
+ * @author Sander Coolen <[email protected] >
19
19
*/
20
20
class FileGetContents extends AbstractRetriever
21
21
{
22
22
protected $ messageBody ;
23
-
23
+
24
24
/**
25
25
* {@inheritDoc}
26
26
* @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve()
27
27
*/
28
28
public function retrieve ($ uri )
29
29
{
30
- $ context = stream_context_create (array (
31
- 'http ' => array (
32
- 'method ' => 'GET ' ,
33
- 'header ' => "Accept: " . Validator::SCHEMA_MEDIA_TYPE
34
- )));
35
-
36
- set_error_handler (function () use ($ uri ) {
30
+ if (!file_exists ($ uri )) {
37
31
throw new ResourceNotFoundException ('JSON schema not found at ' . $ uri );
38
- });
32
+ }
33
+
39
34
$ response = file_get_contents ($ uri );
40
- restore_error_handler ();
41
35
42
36
if (false === $ response ) {
43
- throw new ResourceNotFoundException ('JSON schema not found at ' . $ uri );
37
+ throw new ResourceNotFoundException ('JSON schema was not retrieved at ' . $ uri );
44
38
}
39
+
45
40
if ($ response == ''
46
41
&& substr ($ uri , 0 , 7 ) == 'file:// ' && substr ($ uri , -1 ) == '/ '
47
42
) {
@@ -55,10 +50,10 @@ public function retrieve($uri)
55
50
// Could be a "file://" url or something else - fake up the response
56
51
$ this ->contentType = null ;
57
52
}
58
-
53
+
59
54
return $ this ->messageBody ;
60
55
}
61
-
56
+
62
57
/**
63
58
* @param array $headers HTTP Response Headers
64
59
* @return boolean Whether the Content-Type header was found or not
@@ -70,10 +65,10 @@ private function fetchContentType(array $headers)
70
65
return true ;
71
66
}
72
67
}
73
-
68
+
74
69
return false ;
75
70
}
76
-
71
+
77
72
/**
78
73
* @param string $header
79
74
* @return string|null
0 commit comments