argument("enable") === "enable"; $path = $this->argument("path"); if ($enable) { $this->enable($path); } else { $this->disable($path); } } private function getComposerJson(): array { return json_decode(file_get_contents(base_path("composer.json")), true); } private function replaceComposerJson(array $composerJson): void { file_put_contents( base_path("composer.json"), json_encode( $composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES, ), ); } private function enable(string $path): void { $productionRepo = $this->productionRepository(); $composerJson = $this->getComposerJson(); $composerJson["repositories"] = array_filter( $composerJson["repositories"], fn($repo) => $repo["url"] !== $productionRepo["url"], ); $composerJson["repositories"][] = $this->devRepository($path); $this->replaceComposerJson($composerJson); } private function disable(string $path): void { $devRepo = $this->devRepository($path); $composerJson = $this->getComposerJson(); $composerJson["repositories"] = array_filter( $composerJson["repositories"], fn($repo) => $repo["url"] !== $devRepo["url"], ); $composerJson["repositories"][] = $this->productionRepository(); $this->replaceComposerJson($composerJson); } private function productionRepository(): array { return [ "type" => "vcs", "url" => "ssh://git@code.radical-elements.com:2727/lucent/lucent-laravel.git", ]; } private function devRepository(string $localPath): array { return [ "type" => "path", "url" => $localPath, "options" => [ "symlink" => true, ], ]; } }