Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ This serves two purposes:

- Simplified the asset file locator to only serve files from the media source directory in https://github.com/hydephp/develop/pull/2012
- Added Vite HMR support in https://github.com/hydephp/develop/pull/2016
- Added experimental Laravel Herd support in https://github.com/hydephp/develop/pull/2227

#### HydeFront

Expand Down
27 changes: 27 additions & 0 deletions docs/extensions/realtime-compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,33 @@ The live editor plugin code will not be saved to your static site.
],
```

### Herd Integration

#### Usage

Since HydePHP v2 (Realtime Compiler v4), HydePHP has an experimental integration with [Herd](https://herd.laravel.com/) to provide a seamless development experience. The realtime compiler includes a custom Valet driver that allows Herd to serve your HydePHP site.

To install the Valet driver for Herd, run the following command:

```bash
php hyde herd:install
```

This will copy the HydeValetDriver to your Herd configuration directory, allowing Herd to automatically serve your HydePHP site.

#### Features

When using the Herd integration, you get the following benefits:

- Automatic site detection for HydePHP projects
- The realtime compiler is used to serve your site
- Proper handling of static files and dynamic routes
- Site information displayed in the Herd UI

> The Herd integration requires Herd to be installed on your system.

>warning The Herd integration is experimental and may be unstable. [Report issues at GitHub](https://github.com/hydephp/realtime-compiler/pull/30)!

### Source code

- **GitHub**: [hydephp/realtime-compiler](https://github.com/hydephp/realtime-compiler)
Expand Down
6 changes: 5 additions & 1 deletion packages/realtime-compiler/bin/server.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

try {
define('BASE_PATH', realpath(getcwd()));
define('BASE_PATH', isset($_SERVER['HERD_SITE_PATH']) ? realpath($_SERVER['HERD_SITE_PATH']) : realpath(getcwd()));
define('HYDE_START', microtime(true));

if (isset($_SERVER['HERD_SITE_PATH'])) {
chdir($_SERVER['HERD_SITE_PATH']);
}

require getenv('HYDE_AUTOLOAD_PATH') ?: BASE_PATH.'/vendor/autoload.php';

try {
Expand Down
93 changes: 93 additions & 0 deletions packages/realtime-compiler/resources/stubs/HydeValetDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace Valet\Drivers\Custom;

use Composer\InstalledVersions;
use Valet\Drivers\BasicValetDriver;

/**
* @experimental This driver is experimental and may be unstable. Report issues at GitHub!
*
* @see https://github.com/hydephp/realtime-compiler/pull/30
*/
class HydeValetDriver extends BasicValetDriver
{
/**
* Determine if the driver serves the request.
*/
public function serves(string $sitePath, string $siteName, string $uri): bool
{
return file_exists($sitePath.'/hyde');
}

/**
* Take any steps necessary before loading the front controller for this driver.
*/
public function beforeLoading(string $sitePath, string $siteName, string $uri): void
{
// Set the correct autoloader path for the realtime compiler
putenv('HYDE_AUTOLOAD_PATH='.$sitePath.'/vendor/autoload.php');
}

/**
* Determine if the incoming request is for a static file.
*/
public function isStaticFile(string $sitePath, string $siteName, string $uri): false
{
return false; // Handled by the realtime compiler
}

/**
* Get the fully resolved path to the application's front controller.
*/
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
{
return $sitePath.'/vendor/hyde/realtime-compiler/bin/server.php';
}

/**
* Get the logs paths for the application to show in Herds log viewer.
*/
public function logFilesPaths(): array
{
return ['/storage/logs'];
}

/**
* Display information about the application in the information tab of the Sites UI.
*/
public function siteInformation(string $sitePath, string $phpBinary): array
{
$composerJson = json_decode(file_get_contents($sitePath.'/composer.json'), true);
$hydeConfig = include $sitePath.'/config/hyde.php';

return [
'HydePHP Info' => [
'Hyde Version' => InstalledVersions::isInstalled('hyde/hyde') ? InstalledVersions::getPrettyVersion('hyde/hyde') : 'Unknown',
'Framework Version' => InstalledVersions::getPrettyVersion('hyde/framework') ?: 'Unknown',
'Site Name' => $hydeConfig['name'] ?? 'Unknown',
'Site URL' => $hydeConfig['url'] ?? 'Not set',
'Site Language' => $hydeConfig['language'] ?? 'en',
'Output Directory' => $hydeConfig['output_directory'] ?? '_site',
],
'Build Info' => [
'Pretty URLs' => $hydeConfig['pretty_urls'] ? 'Enabled' : 'Disabled',
'Generate Sitemap' => $hydeConfig['generate_sitemap'] ? 'Yes' : 'No',
'RSS Feed' => ($hydeConfig['rss']['enabled'] ?? false) ? 'Enabled' : 'Disabled',
'Source Root' => $hydeConfig['source_root'] ?: '(Project Root)',
],
'Features' => [
'Enabled Features' => implode(', ', array_map(function ($feature) {
return $feature->name;
}, $hydeConfig['features'] ?? [])),
],
'Server Configuration' => [
'Port' => $hydeConfig['server']['port'] ?? 8080,
'Host' => $hydeConfig['server']['host'] ?? 'localhost',
'Save Preview' => ($hydeConfig['server']['save_preview'] ?? true) ? 'Yes' : 'No',
'Live Edit' => ($hydeConfig['server']['live_edit'] ?? false) ? 'Enabled' : 'Disabled',
'Dashboard' => ($hydeConfig['server']['dashboard']['enabled'] ?? true) ? 'Enabled' : 'Disabled',
],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace Hyde\RealtimeCompiler\Console\Commands;

use Hyde\Hyde;
use Hyde\Console\Concerns\Command;
use Illuminate\Support\Facades\File;
use Exception;

/**
* @experimental This command is experimental and may be unstable. Report issues at GitHub!
*
* @see https://github.com/hydephp/realtime-compiler/pull/30
*/
class HerdInstallCommand extends Command
{
/** @var string */
protected $signature = 'herd:install {--force : Overwrite any existing file}';

/** @var string */
protected $description = '[Experimental] Install the HydePHP Valet driver for Laravel Herd';

public function safeHandle(): int
{
$driverTargetPath = $this->getDriverTargetPath();
$driverSourcePath = Hyde::vendorPath('resources/stubs/HydeValetDriver.php', 'realtime-compiler');

if (! is_dir(dirname($driverTargetPath))) {
$this->error('Herd Valet drivers directory not found. Is Herd installed?');

return Command::FAILURE;
}

if (file_exists($driverTargetPath) && ! $this->option('force')) {
if (! $this->confirm('The HydePHP Valet driver for Herd already exists. Do you want to overwrite it?', true)) {
$this->info('Installation cancelled.');

return Command::SUCCESS;
}
}

try {
File::copy($driverSourcePath, $driverTargetPath);
$this->info('HydePHP Valet driver for Herd successfully installed!');
$this->line('Driver path: '.$driverTargetPath);

return Command::SUCCESS;
} catch (Exception $exception) {
$this->error('Failed to install the HydePHP Valet driver: '.$exception->getMessage());

return Command::FAILURE;
}
}

private function getDriverTargetPath(): string
{
return match (PHP_OS_FAMILY) {
'Darwin' => $_SERVER['HOME'].'/Library/Application Support/Herd/config/valet/Drivers/HydeValetDriver.php',
'Windows' => $_SERVER['USERPROFILE'].'\.config\herd\config\valet\Drivers\HydeValetDriver.php',
default => throw new Exception('Herd is not yet supported on Linux.'),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@
namespace Hyde\RealtimeCompiler;

use Illuminate\Support\ServiceProvider;
use Hyde\RealtimeCompiler\Http\LiveEditController;
use Hyde\RealtimeCompiler\Http\DashboardController;
use Hyde\RealtimeCompiler\Http\LiveEditController;
use Hyde\RealtimeCompiler\Http\VirtualRouteController;
use Hyde\RealtimeCompiler\Console\Commands\HerdInstallCommand;

class RealtimeCompilerServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(RealtimeCompiler::class);

if ($this->app->runningInConsole()) {
$this->commands([
HerdInstallCommand::class,
]);
}
}

public function boot(): void
Expand Down
Loading