From 86e69eed0f4cc43a810b0528b874d8fc403aeda9 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Sun, 2 Jun 2024 18:11:38 -0400 Subject: [PATCH 1/9] Add Forge facade for Laravel integration --- composer.json | 5 +++++ src/Facades/Forge.php | 22 +++++++++++++++++++ src/ForgeManager.php | 42 ++++++++++++++++++++++++++++++++++++ src/ForgeServiceProvider.php | 19 ++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 src/Facades/Forge.php create mode 100644 src/ForgeManager.php create mode 100644 src/ForgeServiceProvider.php diff --git a/composer.json b/composer.json index 7a184a3..8c8b156 100644 --- a/composer.json +++ b/composer.json @@ -48,6 +48,11 @@ "extra": { "branch-alias": { "dev-master": "3.x-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Forge\\ForgeServiceProvider" + ] } }, "config": { diff --git a/src/Facades/Forge.php b/src/Facades/Forge.php new file mode 100644 index 0000000..3e5618f --- /dev/null +++ b/src/Facades/Forge.php @@ -0,0 +1,22 @@ +forge = new Forge($token); + } + + /** + * Dynamically pass methods to the Forge instance. + * + * @param string $method + * @param array $parameters + * @return mixed + */ + public function __call(string $method, array $parameters): mixed + { + return $this->forwardCallTo($this->forge, $method, $parameters); + } +} diff --git a/src/ForgeServiceProvider.php b/src/ForgeServiceProvider.php new file mode 100644 index 0000000..53e6de6 --- /dev/null +++ b/src/ForgeServiceProvider.php @@ -0,0 +1,19 @@ +app->singleton(ForgeManager::class, function ($app) { + return new ForgeManager($app['config']->get('services.forge.token')); + }); + } +} From 03f0f0223ee3a263981269f1e87a647c72e9f8c8 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Sun, 2 Jun 2024 18:20:44 -0400 Subject: [PATCH 2/9] CS fixes --- src/Facades/Forge.php | 2 +- src/ForgeServiceProvider.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Facades/Forge.php b/src/Facades/Forge.php index 3e5618f..c4eb4aa 100644 --- a/src/Facades/Forge.php +++ b/src/Facades/Forge.php @@ -2,8 +2,8 @@ namespace Laravel\Forge\Facades; -use Laravel\Forge\ForgeManager; use Illuminate\Support\Facades\Facade; +use Laravel\Forge\ForgeManager; /** * @mixin \Laravel\Forge\Forge diff --git a/src/ForgeServiceProvider.php b/src/ForgeServiceProvider.php index 53e6de6..1da398c 100644 --- a/src/ForgeServiceProvider.php +++ b/src/ForgeServiceProvider.php @@ -2,8 +2,8 @@ namespace Laravel\Forge; -use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Foundation\Application; +use Illuminate\Support\ServiceProvider; class ForgeServiceProvider extends ServiceProvider { From de7f9ad9444fc3205df91435073eaaf6cf531fd0 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Thu, 6 Jun 2024 11:02:20 -0400 Subject: [PATCH 3/9] Add Facade documenter GitHub action --- .github/workflows/facades.yml | 49 +++++++++++++++++++++++++++++++++++ src/Facades/Forge.php | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/facades.yml diff --git a/.github/workflows/facades.yml b/.github/workflows/facades.yml new file mode 100644 index 0000000..cc3a282 --- /dev/null +++ b/.github/workflows/facades.yml @@ -0,0 +1,49 @@ +name: facades + +on: + push: + branches: + - master + - '*.x' + workflow_dispatch: + +jobs: + update: + runs-on: ubuntu-22.04 + + strategy: + fail-fast: true + + name: Facade DocBlocks + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + extensions: :php-psr + tools: composer:v2 + coverage: none + + - name: Install dependencies + uses: nick-fields/retry@v3 + with: + timeout_minutes: 5 + max_attempts: 5 + command: | + composer config repositories.facade-documenter vcs git@github.com:laravel/facade-documenter.git + composer require --dev laravel/facade-documenter:dev-main --prefer-stable --prefer-dist --no-interaction --no-progress + + - name: Update facade docblocks + run: | + php -f vendor/bin/facade.php -- \ + Laravel\Forge\Facades\\Forge + + - name: Commit facade docblocks + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: Update facade docblocks + file_pattern: src/ diff --git a/src/Facades/Forge.php b/src/Facades/Forge.php index c4eb4aa..4870349 100644 --- a/src/Facades/Forge.php +++ b/src/Facades/Forge.php @@ -6,7 +6,7 @@ use Laravel\Forge\ForgeManager; /** - * @mixin \Laravel\Forge\Forge + * @see \Laravel\Forge\Forge */ class Forge extends Facade { From e4a1edf7b42cb80a94ac79fc4beb9485040d5a34 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Thu, 6 Jun 2024 11:33:23 -0400 Subject: [PATCH 4/9] Fix workflow --- .github/workflows/facades.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/facades.yml b/.github/workflows/facades.yml index cc3a282..b65fb75 100644 --- a/.github/workflows/facades.yml +++ b/.github/workflows/facades.yml @@ -40,7 +40,7 @@ jobs: - name: Update facade docblocks run: | php -f vendor/bin/facade.php -- \ - Laravel\Forge\Facades\\Forge + Laravel\\Forge\\Facades\\Forge - name: Commit facade docblocks uses: stefanzweifel/git-auto-commit-action@v5 From 29a316d372cce54947aa5658d149340b872e920d Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Thu, 6 Jun 2024 11:35:23 -0400 Subject: [PATCH 5/9] Generate docs --- src/Facades/Forge.php | 149 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/src/Facades/Forge.php b/src/Facades/Forge.php index 4870349..98c6ca9 100644 --- a/src/Facades/Forge.php +++ b/src/Facades/Forge.php @@ -6,6 +6,155 @@ use Laravel\Forge\ForgeManager; /** + * @method static \Laravel\Forge\Forge setApiKey(string $apiKey, \GuzzleHttp\Client|null $guzzle = null) + * @method static \Laravel\Forge\Forge setTimeout(int $timeout) + * @method static int getTimeout() + * @method static \Laravel\Forge\Resources\User user() + * @method static mixed get(string $uri) + * @method static mixed post(string $uri, array $payload = []) + * @method static mixed put(string $uri, array $payload = []) + * @method static mixed delete(string $uri, array $payload = []) + * @method static mixed retry(int $timeout, callable $callback, int $sleep = 5) + * @method static \Laravel\Forge\Resources\Job[] jobs(int $serverId) + * @method static \Laravel\Forge\Resources\Job job(int $serverId, int $jobId) + * @method static \Laravel\Forge\Resources\Job createJob(int $serverId, array $data, bool $wait = true) + * @method static void deleteJob(int $serverId, int $jobId) + * @method static \Laravel\Forge\Resources\Site[] sites(int $serverId) + * @method static \Laravel\Forge\Resources\Site site(int $serverId, int $siteId) + * @method static \Laravel\Forge\Resources\Site createSite(int $serverId, array $data, bool $wait = true) + * @method static \Laravel\Forge\Resources\Site updateSite(int $serverId, int $siteId, array $data) + * @method static \Laravel\Forge\Resources\Site addSiteAliases(int $serverId, int $siteId, array $aliases) + * @method static void refreshSiteToken(int $serverId, int $siteId) + * @method static void deleteSite(int $serverId, int $siteId) + * @method static string siteNginxFile(int $serverId, int $siteId) + * @method static void updateSiteNginxFile(int $serverId, int $siteId, string $content) + * @method static string siteEnvironmentFile(int $serverId, int $siteId) + * @method static void updateSiteEnvironmentFile(int $serverId, int $siteId, string $content) + * @method static void installGitRepositoryOnSite(int $serverId, int $siteId, array $data, bool $wait = true) + * @method static void updateSiteGitRepository(int $serverId, int $siteId, array $data) + * @method static void destroySiteGitRepository(int $serverId, int $siteId, bool $wait = true) + * @method static string siteDeploymentScript(int $serverId, int $siteId) + * @method static void updateSiteDeploymentScript(int $serverId, int $siteId, string $content, bool $autoSource = false) + * @method static void enableQuickDeploy(int $serverId, int $siteId) + * @method static void disableQuickDeploy(int $serverId, int $siteId) + * @method static \Laravel\Forge\Resources\Site deploySite(int $serverId, int $siteId, bool $wait = true) + * @method static void resetDeploymentState(int $serverId, int $siteId) + * @method static string siteDeploymentLog(int $serverId, int $siteId) + * @method static string deploymentHistory(int $serverId, int $siteId) + * @method static string deploymentHistoryDeployment(int $serverId, int $siteId, int $deploymentId) + * @method static string deploymentHistoryOutput(int $serverId, int $siteId, int $deploymentId) + * @method static void enableHipchatNotifications(int $serverId, int $siteId, array $data) + * @method static void disableHipchatNotifications(int $serverId, int $siteId) + * @method static void installWordPress(int $serverId, int $siteId, array $data) + * @method static void removeWordPress(int $serverId, int $siteId) + * @method static void installPhpMyAdmin(int $serverId, int $siteId, array $data) + * @method static void removePhpMyAdmin(int $serverId, int $siteId) + * @method static void changeSitePHPVersion(int $serverId, int $siteId, string $version) + * @method static void updateNodeBalancingConfiguration(int $serverId, int $siteId, array $data) + * @method static string siteLog(int $serverId, int $siteId) + * @method static \Laravel\Forge\Resources\Server[] servers() + * @method static \Laravel\Forge\Resources\Server server(string $serverId) + * @method static \Laravel\Forge\Resources\Server createServer(array $data, bool $wait = false, int $timeout = 900) + * @method static \Laravel\Forge\Resources\Server updateServer(string $serverId, array $data) + * @method static void deleteServer(string $serverId) + * @method static void revokeAccessToServer(string $serverId) + * @method static void reconnectToServer(string $serverId) + * @method static void reactivateToServer(string $serverId) + * @method static void rebootServer(string $serverId) + * @method static void rebootMysql(string $serverId) + * @method static void stopMysql(string $serverId) + * @method static void rebootPostgres(string $serverId) + * @method static void stopPostgres(string $serverId) + * @method static void rebootNginx(string $serverId) + * @method static void stopNginx(string $serverId) + * @method static void rebootPHP(string $serverId, array $data) + * @method static void installBlackfire(string $serverId, array $data) + * @method static void removeBlackfire(string $serverId) + * @method static void installPapertrail(string $serverId, array $data) + * @method static void removePapertrail(string $serverId) + * @method static void enableOPCache(string $serverId) + * @method static void disableOPCache(string $serverId) + * @method static \Laravel\Forge\Resources\PHPVersion[] phpVersions(int $serverId) + * @method static void installPHP(string $serverId, string $version) + * @method static void updatePHP(string $serverId, string $version) + * @method static \Laravel\Forge\Resources\Event[] events(string|null $serverId = null) + * @method static \Laravel\Forge\Resources\Daemon[] daemons(int $serverId) + * @method static \Laravel\Forge\Resources\Daemon daemon(int $serverId, int $daemonId) + * @method static \Laravel\Forge\Resources\Daemon createDaemon(int $serverId, array $data, bool $wait = true) + * @method static void restartDaemon(int $serverId, int $daemonId, bool $wait = true) + * @method static void deleteDaemon(int $serverId, int $daemonId) + * @method static \Laravel\Forge\Resources\Worker[] workers(int $serverId, int $siteId) + * @method static \Laravel\Forge\Resources\Worker worker(int $serverId, int $siteId, int $workerId) + * @method static \Laravel\Forge\Resources\Worker createWorker(int $serverId, int $siteId, array $data, bool $wait = true) + * @method static void deleteWorker(int $serverId, int $siteId, int $workerId) + * @method static void restartWorker(int $serverId, int $siteId, int $workerId, bool $wait = true) + * @method static \Laravel\Forge\Resources\SSHKey[] keys(int $serverId) + * @method static \Laravel\Forge\Resources\SSHKey sshKey(int $serverId, int $keyId) + * @method static \Laravel\Forge\Resources\SSHKey createSSHKey(int $serverId, array $data, bool $wait = true) + * @method static void deleteSSHKey(int $serverId, int $keyId) + * @method static \Laravel\Forge\Resources\Recipe[] recipes() + * @method static \Laravel\Forge\Resources\Recipe recipe(string $recipeId) + * @method static \Laravel\Forge\Resources\Recipe createRecipe(array $data) + * @method static \Laravel\Forge\Resources\Recipe updateRecipe(string $recipeId, array $data) + * @method static void deleteRecipe(string $recipeId) + * @method static void runRecipe(string $recipeId, array $data) + * @method static \Laravel\Forge\Resources\BackupConfiguration[] backupConfigurations(string $serverId) + * @method static \Laravel\Forge\Resources\BackupConfiguration backupConfiguration(string $serverId, string $backupConfigurationId) + * @method static \Laravel\Forge\Resources\BackupConfiguration createBackupConfiguration(string $serverId, array $data) + * @method static \Laravel\Forge\Resources\BackupConfiguration updateBackupConfiguration(int $serverId, int $backupConfigurationId, array $data) + * @method static void deleteBackupConfiguration(string $serverId, string $backupConfigurationId) + * @method static void restoreBackup(string $serverId, string $backupConfigurationId, string $backupId) + * @method static void deleteBackup(string $serverId, string $backupConfigurationId, string $backupId) + * @method static \Laravel\Forge\Resources\Webhook[] webhooks(int $serverId, int $siteId) + * @method static \Laravel\Forge\Resources\Webhook webhook(int $serverId, int $siteId, int $webhookId) + * @method static \Laravel\Forge\Resources\Webhook createWebhook(int $serverId, int $siteId, array $data) + * @method static void deleteWebhook(int $serverId, int $siteId, int $webhookId) + * @method static \Laravel\Forge\Resources\DatabaseUser[] databaseUsers(int $serverId) + * @method static \Laravel\Forge\Resources\DatabaseUser databaseUser(int $serverId, int $userId) + * @method static \Laravel\Forge\Resources\DatabaseUser createDatabaseUser(int $serverId, array $data, bool $wait = true) + * @method static \Laravel\Forge\Resources\DatabaseUser updateDatabaseUser(int $serverId, int $userId, array $data) + * @method static void deleteDatabaseUser(int $serverId, int $userId) + * @method static \Laravel\Forge\Resources\Credential[] credentials() + * @method static \Laravel\Forge\Resources\Certificate[] certificates(int $serverId, int $siteId) + * @method static \Laravel\Forge\Resources\Certificate certificate(int $serverId, int $siteId, int $certificateId) + * @method static \Laravel\Forge\Resources\Certificate createCertificate(int $serverId, int $siteId, array $data, bool $wait = true) + * @method static void deleteCertificate(int $serverId, int $siteId, int $certificateId) + * @method static string getCertificateSigningRequest(int $serverId, int $siteId, int $certificateId) + * @method static void installCertificate(int $serverId, int $siteId, int $certificateId, array $data, bool $wait = true) + * @method static void activateCertificate(int $serverId, int $siteId, int $certificateId, bool $wait = true) + * @method static \Laravel\Forge\Resources\Certificate obtainLetsEncryptCertificate(int $serverId, int $siteId, array $data, bool $wait = true) + * @method static \Laravel\Forge\Resources\FirewallRule[] firewallRules(int $serverId) + * @method static \Laravel\Forge\Resources\FirewallRule firewallRule(int $serverId, int $ruleId) + * @method static \Laravel\Forge\Resources\FirewallRule createFirewallRule(int $serverId, array $data, bool $wait = true) + * @method static void deleteFirewallRule(int $serverId, int $ruleId) + * @method static \Laravel\Forge\Resources\RedirectRule[] redirectRules(int $serverId, int $siteId) + * @method static \Laravel\Forge\Resources\RedirectRule redirectRule(int $serverId, int $siteId, int $ruleId) + * @method static \Laravel\Forge\Resources\RedirectRule createRedirectRule(int $serverId, int $siteId, array $data, bool $wait = true) + * @method static void deleteRedirectRule(int $serverId, int $siteId, int $ruleId) + * @method static \Laravel\Forge\Resources\SecurityRule[] securityRules(int $serverId, int $siteId) + * @method static \Laravel\Forge\Resources\SecurityRule securityRule(int $serverId, int $siteId, int $ruleId) + * @method static \Laravel\Forge\Resources\SecurityRule createSecurityRule(int $serverId, int $siteId, array $data, bool $wait = true) + * @method static void deleteSecurityRule(int $serverId, int $siteId, int $ruleId) + * @method static \Laravel\Forge\Resources\Database[] databases(int $serverId) + * @method static \Laravel\Forge\Resources\Database database(int $serverId, int $databaseId) + * @method static \Laravel\Forge\Resources\Database createDatabase(int $serverId, array $data, bool $wait = true) + * @method static \Laravel\Forge\Resources\Database updateDatabase(int $serverId, int $databaseId, array $data) + * @method static void deleteDatabase(int $serverId, int $databaseId) + * @method static void syncDatabases(int $serverId) + * @method static \Laravel\Forge\Resources\Monitor[] monitors(int $serverId) + * @method static \Laravel\Forge\Resources\Monitor monitor(int $serverId, int $monitorId) + * @method static \Laravel\Forge\Resources\Monitor createMonitor(int $serverId, array $data) + * @method static void deleteMonitor(int $serverId, int $monitorId) + * @method static \Laravel\Forge\Resources\NginxTemplate[] nginxTemplates(int $serverId) + * @method static \Laravel\Forge\Resources\NginxTemplate nginxTemplate(int $serverId, int $templateId) + * @method static \Laravel\Forge\Resources\NginxTemplate nginxDefaultTemplate(int $serverId) + * @method static \Laravel\Forge\Resources\NginxTemplate createNginxTemplate(int $serverId, array $data, bool $wait = true) + * @method static \Laravel\Forge\Resources\NginxTemplate updateNginxTemplate(int $serverId, int $templateId, array $data) + * @method static void deleteNginxTemplate(int $serverId, int $templateId) + * @method static \Laravel\Forge\Resources\SiteCommand executeSiteCommand(int $serverId, int $siteId, array $data) + * @method static \Laravel\Forge\Resources\SiteCommand listCommandHistory(int $serverId, int $siteId) + * @method static \Laravel\Forge\Resources\SiteCommand getSiteCommand(int $serverId, int $siteId, int $commandId) + * * @see \Laravel\Forge\Forge */ class Forge extends Facade From a4f06a0e6f382bb011a6f2127c2cb858bd05b692 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Thu, 20 Jun 2024 09:58:41 -0400 Subject: [PATCH 6/9] Remove return type --- src/ForgeManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ForgeManager.php b/src/ForgeManager.php index 1cac29e..7eb6b70 100644 --- a/src/ForgeManager.php +++ b/src/ForgeManager.php @@ -35,7 +35,7 @@ public function __construct($token) * @param array $parameters * @return mixed */ - public function __call(string $method, array $parameters): mixed + public function __call(string $method, array $parameters) { return $this->forwardCallTo($this->forge, $method, $parameters); } From f8d453ca2ba40d01e239df18eff20f1513527ad5 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Fri, 21 Jun 2024 09:39:59 -0400 Subject: [PATCH 7/9] Require illuminate/support --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 8c8b156..c5a2ce5 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "guzzlehttp/guzzle": "^6.3.1|^7.0" }, "require-dev": { + "illuminate/support": "^7.0|^8.0|^9.0|^10.0|^11.0", "mockery/mockery": "^1.3.1", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^8.4|^9.0|^10.4" From 6796f16263453ad8f2453361ae36958c182e296e Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Tue, 25 Jun 2024 09:43:55 -0400 Subject: [PATCH 8/9] Forward guzzle client --- src/ForgeManager.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ForgeManager.php b/src/ForgeManager.php index 7eb6b70..ee9f4b3 100644 --- a/src/ForgeManager.php +++ b/src/ForgeManager.php @@ -2,6 +2,7 @@ namespace Laravel\Forge; +use GuzzleHttp\Client as HttpClient; use Illuminate\Support\Traits\ForwardsCalls; /** @@ -22,10 +23,11 @@ class ForgeManager * Create a new Forge manager instance. * * @param string $token + * @param \GuzzleHttp\Client|null $guzzle */ - public function __construct($token) + public function __construct($token, HttpClient $guzzle = null) { - $this->forge = new Forge($token); + $this->forge = new Forge($token, $guzzle); } /** From df8476fa42ea661be6fa82dc129efa69a56d8328 Mon Sep 17 00:00:00 2001 From: Steve Bauman Date: Tue, 25 Jun 2024 18:55:56 -0400 Subject: [PATCH 9/9] Fix CS --- src/ForgeManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ForgeManager.php b/src/ForgeManager.php index ee9f4b3..109eed0 100644 --- a/src/ForgeManager.php +++ b/src/ForgeManager.php @@ -23,7 +23,7 @@ class ForgeManager * Create a new Forge manager instance. * * @param string $token - * @param \GuzzleHttp\Client|null $guzzle + * @param \GuzzleHttp\Client|null $guzzle */ public function __construct($token, HttpClient $guzzle = null) {