1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Hyde\RealtimeCompiler\Console\Commands; |
6
|
|
|
|
7
|
|
|
use Hyde\Hyde; |
8
|
|
|
use Hyde\Console\Concerns\Command; |
9
|
|
|
use Illuminate\Support\Facades\File; |
10
|
|
|
use Exception; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @experimental This command is experimental and may be unstable. Report issues at GitHub! |
14
|
|
|
* |
15
|
|
|
* @see https://github.com/hydephp/realtime-compiler/pull/30 |
16
|
|
|
*/ |
17
|
|
|
class HerdInstallCommand extends Command |
18
|
|
|
{ |
19
|
|
|
/** @var string */ |
20
|
|
|
protected $signature = 'herd:install {--force : Overwrite any existing file}'; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
protected $description = '[Experimental] Install the HydePHP Valet driver for Laravel Herd'; |
24
|
|
|
|
25
|
|
|
public function safeHandle(): int |
26
|
|
|
{ |
27
|
|
|
$driverTargetPath = $this->getDriverTargetPath(); |
28
|
|
|
$driverSourcePath = Hyde::vendorPath('resources/stubs/HydeValetDriver.php', 'realtime-compiler'); |
|
|
|
|
29
|
|
|
|
30
|
|
|
if (! is_dir(dirname($driverTargetPath))) { |
31
|
|
|
$this->error('Herd Valet drivers directory not found. Is Herd installed?'); |
32
|
|
|
|
33
|
|
|
return Command::FAILURE; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
if (file_exists($driverTargetPath) && ! $this->option('force')) { |
37
|
|
|
if (! $this->confirm('The HydePHP Valet driver for Herd already exists. Do you want to overwrite it?', true)) { |
38
|
|
|
$this->info('Installation cancelled.'); |
39
|
|
|
|
40
|
|
|
return Command::SUCCESS; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
try { |
45
|
|
|
File::copy($driverSourcePath, $driverTargetPath); |
46
|
|
|
$this->info('HydePHP Valet driver for Herd successfully installed!'); |
47
|
|
|
$this->line('Driver path: '.$driverTargetPath); |
48
|
|
|
|
49
|
|
|
return Command::SUCCESS; |
50
|
|
|
} catch (Exception $exception) { |
51
|
|
|
$this->error('Failed to install the HydePHP Valet driver: '.$exception->getMessage()); |
52
|
|
|
|
53
|
|
|
return Command::FAILURE; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private function getDriverTargetPath(): string |
58
|
|
|
{ |
59
|
|
|
return match (PHP_OS_FAMILY) { |
60
|
|
|
'Darwin' => $_SERVER['HOME'].'/Library/Application Support/Herd/config/valet/Drivers/HydeValetDriver.php', |
61
|
|
|
'Windows' => $_SERVER['USERPROFILE'].'\.config\herd\config\valet\Drivers\HydeValetDriver.php', |
62
|
|
|
default => throw new Exception('Herd is not yet supported on Linux.'), |
63
|
|
|
}; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|