Search code examples
phpsymfonylaravel-valet

"Warning: require_once(./cli/includes/require-drivers.php): Failed to open stream" when using custom Laravel Valet driver for Symfony project


I'm trying to create a custom Laravel Valet driver for a Symfony project as I need to handle asset files in a specific way. I've created the following ProjectValetDriver class in /.config/valet/Drivers

<?php

namespace Valet\Drivers\Custom;

use Valet\Drivers\LaravelValetDriver;

class ProjectValetDriver extends LaravelValetDriver
{
    public function serves(string $sitePath, string $siteName, string $uri): bool
    {
        return $siteName === '[project-name]';
    }

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

        return false;
    }

    public function frontControllerPath(string $sitePath, string $siteName, string $uri): string
    {
        return $sitePath.'/public/index.php';
    }
}

The custom driver is correctly registered, however when I visit the site I get the following error;

Warning: require_once(./cli/includes/require-drivers.php): Failed to open stream: No such file or directory in /Users/[user]/.composer/vendor/laravel/valet/server.php on line 3

The public/index.php file is called correctly as well, but that file calling require_once dirname(__DIR__) . '/vendor/autoload_runtime.php'; seems to break everything. Without the custom driver the site loads fine. Any idea what's going on?


Solution

  • The issue was ultimately solved by extending Valet\Drivers\Specific\SymfonyValetDriver instead of LaravelValetDriver. In doing so, I can also ommit the frontControllerPath method from the custom driver.