diff --git a/cli/Valet/Upgrader.php b/cli/Valet/Upgrader.php new file mode 100644 index 000000000..f59d6ae5d --- /dev/null +++ b/cli/Valet/Upgrader.php @@ -0,0 +1,61 @@ +files->exists($samplePath)) { + if (! str_contains($this->files->get($samplePath), 'namespace')) { + $this->files->putAsUser( + VALET_HOME_PATH.'/Drivers/SampleValetDriver.php', + $this->files->getStub('SampleValetDriver.php') + ); + } + } + } + + public function errorIfOldCustomDrivers() + { + $driversPath = VALET_HOME_PATH.'/Drivers'; + + foreach ($this->files->scanDir($driversPath) as $driver) { + if (! str_contains($this->files->get($driversPath.'/'.$driver), 'namespace')) { + warning('Please make sure all custom drivers have been upgraded for Valet 4.'); + exit; + } + } + } +} diff --git a/cli/app.php b/cli/app.php index eb2ccadca..30c750202 100644 --- a/cli/app.php +++ b/cli/app.php @@ -9,12 +9,15 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\EventDispatcher\EventDispatcher; use Valet\Drivers\ValetDriver; + use function Valet\info; use function Valet\output; use function Valet\table; use function Valet\warning; use function Valet\writer; +$version = '4.0.0'; + /** * Load correct autoloader depending on install location. */ @@ -26,24 +29,14 @@ require_once getenv('HOME').'/.composer/vendor/autoload.php'; } -/** - * Relocate config dir to ~/.config/valet/ if found in old location. - */ -if (is_dir(VALET_LEGACY_HOME_PATH) && ! is_dir(VALET_HOME_PATH)) { - Configuration::createConfigurationDirectory(); -} - /** * Create the application. */ Container::setInstance(new Container); -$version = '4.0.0'; - $app = new Application('Laravel Valet', $version); -$dispatcher = new EventDispatcher(); -$app->setDispatcher($dispatcher); +$app->setDispatcher($dispatcher = new EventDispatcher()); $dispatcher->addListener( ConsoleEvents::COMMAND, @@ -51,14 +44,11 @@ function (ConsoleCommandEvent $event) { writer($event->getOutput()); }); -/** - * Prune missing directories and symbolic links on every command. - */ -if (is_dir(VALET_HOME_PATH)) { - Configuration::prune(); - - Site::pruneLinks(); -} +Upgrader::relocateOldConfig(); +Upgrader::pruneMissingDirectories(); +Upgrader::pruneSymbolicLinks(); +Upgrader::fixOldSampleValetDriver(); +Upgrader::errorIfOldCustomDrivers(); /** * Install Valet and any required services. diff --git a/cli/includes/facades.php b/cli/includes/facades.php index 2559c0395..96be663fa 100644 --- a/cli/includes/facades.php +++ b/cli/includes/facades.php @@ -59,6 +59,9 @@ class PhpFpm extends Facade class Site extends Facade { } +class Upgrader extends Facade +{ +} class Valet extends Facade { } diff --git a/cli/stubs/SampleValetDriver.php b/cli/stubs/SampleValetDriver.php index b392636de..119816027 100644 --- a/cli/stubs/SampleValetDriver.php +++ b/cli/stubs/SampleValetDriver.php @@ -1,5 +1,9 @@