Laravel Herd: Create custom driver for Symfony

Ignacio
2 min readDec 31, 2024

--

We know that Herd is designed to develop with Laravel. Although its creators have made an effort to extend its functionality to different frameworks such as Symfony, Zend, Drupal, WordPress, Joomla! or Magento 2.

This is achieved in a very simple way, through the so-called Drivers, which are nothing more than .php files with some functions to detect whether it is the driver or not.

Herd already comes with a driver for Symfony, but unfortunately for me, the driver checks did not match the structure of my files and folders. That is why I decided to create a custom driver for Symfony with Herd, which opens the doors to more features of the application, such as logs, Xdebug, among other things.

The original Symfony Driver file can be found in /Applications/Herd.app/Contents/Resources/valet/cli/Valet/Drivers/Specific/

The custom driver must be placed in /Users/[your-user]/Library/Application Support/Herd/config/valet/Drivers.

I named my file CustomSymfonyValetDriver.php

The code that worked for me is the following:

<?php

namespace Valet\Drivers\Custom;

use Valet\Drivers\LaravelValetDriver;
use Valet\Drivers\ValetDriver;

class CustomSymfonyValetDriver extends ValetDriver
{
public function serves(string $sitePath, string $siteName, string $uri): bool
{
return file_exists(sprintf('%s/public/index.php', $sitePath))
&& file_exists(sprintf('%s/src/App/Kernel.php', $sitePath));
}

public function logFilesPaths() {
return ['/var/log'];
}

public function isStaticFile(string $sitePath, string $siteName, string $uri): string|false|null
{
if ($this->isActualFile($staticFilePath = $sitePath.'/public/'.$uri)) {
return $staticFilePath;
}

return false;
}

public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
{
$frontControllerPath = null;

if (file_exists($path = $sitePath.'/public/index.php')) {
$frontControllerPath = $path;
}

$_SERVER['SCRIPT_FILENAME'] = $frontControllerPath;

return $frontControllerPath;
}

public function siteInformation(string $sitePath, string $phpBinary): array
{
return [
"Overview" => [
"Site Name" => "Symfony App",
],
];
}
}

Anyway, don’t forget to check the correct path to your index.php, Kernel.php, logs folder, public folder files.

I hope it has been useful.

--

--

Ignacio
Ignacio

No responses yet