1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-07 01:00:09 +01:00
Files
laravel-valet/cli/Valet/Drivers/Specific/SculpinValetDriver.php
Matt Stauffer efa7937038 Update drivers location and loading
- Extract much of server.php into a `Server` class
- Move all but the Laravel and Basic drivers into a subfolder
- Load all but the Laravel and Basic drivers via glob
- Add `beforeLoading` hook to simplify the `frontControllerPath` method for some drivers
2022-12-18 15:08:17 -06:00

62 lines
1.5 KiB
PHP

<?php
namespace Valet\Drivers\Specific;
use Valet\Drivers\BasicValetDriver;
class SculpinValetDriver extends BasicValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves(string $sitePath, string $siteName, string $uri): bool
{
return $this->isModernSculpinProject($sitePath) ||
$this->isLegacySculpinProject($sitePath);
}
private function isModernSculpinProject($sitePath)
{
return is_dir($sitePath.'/source') &&
is_dir($sitePath.'/output_dev') &&
$this->composerRequiresSculpin($sitePath);
}
private function isLegacySculpinProject($sitePath)
{
return is_dir($sitePath.'/.sculpin');
}
private function composerRequiresSculpin($sitePath)
{
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.
*
* @param string $uri
* @return string
*/
public function mutateUri(string $uri): string
{
return rtrim('/output_dev'.$uri, '/');
}
}