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
- )));
30
+ if (!file_exists ($ uri )) {
31
+ throw new ResourceNotFoundException ('JSON schema not found at ' . $ uri );
32
+ }
35
33
36
- $ response = @ file_get_contents ($ uri );
34
+ $ response = file_get_contents ($ uri );
37
35
38
36
if (false === $ response ) {
39
- throw new ResourceNotFoundException ('JSON schema not found at ' . $ uri );
37
+ throw new ResourceNotFoundException ('JSON schema was not retrieved at ' . $ uri );
40
38
}
39
+
41
40
if ($ response == ''
42
41
&& substr ($ uri , 0 , 7 ) == 'file:// ' && substr ($ uri , -1 ) == '/ '
43
42
) {
@@ -51,10 +50,10 @@ public function retrieve($uri)
51
50
// Could be a "file://" url or something else - fake up the response
52
51
$ this ->contentType = null ;
53
52
}
54
-
53
+
55
54
return $ this ->messageBody ;
56
55
}
57
-
56
+
58
57
/**
59
58
* @param array $headers HTTP Response Headers
60
59
* @return boolean Whether the Content-Type header was found or not
@@ -66,10 +65,10 @@ private function fetchContentType(array $headers)
66
65
return true ;
67
66
}
68
67
}
69
-
68
+
70
69
return false ;
71
70
}
72
-
71
+
73
72
/**
74
73
* @param string $header
75
74
* @return string|null
0 commit comments