Skip to content

Commit a4a8226

Browse files
authored
Merge pull request #1125 from hydephp/refactor-hyde-path-helper
Refactor the Hyde::path() helper to normalize already absolute paths
2 parents 8d9fe40 + 6fce399 commit a4a8226

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

packages/framework/src/Console/Concerns/Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function handleException(Exception $exception): int
8484
*/
8585
public static function fileLink(string $filepath, string $label = null): string
8686
{
87-
$link = 'file://'.str_replace('\\', '/', realpath($filepath) ?: Hyde::path(Hyde::pathToRelative($filepath)));
87+
$link = 'file://'.str_replace('\\', '/', realpath($filepath) ?: Hyde::path($filepath));
8888

8989
return $label ? "<href=$link>$label</>" : $link;
9090
}

packages/framework/src/Foundation/Kernel/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function path(string $path = ''): string
6161
return $this->getBasePath();
6262
}
6363

64-
$path = unslash($path);
64+
$path = unslash($this->pathToRelative($path));
6565

6666
return path_join($this->getBasePath(), $path);
6767
}

packages/framework/tests/Feature/Foundation/FilesystemTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ public function test_path_method_returns_expected_value_regardless_of_trailing_d
9191
$this->assertEquals('/foo/bar/file.php', $this->filesystem->path('\\/bar/file.php/'));
9292
}
9393

94+
public function test_path_method_resolves_already_absolute_paths()
95+
{
96+
Hyde::getInstance()->setBasePath('/foo');
97+
$this->assertEquals('/foo/bar', $this->filesystem->path('/foo/bar'));
98+
}
99+
100+
public function test_path_method_resolves_already_absolute_paths_using_helper()
101+
{
102+
$this->assertEquals($this->filesystem->path('foo'), $this->filesystem->path($this->filesystem->path('foo')));
103+
}
104+
105+
public function test_path_method_resolves_already_absolute_paths_using_helper_with_trailing_slash()
106+
{
107+
$this->assertEquals($this->filesystem->path('foo'), $this->filesystem->path($this->filesystem->path('foo/')));
108+
}
109+
94110
public function test_vendor_path_method_exists()
95111
{
96112
$this->assertTrue(method_exists(Filesystem::class, 'vendorPath'));

0 commit comments

Comments
 (0)