Skip to content

Commit 1cc10c5

Browse files
Deleted unused stream context and check if a local file exists
1 parent 2765c50 commit 1cc10c5

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/JsonSchema/Uri/Retrievers/FileGetContents.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +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-
)));
30+
if (!file_exists($uri)) {
31+
throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
32+
}
3533

36-
$response = @file_get_contents($uri);
34+
$response = file_get_contents($uri);
3735

3836
if (false === $response) {
39-
throw new ResourceNotFoundException('JSON schema not found at ' . $uri);
37+
throw new ResourceNotFoundException('JSON schema was not retrieved at ' . $uri);
4038
}
39+
4140
if ($response == ''
4241
&& substr($uri, 0, 7) == 'file://' && substr($uri, -1) == '/'
4342
) {
@@ -51,10 +50,10 @@ public function retrieve($uri)
5150
// Could be a "file://" url or something else - fake up the response
5251
$this->contentType = null;
5352
}
54-
53+
5554
return $this->messageBody;
5655
}
57-
56+
5857
/**
5958
* @param array $headers HTTP Response Headers
6059
* @return boolean Whether the Content-Type header was found or not
@@ -66,10 +65,10 @@ private function fetchContentType(array $headers)
6665
return true;
6766
}
6867
}
69-
68+
7069
return false;
7170
}
72-
71+
7372
/**
7473
* @param string $header
7574
* @return string|null

0 commit comments

Comments
 (0)