Skip to content

Commit fa4ed19

Browse files
caendesilvagithub-actions[bot]
authored andcommitted
Merge pull request #2227 from hydephp/herd-valet-support
Add experimental support for Laravel Herd hydephp/develop@c0ea2b5
1 parent b6a4a0d commit fa4ed19

File tree

4 files changed

+171
-2
lines changed

4 files changed

+171
-2
lines changed

bin/server.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

33
try {
4-
define('BASE_PATH', realpath(getcwd()));
4+
define('BASE_PATH', isset($_SERVER['HERD_SITE_PATH']) ? realpath($_SERVER['HERD_SITE_PATH']) : realpath(getcwd()));
55
define('HYDE_START', microtime(true));
66

7+
if (isset($_SERVER['HERD_SITE_PATH'])) {
8+
chdir($_SERVER['HERD_SITE_PATH']);
9+
}
10+
711
require getenv('HYDE_AUTOLOAD_PATH') ?: BASE_PATH.'/vendor/autoload.php';
812

913
try {

resources/stubs/HydeValetDriver.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
namespace Valet\Drivers\Custom;
4+
5+
use Composer\InstalledVersions;
6+
use Valet\Drivers\BasicValetDriver;
7+
8+
/**
9+
* @experimental This driver is experimental and may be unstable. Report issues at GitHub!
10+
*
11+
* @see https://github.com/hydephp/realtime-compiler/pull/30
12+
*/
13+
class HydeValetDriver extends BasicValetDriver
14+
{
15+
/**
16+
* Determine if the driver serves the request.
17+
*/
18+
public function serves(string $sitePath, string $siteName, string $uri): bool
19+
{
20+
return file_exists($sitePath.'/hyde');
21+
}
22+
23+
/**
24+
* Take any steps necessary before loading the front controller for this driver.
25+
*/
26+
public function beforeLoading(string $sitePath, string $siteName, string $uri): void
27+
{
28+
// Set the correct autoloader path for the realtime compiler
29+
putenv('HYDE_AUTOLOAD_PATH='.$sitePath.'/vendor/autoload.php');
30+
}
31+
32+
/**
33+
* Determine if the incoming request is for a static file.
34+
*/
35+
public function isStaticFile(string $sitePath, string $siteName, string $uri): false
36+
{
37+
return false; // Handled by the realtime compiler
38+
}
39+
40+
/**
41+
* Get the fully resolved path to the application's front controller.
42+
*/
43+
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
44+
{
45+
return $sitePath.'/vendor/hyde/realtime-compiler/bin/server.php';
46+
}
47+
48+
/**
49+
* Get the logs paths for the application to show in Herds log viewer.
50+
*/
51+
public function logFilesPaths(): array
52+
{
53+
return ['/storage/logs'];
54+
}
55+
56+
/**
57+
* Display information about the application in the information tab of the Sites UI.
58+
*/
59+
public function siteInformation(string $sitePath, string $phpBinary): array
60+
{
61+
$composerJson = json_decode(file_get_contents($sitePath.'/composer.json'), true);
62+
$hydeConfig = include $sitePath.'/config/hyde.php';
63+
64+
return [
65+
'HydePHP Info' => [
66+
'Hyde Version' => InstalledVersions::isInstalled('hyde/hyde') ? InstalledVersions::getPrettyVersion('hyde/hyde') : 'Unknown',
67+
'Framework Version' => InstalledVersions::getPrettyVersion('hyde/framework') ?: 'Unknown',
68+
'Site Name' => $hydeConfig['name'] ?? 'Unknown',
69+
'Site URL' => $hydeConfig['url'] ?? 'Not set',
70+
'Site Language' => $hydeConfig['language'] ?? 'en',
71+
'Output Directory' => $hydeConfig['output_directory'] ?? '_site',
72+
],
73+
'Build Info' => [
74+
'Pretty URLs' => $hydeConfig['pretty_urls'] ? 'Enabled' : 'Disabled',
75+
'Generate Sitemap' => $hydeConfig['generate_sitemap'] ? 'Yes' : 'No',
76+
'RSS Feed' => ($hydeConfig['rss']['enabled'] ?? false) ? 'Enabled' : 'Disabled',
77+
'Source Root' => $hydeConfig['source_root'] ?: '(Project Root)',
78+
],
79+
'Features' => [
80+
'Enabled Features' => implode(', ', array_map(function ($feature) {
81+
return $feature->name;
82+
}, $hydeConfig['features'] ?? [])),
83+
],
84+
'Server Configuration' => [
85+
'Port' => $hydeConfig['server']['port'] ?? 8080,
86+
'Host' => $hydeConfig['server']['host'] ?? 'localhost',
87+
'Save Preview' => ($hydeConfig['server']['save_preview'] ?? true) ? 'Yes' : 'No',
88+
'Live Edit' => ($hydeConfig['server']['live_edit'] ?? false) ? 'Enabled' : 'Disabled',
89+
'Dashboard' => ($hydeConfig['server']['dashboard']['enabled'] ?? true) ? 'Enabled' : 'Disabled',
90+
],
91+
];
92+
}
93+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hyde\RealtimeCompiler\Console\Commands;
6+
7+
use Hyde\Hyde;
8+
use Hyde\Console\Concerns\Command;
9+
use Illuminate\Support\Facades\File;
10+
use Exception;
11+
12+
/**
13+
* @experimental This command is experimental and may be unstable. Report issues at GitHub!
14+
*
15+
* @see https://github.com/hydephp/realtime-compiler/pull/30
16+
*/
17+
class HerdInstallCommand extends Command
18+
{
19+
/** @var string */
20+
protected $signature = 'herd:install {--force : Overwrite any existing file}';
21+
22+
/** @var string */
23+
protected $description = '[Experimental] Install the HydePHP Valet driver for Laravel Herd';
24+
25+
public function safeHandle(): int
26+
{
27+
$driverTargetPath = $this->getDriverTargetPath();
28+
$driverSourcePath = Hyde::vendorPath('resources/stubs/HydeValetDriver.php', 'realtime-compiler');
29+
30+
if (! is_dir(dirname($driverTargetPath))) {
31+
$this->error('Herd Valet drivers directory not found. Is Herd installed?');
32+
33+
return Command::FAILURE;
34+
}
35+
36+
if (file_exists($driverTargetPath) && ! $this->option('force')) {
37+
if (! $this->confirm('The HydePHP Valet driver for Herd already exists. Do you want to overwrite it?', true)) {
38+
$this->info('Installation cancelled.');
39+
40+
return Command::SUCCESS;
41+
}
42+
}
43+
44+
try {
45+
File::copy($driverSourcePath, $driverTargetPath);
46+
$this->info('HydePHP Valet driver for Herd successfully installed!');
47+
$this->line('Driver path: '.$driverTargetPath);
48+
49+
return Command::SUCCESS;
50+
} catch (Exception $exception) {
51+
$this->error('Failed to install the HydePHP Valet driver: '.$exception->getMessage());
52+
53+
return Command::FAILURE;
54+
}
55+
}
56+
57+
private function getDriverTargetPath(): string
58+
{
59+
return match (PHP_OS_FAMILY) {
60+
'Darwin' => $_SERVER['HOME'].'/Library/Application Support/Herd/config/valet/Drivers/HydeValetDriver.php',
61+
'Windows' => $_SERVER['USERPROFILE'].'\.config\herd\config\valet\Drivers\HydeValetDriver.php',
62+
default => throw new Exception('Herd is not yet supported on Linux.'),
63+
};
64+
}
65+
}

src/RealtimeCompilerServiceProvider.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
namespace Hyde\RealtimeCompiler;
66

77
use Illuminate\Support\ServiceProvider;
8-
use Hyde\RealtimeCompiler\Http\LiveEditController;
98
use Hyde\RealtimeCompiler\Http\DashboardController;
9+
use Hyde\RealtimeCompiler\Http\LiveEditController;
1010
use Hyde\RealtimeCompiler\Http\VirtualRouteController;
11+
use Hyde\RealtimeCompiler\Console\Commands\HerdInstallCommand;
1112

1213
class RealtimeCompilerServiceProvider extends ServiceProvider
1314
{
1415
public function register(): void
1516
{
1617
$this->app->singleton(RealtimeCompiler::class);
18+
19+
if ($this->app->runningInConsole()) {
20+
$this->commands([
21+
HerdInstallCommand::class,
22+
]);
23+
}
1724
}
1825

1926
public function boot(): void

0 commit comments

Comments
 (0)