Skip to content

Commit 780dd6f

Browse files
Deleted unused stream context and check if a local file exists
1 parent 9ef71fd commit 780dd6f

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/JsonSchema/Uri/Retrievers/FileGetContents.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,29 @@
1414

1515
/**
1616
* 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]>
1919
*/
2020
class FileGetContents extends AbstractRetriever
2121
{
2222
protected $messageBody;
23-
23+
2424
/**
2525
* {@inheritDoc}
2626
* @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve()
2727
*/
2828
public function retrieve($uri)
2929
{
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)) {
3731
throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
38-
});
32+
}
33+
3934
$response = file_get_contents($uri);
40-
restore_error_handler();
4135

4236
if (false === $response) {
43-
throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
37+
throw new ResourceNotFoundException('JSON schema was not retrieved at ' . $uri);
4438
}
39+
4540
if ($response == ''
4641
&& substr($uri, 0, 7) == 'file://' && substr($uri, -1) == '/'
4742
) {
@@ -55,10 +50,10 @@ public function retrieve($uri)
5550
// Could be a "file://" url or something else - fake up the response
5651
$this->contentType = null;
5752
}
58-
53+
5954
return $this->messageBody;
6055
}
61-
56+
6257
/**
6358
* @param array $headers HTTP Response Headers
6459
* @return boolean Whether the Content-Type header was found or not
@@ -70,10 +65,10 @@ private function fetchContentType(array $headers)
7065
return true;
7166
}
7267
}
73-
68+
7469
return false;
7570
}
76-
71+
7772
/**
7873
* @param string $header
7974
* @return string|null

0 commit comments

Comments
 (0)