diff --git a/src/Foundation/HydeKernel.php b/src/Foundation/HydeKernel.php index 3b65f666..b7c8205b 100644 --- a/src/Foundation/HydeKernel.php +++ b/src/Foundation/HydeKernel.php @@ -49,7 +49,7 @@ class HydeKernel implements SerializableContract use Serializable; use Macroable; - final public const VERSION = '1.4.0'; + final public const VERSION = '1.4.1'; protected static self $instance; diff --git a/src/Foundation/Kernel/Filesystem.php b/src/Foundation/Kernel/Filesystem.php index dcc8f79e..883663d3 100644 --- a/src/Foundation/Kernel/Filesystem.php +++ b/src/Foundation/Kernel/Filesystem.php @@ -56,6 +56,10 @@ public function path(string $path = ''): string return $this->getBasePath(); } + if (str_starts_with($path, 'phar://')) { + return $path; + } + $path = unslash($this->pathToRelative($path)); return path_join($this->getBasePath(), $path); diff --git a/src/Foundation/PharSupport.php b/src/Foundation/PharSupport.php index 7f76b02f..7117df5b 100644 --- a/src/Foundation/PharSupport.php +++ b/src/Foundation/PharSupport.php @@ -6,7 +6,6 @@ use Hyde\Hyde; use Phar; -use BadMethodCallException; use function dirname; use function is_dir; @@ -47,10 +46,6 @@ public static function hasVendorDirectory(): bool public static function vendorPath(string $path = '', string $package = 'framework'): string { - if ($package !== 'framework') { - throw new BadMethodCallException('Cannot use vendorPath() outside of the framework package when running from a Phar archive.'); - } - - return rtrim(str_replace('/', DIRECTORY_SEPARATOR, rtrim(dirname(__DIR__, 2).'/'.$path, '/\\')), '/\\'); + return rtrim(str_replace('/', DIRECTORY_SEPARATOR, rtrim(dirname(__DIR__, 3).'/'.$package.'/'.$path, '/\\')), '/\\'); } } diff --git a/tests/Feature/Foundation/FilesystemTest.php b/tests/Feature/Foundation/FilesystemTest.php index 30400cee..a21c3ccd 100644 --- a/tests/Feature/Foundation/FilesystemTest.php +++ b/tests/Feature/Foundation/FilesystemTest.php @@ -115,6 +115,11 @@ public function testPathMethodResolvesAlreadyAbsolutePathsUsingHelperWithTrailin $this->assertSame($this->filesystem->path('foo'), $this->filesystem->path($this->filesystem->path('foo/'))); } + public function testPathMethodDoesNotModifyPharPaths() + { + $this->assertSame('phar://foo', $this->filesystem->path('phar://foo')); + } + public function testHydePathMethodExists() { $this->assertTrue(method_exists(HydeKernel::class, 'path')); diff --git a/tests/Feature/PharSupportTest.php b/tests/Feature/PharSupportTest.php index 8bca9b57..f6e46f32 100644 --- a/tests/Feature/PharSupportTest.php +++ b/tests/Feature/PharSupportTest.php @@ -4,7 +4,6 @@ namespace Hyde\Framework\Testing\Feature; -use BadMethodCallException; use Hyde\Foundation\PharSupport; use Hyde\Hyde; use Hyde\Testing\TestCase; @@ -65,16 +64,6 @@ public function test_vendor_path_can_run_in_phar_with_path_argument() $this->assertEquals($this->replaceSlashes(Hyde::path("{$this->getBaseVendorPath()}/framework/file.php")), Hyde::vendorPath('file.php')); } - public function test_vendor_path_can_run_in_phar_with_package_argument_but_throws() - { - PharSupport::mock('running', true); - PharSupport::mock('hasVendorDirectory', false); - - $this->expectException(BadMethodCallException::class); - - Hyde::vendorPath(package: 'realtime-compiler'); - } - protected function getBaseVendorPath(): string { // Monorepo support for symlinked packages directory