Skip to content

Commit d0c6c4d

Browse files
committed
feat: Add the ability for drivers to check Composer dependencies
- Add new public `composerRequires` method to the base `ValetDriver` class. - Remove the private `composerRequiresSculpin` method from `SculpinValetDriver`, and update it's reference to use the new global `composerRequires` method.
1 parent ff0af00 commit d0c6c4d

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

cli/Valet/Drivers/Specific/SculpinValetDriver.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function serves($sitePath, $siteName, $uri) {
2626
* @return bool
2727
*/
2828
private function isModernSculpinProject($sitePath) {
29-
return is_dir("{$sitePath}/source") && is_dir("{$sitePath}/output_dev") && $this->composerRequiresSculpin($sitePath);
29+
return is_dir("{$sitePath}/source") && is_dir("{$sitePath}/output_dev") && $this->composerRequires($sitePath, 'sculpin/sculpin');
3030
}
3131

3232
/**
@@ -40,28 +40,6 @@ private function isLegacySculpinProject($sitePath) {
4040
return is_dir("{$sitePath}/.sculpin");
4141
}
4242

43-
/**
44-
* Check if the composer.json file requires Sculpin.
45-
*
46-
* @param string $sitePath
47-
*
48-
* @return bool
49-
*/
50-
private function composerRequiresSculpin($sitePath) {
51-
if (!file_exists("{$sitePath}/composer.json")) {
52-
return false;
53-
}
54-
55-
$composer_json_source = file_get_contents("{$sitePath}/composer.json");
56-
$composer_json = json_decode($composer_json_source, true);
57-
58-
if (json_last_error() !== JSON_ERROR_NONE) {
59-
return false;
60-
}
61-
62-
return isset($composer_json['require']['sculpin/sculpin']);
63-
}
64-
6543
/**
6644
* Mutate the incoming URI.
6745
*

cli/Valet/Drivers/ValetDriver.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,27 @@ public function loadServerEnvironmentVariables($sitePath, $siteName) {
237237
putenv("$key=$value");
238238
}
239239
}
240+
241+
/**
242+
* Check the site's Composer dependencies
243+
*
244+
* @param string $sitePath
245+
* @param string $namespacedPackage
246+
*
247+
* @return bool
248+
*/
249+
public function composerRequires($sitePath, $namespacedPackage) {
250+
if (! file_exists("$sitePath/composer.json")) {
251+
return false;
252+
}
253+
254+
$composer_json_source = file_get_contents("$sitePath/composer.json");
255+
$composer_json = json_decode($composer_json_source, true);
256+
257+
if (json_last_error() !== JSON_ERROR_NONE) {
258+
return false;
259+
}
260+
261+
return isset($composer_json['require'][$namespacedPackage]);
262+
}
240263
}

0 commit comments

Comments
 (0)