1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-07 01:00:09 +01:00

Add the ability for drivers to check Composer dependencies (#1345)

This commit is contained in:
Matt Stauffer
2023-01-13 21:54:59 -05:00
committed by GitHub
parent 303462ffd1
commit 9143636c76
4 changed files with 32 additions and 19 deletions

View File

@@ -15,34 +15,18 @@ public function serves(string $sitePath, string $siteName, string $uri): bool
$this->isLegacySculpinProject($sitePath);
}
private function isModernSculpinProject($sitePath): bool
private function isModernSculpinProject(string $sitePath): bool
{
return is_dir($sitePath.'/source') &&
is_dir($sitePath.'/output_dev') &&
$this->composerRequiresSculpin($sitePath);
$this->composerRequires($sitePath, 'sculpin/sculpin');
}
private function isLegacySculpinProject($sitePath): bool
private function isLegacySculpinProject(string $sitePath): bool
{
return is_dir($sitePath.'/.sculpin');
}
private function composerRequiresSculpin($sitePath): bool
{
if (! file_exists($sitePath.'/composer.json')) {
return false;
}
$composer_json_source = file_get_contents($sitePath.'/composer.json');
$composer_json = json_decode($composer_json_source, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return false;
}
return isset($composer_json['require']['sculpin/sculpin']);
}
/**
* Mutate the incoming URI.
*/

View File

@@ -196,4 +196,20 @@ public function loadServerEnvironmentVariables(string $sitePath, string $siteNam
putenv($key.'='.$value);
}
}
public function composerRequires(string $sitePath, string $namespacedPackage): bool
{
if (! file_exists($sitePath.'/composer.json')) {
return false;
}
$composer_json_source = file_get_contents($sitePath.'/composer.json');
$composer_json = json_decode($composer_json_source, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return false;
}
return isset($composer_json['require'][$namespacedPackage]);
}
}