Skip to content

Commit 73822d0

Browse files
committed
feat: add new namespace to the SampleValetDriver class as Valet\Drivers\Custom
- Add namespace to the sample custom driver, and a `use` declaration to make sure the `ValetDriver` is available in this custom class. - Add new `customDrivers` method to bulk map the custom drivers from the `~.config/valet/Drivers` directory into the drivers array using the new namespace of `Valet\Drivers\Custom`.
1 parent eb9ee70 commit 73822d0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

cli/Valet/Drivers/ValetDriver.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public static function assign($sitePath, $siteName, $uri) {
6464
$drivers[] = $customSiteDriver;
6565
}
6666

67-
$drivers = array_merge($drivers, static::driversIn(VALET_HOME_PATH . '/Drivers'));
67+
// Queue custom drivers for this environment
68+
$drivers = array_merge($drivers, static::customDrivers());
6869

6970
// Queue Valet-shipped drivers
7071
$drivers[] = 'Specific\StatamicValetDriver';
@@ -143,6 +144,16 @@ public static function specificDrivers() {
143144
}, static::driversIn(__DIR__ . '/Specific'));
144145
}
145146

147+
/**
148+
* Get all of the custom drivers defined by the user in `~/.config/valet/Drivers`.
149+
*
150+
* @return array
151+
*/
152+
public static function customDrivers() {
153+
return array_map(function ($item) {
154+
return "Custom\\$item";
155+
}, static::driversIn(VALET_HOME_PATH . '/Drivers'));
156+
}
146157

147158
/**
148159
* Take any steps necessary before loading the front controller for this driver.

cli/stubs/SampleValetDriver.php

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

3+
namespace Valet\Drivers\Custom;
4+
5+
use Valet\Drivers\ValetDriver;
6+
37
class SampleValetDriver extends ValetDriver {
48
/**
59
* Determine if the driver serves the request.

0 commit comments

Comments
 (0)