Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/JsonSchema/Uri/UriResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ public function generate(array $components)
return $uri;
}

/**
* Custom realpath implementation to
* make results consistent in Windows and *nix
* environments.
*
* @param string $path
* The path being checked.
*/
protected function realpath($path)
{
$scheme = 'file://';
$scheme_length = strlen($scheme);
if (strcasecmp(substr($path, 0, $scheme_length), $scheme) === 0) {
// realpath on Windows will fail to properly expand
// paths with the file:// scheme.
$path = substr($path, $scheme_length, strlen($path) - $scheme_length);
return realpath($path);
}
return realpath($path);
}

/**
* {@inheritdoc}
*/
Expand All @@ -79,9 +100,9 @@ public function resolve($uri, $baseUri = null)
// treat non-uri base as local file path
if (!is_null($baseUri) && !filter_var($baseUri, \FILTER_VALIDATE_URL)) {
if (is_file($baseUri)) {
$baseUri = 'file://' . realpath($baseUri);
$baseUri = 'file://' . $this->realpath($baseUri);
} elseif (is_dir($baseUri)) {
$baseUri = 'file://' . realpath($baseUri) . '/';
$baseUri = 'file://' . $this->realpath($baseUri) . '/';
} else {
$baseUri = 'file://' . getcwd() . '/' . $baseUri;
}
Expand Down