mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 08:30:07 +01:00
Add the ability for drivers to check Composer dependencies (#1345)
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Valet\Drivers\BasicValetDriver;
|
||||
use Valet\Drivers\Specific\BedrockValetDriver;
|
||||
use Valet\Drivers\ValetDriver;
|
||||
|
||||
@@ -28,4 +29,11 @@ public function test_it_prioritizes_non_basic_matches()
|
||||
$this->assertNotEquals('Valet\Drivers\BasicWithPublicValetDriver', get_class($assignedDriver));
|
||||
$this->assertNotEquals('Valet\Drivers\BasicValetDriver', get_class($assignedDriver));
|
||||
}
|
||||
|
||||
public function test_it_checks_composer_dependencies()
|
||||
{
|
||||
$driver = new BasicValetDriver;
|
||||
$this->assertTrue($driver->composerRequires(__DIR__.'/../files/sites/has-composer', 'tightenco/collect'));
|
||||
$this->assertFalse($driver->composerRequires(__DIR__.'/../files/sites/has-composer', 'tightenco/ziggy'));
|
||||
}
|
||||
}
|
||||
|
||||
5
tests/files/sites/has-composer/composer.json
Normal file
5
tests/files/sites/has-composer/composer.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"require": {
|
||||
"tightenco/collect": "1.0.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user