Skip to content

Commit 4c367f1

Browse files
committed
refactor: the assigning of drivers and allow the retrieval of drivers using the new namespaces.
- Remove listing the specific drivers individually, which would be a maintenance nightmare for new drivers. - Add new `specificDrivers` method to bulk map the specific drivers into the array using the namespace.
1 parent d0c6c4d commit 4c367f1

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

cli/Valet/Drivers/ValetDriver.php

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,38 +55,32 @@ abstract public function frontControllerPath($sitePath, $siteName, $uri);
5555
public static function assign($sitePath, $siteName, $uri) {
5656
$drivers = [];
5757

58+
// Get all specific drivers.
59+
// Must scan these so they're extensible by customSiteDrivers loaded next.
60+
$specificDrivers = static::specificDrivers();
61+
62+
// Queue custom driver based on path
5863
if ($customSiteDriver = static::customSiteDriver($sitePath)) {
5964
$drivers[] = $customSiteDriver;
6065
}
6166

6267
$drivers = array_merge($drivers, static::driversIn(VALET_HOME_PATH . '/Drivers'));
6368

69+
// Queue Valet-shipped drivers
70+
$drivers[] = 'Specific\StatamicValetDriver';
6471
$drivers[] = 'LaravelValetDriver';
65-
66-
$drivers[] = 'WordPressValetDriver';
67-
$drivers[] = 'BedrockValetDriver';
68-
$drivers[] = 'ContaoValetDriver';
69-
$drivers[] = 'SymfonyValetDriver';
70-
$drivers[] = 'CraftValetDriver';
71-
$drivers[] = 'StatamicValetDriver';
72-
$drivers[] = 'StatamicV1ValetDriver';
73-
$drivers[] = 'CakeValetDriver';
74-
$drivers[] = 'SculpinValetDriver';
75-
$drivers[] = 'JigsawValetDriver';
76-
$drivers[] = 'KirbyValetDriver';
77-
$drivers[] = 'KatanaValetDriver';
78-
$drivers[] = 'JoomlaValetDriver';
79-
$drivers[] = 'DrupalValetDriver';
80-
$drivers[] = 'Concrete5ValetDriver';
81-
$drivers[] = 'Typo3ValetDriver';
82-
$drivers[] = 'NeosValetDriver';
83-
$drivers[] = 'Magento2ValetDriver';
84-
72+
$drivers = array_unique(array_merge($drivers, $specificDrivers));
8573
$drivers[] = 'BasicWithPublicValetDriver';
8674
$drivers[] = 'BasicValetDriver';
8775

8876
foreach ($drivers as $driver) {
89-
$driver = new $driver();
77+
if ($driver === 'LocalValetDriver') {
78+
$driver = new $driver();
79+
}
80+
else {
81+
$className = "Valet\Drivers\\{$driver}";
82+
$driver = new $className();
83+
}
9084

9185
if ($driver->serves($sitePath, $siteName, $driver->mutateUri($uri))) {
9286
return $driver;
@@ -138,6 +132,18 @@ public static function driversIn($path) {
138132
return $drivers;
139133
}
140134

135+
/**
136+
* Get all of the specific drivers shipped with Valet.
137+
*
138+
* @return array
139+
*/
140+
public static function specificDrivers() {
141+
return array_map(function ($item) {
142+
return "Specific\\$item";
143+
}, static::driversIn(__DIR__ . '/Specific'));
144+
}
145+
146+
141147
/**
142148
* Take any steps necessary before loading the front controller for this driver.
143149
*

0 commit comments

Comments
 (0)