diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e3d1b60364c..5e075dcdba1 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -22,7 +22,7 @@ This serves two purposes: - for now removed features. ### Fixed -- for any bug fixes. +- Improved support for running HydePHP through the Phar archive in https://github.com/hydephp/develop/pull/1491 ### Security - in case of vulnerabilities. diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index dcc8f79ed73..883663d3f31 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/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/packages/framework/src/Foundation/PharSupport.php b/packages/framework/src/Foundation/PharSupport.php index 7f76b02f0d4..7117df5b884 100644 --- a/packages/framework/src/Foundation/PharSupport.php +++ b/packages/framework/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/packages/framework/tests/Feature/Foundation/FilesystemTest.php b/packages/framework/tests/Feature/Foundation/FilesystemTest.php index 30400cee8ff..a21c3ccd041 100644 --- a/packages/framework/tests/Feature/Foundation/FilesystemTest.php +++ b/packages/framework/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/packages/framework/tests/Feature/PharSupportTest.php b/packages/framework/tests/Feature/PharSupportTest.php index 8bca9b57805..f6e46f32241 100644 --- a/packages/framework/tests/Feature/PharSupportTest.php +++ b/packages/framework/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 diff --git a/packages/realtime-compiler/src/Http/DashboardController.php b/packages/realtime-compiler/src/Http/DashboardController.php index 15d30dacd67..08e15fb85a8 100644 --- a/packages/realtime-compiler/src/Http/DashboardController.php +++ b/packages/realtime-compiler/src/Http/DashboardController.php @@ -13,6 +13,7 @@ use Hyde\Pages\MarkdownPost; use Desilva\Microserve\Request; use Desilva\Microserve\Response; +use Hyde\Foundation\PharSupport; use Hyde\Pages\Concerns\HydePage; use Hyde\Pages\DocumentationPage; use Hyde\Support\Models\RouteKey; @@ -261,7 +262,11 @@ public function isInteractive(): bool public function getScripts(): string { - return file_get_contents(__DIR__.'/../../resources/dashboard.js'); + if (PharSupport::running()) { + return file_get_contents('phar://hyde.phar/vendor/hyde/realtime-compiler/resources/dashboard.js'); + } + + return file_get_contents(Hyde::vendorPath('resources/dashboard.js', 'realtime-compiler')); } public function getFlash(string $key, $default = null): ?string