diff --git a/cli/Valet/Configuration.php b/cli/Valet/Configuration.php index be32570..dba6681 100644 --- a/cli/Valet/Configuration.php +++ b/cli/Valet/Configuration.php @@ -90,6 +90,10 @@ public function prune(): void */ public function get(string $key, $default = null) { + if (!$this->files->exists($this->path())) { + return $default; + } + $config = $this->read(); return array_key_exists($key, $config) ? $config[$key] : $default; diff --git a/cli/Valet/Contracts/PackageManager.php b/cli/Valet/Contracts/PackageManager.php index 4223937..9d0d87a 100644 --- a/cli/Valet/Contracts/PackageManager.php +++ b/cli/Valet/Contracts/PackageManager.php @@ -48,4 +48,10 @@ public function restartNetworkManager(): void; * Get package name by service */ public function packageName(string $name): string; + + /** + * This function will determine whether a package manager supports versioned + * packages e.g php78-cli, php-78-gd etc + */ + public function supportsVersionedPackages(): bool; } diff --git a/cli/Valet/Filesystem.php b/cli/Valet/Filesystem.php index f014ee5..42b745f 100644 --- a/cli/Valet/Filesystem.php +++ b/cli/Valet/Filesystem.php @@ -133,6 +133,10 @@ public function get(string $path): string */ public function put(string $path, string $contents, ?string $owner = null): string { + if (!$this->exists($path)) { + $this->ensureDirExists(dirname($path), user()); + } + $status = file_put_contents($path, $contents); if ($owner) { diff --git a/cli/Valet/Nginx.php b/cli/Valet/Nginx.php index 39dc117..23f90a7 100644 --- a/cli/Valet/Nginx.php +++ b/cli/Valet/Nginx.php @@ -136,6 +136,10 @@ public function uninstall(): void */ public function configuredSites(): Collection { + if (!$this->files->exists(VALET_HOME_PATH . '/Nginx')) { + return collect([]); + } + return collect($this->files->scandir(VALET_HOME_PATH . '/Nginx')) ->reject(function ($file) { return str_starts_with($file, '.'); @@ -176,7 +180,7 @@ public function installServer($phpVersion = null): void */ private function rewriteSecureNginxFiles(): void { - $domain = $this->configuration->get('domain'); + $domain = $this->configuration->get('domain', 'test'); $this->siteSecure->reSecureForNewDomain($domain, $domain); } diff --git a/cli/Valet/PackageManagers/Apt.php b/cli/Valet/PackageManagers/Apt.php index 9efe7af..7ed511b 100644 --- a/cli/Valet/PackageManagers/Apt.php +++ b/cli/Valet/PackageManagers/Apt.php @@ -143,4 +143,13 @@ public function packageName(string $name): string } throw new \InvalidArgumentException(\sprintf('Package not found by %s', $name)); } + + /** + * This function will determine whether a package manager supports versioned + * packages e.g php78-cli, php-78-gd etc + */ + public function supportsVersionedPackages(): bool + { + return true; + } } diff --git a/cli/Valet/PackageManagers/Dnf.php b/cli/Valet/PackageManagers/Dnf.php index 0ee2be9..c8e63fd 100644 --- a/cli/Valet/PackageManagers/Dnf.php +++ b/cli/Valet/PackageManagers/Dnf.php @@ -138,4 +138,13 @@ public function packageName(string $name): string } throw new \InvalidArgumentException(\sprintf('Package not found by %s', $name)); } + + /** + * This function will determine whether a package manager supports versioned + * packages e.g php78-cli, php-78-gd etc + */ + public function supportsVersionedPackages(): bool + { + return true; + } } diff --git a/cli/Valet/PackageManagers/Eopkg.php b/cli/Valet/PackageManagers/Eopkg.php index 0cee021..75fa8c3 100644 --- a/cli/Valet/PackageManagers/Eopkg.php +++ b/cli/Valet/PackageManagers/Eopkg.php @@ -142,4 +142,13 @@ public function packageName(string $name): string } throw new \InvalidArgumentException(\sprintf('Package not found by %s', $name)); } + + /** + * This function will determine whether a package manager supports versioned + * packages e.g php78-cli, php-78-gd etc + */ + public function supportsVersionedPackages(): bool + { + return true; + } } diff --git a/cli/Valet/PackageManagers/PackageKit.php b/cli/Valet/PackageManagers/PackageKit.php index d1a897c..20f29e7 100644 --- a/cli/Valet/PackageManagers/PackageKit.php +++ b/cli/Valet/PackageManagers/PackageKit.php @@ -149,4 +149,13 @@ public function packageName(string $name): string } throw new \InvalidArgumentException(\sprintf('Package not found by %s', $name)); } + + /** + * This function will determine whether a package manager supports versioned + * packages e.g php78-cli, php-78-gd etc + */ + public function supportsVersionedPackages(): bool + { + return true; + } } diff --git a/cli/Valet/PackageManagers/Pacman.php b/cli/Valet/PackageManagers/Pacman.php index 5c520b8..05bf8af 100644 --- a/cli/Valet/PackageManagers/Pacman.php +++ b/cli/Valet/PackageManagers/Pacman.php @@ -147,4 +147,13 @@ public function packageName(string $name): string } throw new \InvalidArgumentException(\sprintf('Package not found by %s', $name)); } + + /** + * This function will determine whether a package manager supports versioned + * packages e.g php78-cli, php-78-gd etc + */ + public function supportsVersionedPackages(): bool + { + return false; + } } diff --git a/cli/Valet/PackageManagers/Yum.php b/cli/Valet/PackageManagers/Yum.php index 896f043..a5cf5da 100644 --- a/cli/Valet/PackageManagers/Yum.php +++ b/cli/Valet/PackageManagers/Yum.php @@ -141,4 +141,13 @@ public function packageName(string $name): string } throw new \InvalidArgumentException(\sprintf('Package not found by %s', $name)); } + + /** + * This function will determine whether a package manager supports versioned + * packages e.g php78-cli, php-78-gd etc + */ + public function supportsVersionedPackages(): bool + { + return false; + } } diff --git a/cli/Valet/PhpFpm.php b/cli/Valet/PhpFpm.php index 6604754..aec1a5b 100644 --- a/cli/Valet/PhpFpm.php +++ b/cli/Valet/PhpFpm.php @@ -59,7 +59,7 @@ public function install(?string $version = null, bool $installExt = true): void { $version = $version ?: $this->getCurrentVersion(); $version = $this->normalizePhpVersion($version); - if ($version === '') { + if ($version === '' && !$this->pm->supportsVersionedPackages()) { return; } @@ -297,9 +297,18 @@ private function installExtensions(string $version): void { $extArray = []; $extensionPrefix = $this->pm->getPhpExtensionPrefix($version); - foreach (self::COMMON_EXTENSIONS as $ext) { - $extArray[] = "{$extensionPrefix}{$ext}"; + + if (($this->pm instanceof \Valet\PackageManagers\Pacman)) { + foreach (self::COMMON_EXTENSIONS as $ext) { + $extArray[] = "{$extensionPrefix}{$ext}"; + } + + } else { + foreach (['gd'] as $ext) { + $extArray[] = "{$extensionPrefix}{$ext}"; + } } + $this->pm->ensureInstalled(implode(' ', $extArray)); } @@ -400,6 +409,6 @@ private function validateIsolationVersion(string $version): void */ private function getDefaultVersion(): string { - return $this->normalizePhpVersion(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION); + return !$this->pm->supportsVersionedPackages() ? '' : $this->normalizePhpVersion(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION); } } diff --git a/cli/Valet/SiteSecure.php b/cli/Valet/SiteSecure.php index 0a33e32..e08a849 100644 --- a/cli/Valet/SiteSecure.php +++ b/cli/Valet/SiteSecure.php @@ -194,6 +194,10 @@ private function unTrustCa(): void */ private function trustCa(string $caPemPath): void { + if (!$this->files->exists($this->caCertificatePath)) { + $this->caCertificatePath = str_replace('local/', '', $this->caCertificatePath); + } + $this->files->copy($caPemPath, sprintf('%s%s.crt', $this->caCertificatePath, $this->caCertificatePem)); $this->cli->run('sudo update-ca-certificates'); diff --git a/cli/Valet/Valet.php b/cli/Valet/Valet.php index 24e5a1d..55a5b7c 100644 --- a/cli/Valet/Valet.php +++ b/cli/Valet/Valet.php @@ -142,22 +142,27 @@ public function migrateConfig(): void return; } - // Fetch FPM running process - $fpmVersions = $this->getRunningFpmVersions($oldHomePath); + $fpmVersions = []; - // Stop running fpm services - if (count($fpmVersions)) { - foreach ($fpmVersions as $fpmVersion) { - PhpFpmFacade::stop($fpmVersion); + if ($this->files->isDir($oldHomePath)) { + // Fetch FPM running process + $fpmVersions = $this->getRunningFpmVersions($oldHomePath); + + // Stop running fpm services + if (count($fpmVersions)) { + foreach ($fpmVersions as $fpmVersion) { + PhpFpmFacade::stop($fpmVersion); + } } - } - if ($this->files->exists($oldHomePath . '/valet.sock')) { - PhpFpmFacade::stop(); - } + if ($this->files->exists($oldHomePath . '/valet.sock')) { + PhpFpmFacade::stop(); + } + + // Copy directory + $this->files->copyDirectory($oldHomePath, $newHomePath); - // Copy directory - $this->files->copyDirectory($oldHomePath, $newHomePath); + } // Replace $oldHomePath to $newHomePath in Certificates, Valet.conf file $this->updateNginxConfFiles(); @@ -194,7 +199,12 @@ private function updateNginxConfFiles(): void $oldHomePath = OLD_VALET_HOME_PATH; $nginxPath = $newHomePath . '/Nginx'; - $siteConfigs = $this->files->scandir($nginxPath); + $siteConfigs = []; + + if ($this->files->isDir($nginxPath)) { + $siteConfigs = $this->files->scandir($nginxPath); + } + foreach ($siteConfigs as $siteConfig) { $filePath = \sprintf('%s/%s', $nginxPath, $siteConfig); $content = $this->files->get($filePath); @@ -202,7 +212,11 @@ private function updateNginxConfFiles(): void $this->files->put($filePath, $content); } - $sitesAvailableConf = $this->files->get(Nginx::SITES_AVAILABLE_CONF); + $sitesAvailableConf = ''; + if ($this->files->exists(Nginx::SITES_AVAILABLE_CONF)) { + $sitesAvailableConf = $this->files->get(Nginx::SITES_AVAILABLE_CONF); + } + $sitesAvailableConf = str_replace($oldHomePath, $newHomePath, $sitesAvailableConf); $this->files->put(Nginx::SITES_AVAILABLE_CONF, $sitesAvailableConf); @@ -216,6 +230,7 @@ private function getRunningFpmVersions(string $homePath): array $runningVersions = []; $files = $this->files->scandir($homePath); + foreach ($files as $file) { preg_match('/valet(\d)(\d)\.sock/', $file, $matches); if (count($matches) >= 2) { diff --git a/cli/app.php b/cli/app.php index 2d0069f..adab663 100644 --- a/cli/app.php +++ b/cli/app.php @@ -58,7 +58,7 @@ Configuration::install(); Nginx::install(); PhpFpm::install(); - DnsMasq::install(Configuration::get('domain')); + DnsMasq::install(Configuration::get('domain', 'test')); Mailpit::install(); ValetRedis::install(); Nginx::restart();