├── src ├── Exceptions │ ├── ForbiddenException.php │ ├── FailedActionException.php │ ├── NotFoundException.php │ ├── RateLimitExceededException.php │ ├── ValidationException.php │ └── TimeoutException.php ├── Resources │ ├── GitProviders.php │ ├── LoadBalancingStrategies.php │ ├── ServerTypes.php │ ├── ServerProviders.php │ ├── Credential.php │ ├── Event.php │ ├── Webhook.php │ ├── InstallableServices.php │ ├── SSHKey.php │ ├── PHPVersion.php │ ├── NginxTemplate.php │ ├── FirewallRule.php │ ├── Database.php │ ├── SecurityRule.php │ ├── Monitor.php │ ├── DatabaseUser.php │ ├── Job.php │ ├── RedirectRule.php │ ├── Recipe.php │ ├── Daemon.php │ ├── SiteCommand.php │ ├── Backup.php │ ├── Resource.php │ ├── Worker.php │ ├── User.php │ ├── Certificate.php │ ├── BackupConfiguration.php │ ├── Server.php │ └── Site.php ├── Actions │ ├── ManagesCredentials.php │ ├── ManagesSiteCommands.php │ ├── ManagesMonitors.php │ ├── ManagesRecipes.php │ ├── ManagesJobs.php │ ├── ManagesSSHKeys.php │ ├── ManagesWebhooks.php │ ├── ManagesFirewallRules.php │ ├── ManagesRedirectRules.php │ ├── ManagesSecurityRules.php │ ├── ManagesDatabaseUsers.php │ ├── ManagesDaemons.php │ ├── ManagesDatabases.php │ ├── ManagesNginxTemplates.php │ ├── ManagesWorkers.php │ ├── ManagesBackups.php │ ├── ManagesCertificates.php │ ├── ManagesServers.php │ └── ManagesSites.php ├── ForgeServiceProvider.php ├── ForgeManager.php ├── Forge.php ├── MakesHttpRequests.php └── Facades │ └── Forge.php ├── LICENSE.md ├── composer.json └── README.md /src/Exceptions/ForbiddenException.php: -------------------------------------------------------------------------------- 1 | transformCollection( 17 | $this->get('credentials')['credentials'], Credential::class 18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/ForgeServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->singleton(ForgeManager::class, function ($app) { 16 | return new ForgeManager($app['config']->get('services.forge.token')); 17 | }); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Exceptions/RateLimitExceededException.php: -------------------------------------------------------------------------------- 1 | rateLimitResetsAt = $rateLimitReset; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Exceptions/ValidationException.php: -------------------------------------------------------------------------------- 1 | errors = $errors; 26 | } 27 | 28 | /** 29 | * The array of errors. 30 | * 31 | * @return array 32 | */ 33 | public function errors() 34 | { 35 | return $this->errors; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Exceptions/TimeoutException.php: -------------------------------------------------------------------------------- 1 | output = $output; 26 | } 27 | 28 | /** 29 | * The output returned from the operation. 30 | * 31 | * @return array 32 | */ 33 | public function output() 34 | { 35 | return $this->output; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Resources/Event.php: -------------------------------------------------------------------------------- 1 | forge = new Forge($token, $guzzle); 30 | } 31 | 32 | /** 33 | * Dynamically pass methods to the Forge instance. 34 | * 35 | * @return mixed 36 | */ 37 | public function __call(string $method, array $parameters) 38 | { 39 | return $this->forwardCallTo($this->forge, $method, $parameters); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Resources/Webhook.php: -------------------------------------------------------------------------------- 1 | forge->deleteWebhook($this->serverId, $this->siteId, $this->id); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Resources/InstallableServices.php: -------------------------------------------------------------------------------- 1 | forge->deleteSSHKey($this->serverId, $this->id); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Resources/PHPVersion.php: -------------------------------------------------------------------------------- 1 | forge->updateNginxTemplate($this->serverId, $this->id, $data); 43 | } 44 | 45 | /** 46 | * Delete the given nginx template. 47 | * 48 | * @return void 49 | */ 50 | public function delete() 51 | { 52 | $this->forge->deleteNginxTemplate($this->serverId, $this->id); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Resources/FirewallRule.php: -------------------------------------------------------------------------------- 1 | forge->deleteFirewallRule($this->serverId, $this->id); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Resources/Database.php: -------------------------------------------------------------------------------- 1 | forge->updateDatabase($this->serverId, $this->id, $data); 50 | } 51 | 52 | /** 53 | * Delete the given database. 54 | * 55 | * @return void 56 | */ 57 | public function delete() 58 | { 59 | $this->forge->deleteDatabase($this->serverId, $this->id); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Resources/SecurityRule.php: -------------------------------------------------------------------------------- 1 | forge->deleteSecurityRule($this->serverId, $this->siteId, $this->id); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Resources/Monitor.php: -------------------------------------------------------------------------------- 1 | forge->updateDatabaseUser($this->serverId, $this->id, $data); 50 | } 51 | 52 | /** 53 | * Delete the given user. 54 | * 55 | * @return void 56 | */ 57 | public function delete() 58 | { 59 | $this->forge->deleteDatabaseUser($this->serverId, $this->id); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Resources/Job.php: -------------------------------------------------------------------------------- 1 | forge->deleteJob($this->serverId, $this->id); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Resources/RedirectRule.php: -------------------------------------------------------------------------------- 1 | forge->deleteRedirectRule($this->serverId, $this->siteId, $this->id); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Resources/Recipe.php: -------------------------------------------------------------------------------- 1 | forge->updateRecipe($this->id, $data); 50 | } 51 | 52 | /** 53 | * Delete the given recipe. 54 | * 55 | * @return void 56 | */ 57 | public function delete() 58 | { 59 | $this->forge->deleteRecipe($this->id); 60 | } 61 | 62 | /** 63 | * Run the given recipe. 64 | * 65 | * @return void 66 | */ 67 | public function run(array $data) 68 | { 69 | $this->forge->runRecipe($this->id, $data); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Resources/Daemon.php: -------------------------------------------------------------------------------- 1 | forge->restartDaemon($this->serverId, $this->id, $wait); 65 | } 66 | 67 | /** 68 | * Delete the given daemon. 69 | * 70 | * @return void 71 | */ 72 | public function delete() 73 | { 74 | $this->forge->deleteDaemon($this->serverId, $this->id); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Actions/ManagesSiteCommands.php: -------------------------------------------------------------------------------- 1 | post("servers/$serverId/sites/$siteId/commands", $data)['command']); 19 | } 20 | 21 | /** 22 | * List commands for a site. 23 | * 24 | * @param int $serverId 25 | * @param int $siteId 26 | * @return \Laravel\Forge\Resources\SiteCommand 27 | */ 28 | public function listCommandHistory($serverId, $siteId) 29 | { 30 | return $this->transformCollection( 31 | $this->get("servers/$serverId/sites/$siteId/commands")['commands'], 32 | SiteCommand::class 33 | ); 34 | } 35 | 36 | /** 37 | * Get the output for a command. 38 | * 39 | * @param int $serverId 40 | * @param int $siteId 41 | * @param int $commandId 42 | * @return \Laravel\Forge\Resources\SiteCommand 43 | */ 44 | public function getSiteCommand($serverId, $siteId, $commandId) 45 | { 46 | $command = $this->get("servers/$serverId/sites/$siteId/commands/$commandId"); 47 | 48 | return $this->transformCollection( 49 | [$command['command']], 50 | SiteCommand::class, 51 | ['output' => $command['output']] 52 | ); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Resources/SiteCommand.php: -------------------------------------------------------------------------------- 1 | transformCollection( 18 | $this->get("servers/$serverId/monitors")['monitors'], 19 | Monitor::class, 20 | ['server_id' => $serverId] 21 | ); 22 | } 23 | 24 | /** 25 | * Get a monitor instance. 26 | * 27 | * @param int $serverId 28 | * @param int $monitorId 29 | * @return \Laravel\Forge\Resources\Monitor 30 | */ 31 | public function monitor($serverId, $monitorId) 32 | { 33 | return new Monitor( 34 | $this->get("servers/$serverId/monitors/$monitorId")['monitor'] + ['server_id' => $serverId], $this 35 | ); 36 | } 37 | 38 | /** 39 | * Create a new monitor. 40 | * 41 | * @param int $serverId 42 | * @return \Laravel\Forge\Resources\Monitor 43 | */ 44 | public function createMonitor($serverId, array $data) 45 | { 46 | $monitor = $this->post("servers/$serverId/monitors", $data)['monitor']; 47 | 48 | return new Monitor($monitor + ['server_id' => $serverId], $this); 49 | } 50 | 51 | /** 52 | * Delete the given monitor. 53 | * 54 | * @param int $serverId 55 | * @param int $monitorId 56 | * @return void 57 | */ 58 | public function deleteMonitor($serverId, $monitorId) 59 | { 60 | $this->delete("servers/$serverId/monitors/$monitorId"); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel/forge-sdk", 3 | "description": "The official Laravel Forge PHP SDK.", 4 | "keywords": ["laravel", "forge"], 5 | "license": "MIT", 6 | "support": { 7 | "issues": "https://github.com/laravel/forge-sdk/issues", 8 | "source": "https://github.com/laravel/forge-sdk" 9 | }, 10 | "authors": [ 11 | { 12 | "name": "Taylor Otwell", 13 | "email": "taylor@laravel.com" 14 | }, 15 | { 16 | "name": "Mohamed Said", 17 | "email": "mohamed@laravel.com" 18 | }, 19 | { 20 | "name": "Dries Vints", 21 | "email": "dries@laravel.com" 22 | }, 23 | { 24 | "name": "James Brooks", 25 | "email": "james@laravel.com" 26 | } 27 | ], 28 | "require": { 29 | "php": "^7.2|^8.0", 30 | "ext-json": "*", 31 | "guzzlehttp/guzzle": "^6.3.1|^7.0" 32 | }, 33 | "require-dev": { 34 | "illuminate/support": "^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", 35 | "mockery/mockery": "^1.3.1", 36 | "phpstan/phpstan": "^1.10", 37 | "phpunit/phpunit": "^8.4|^9.0|^10.4" 38 | }, 39 | "autoload": { 40 | "psr-4": { 41 | "Laravel\\Forge\\": "src/" 42 | } 43 | }, 44 | "autoload-dev": { 45 | "psr-4": { 46 | "Tests\\": "tests/" 47 | } 48 | }, 49 | "extra": { 50 | "branch-alias": { 51 | "dev-master": "3.x-dev" 52 | }, 53 | "laravel": { 54 | "providers": [ 55 | "Laravel\\Forge\\ForgeServiceProvider" 56 | ] 57 | } 58 | }, 59 | "config": { 60 | "sort-packages": true 61 | }, 62 | "minimum-stability": "dev", 63 | "prefer-stable": true 64 | } 65 | -------------------------------------------------------------------------------- /src/Actions/ManagesRecipes.php: -------------------------------------------------------------------------------- 1 | transformCollection( 17 | $this->get('recipes')['recipes'], Recipe::class 18 | ); 19 | } 20 | 21 | /** 22 | * Get a recipe instance. 23 | * 24 | * @param string $recipeId 25 | * @return \Laravel\Forge\Resources\Recipe 26 | */ 27 | public function recipe($recipeId) 28 | { 29 | return new Recipe($this->get("recipes/$recipeId")['recipe']); 30 | } 31 | 32 | /** 33 | * Create a new recipe. 34 | * 35 | * @return \Laravel\Forge\Resources\Recipe 36 | */ 37 | public function createRecipe(array $data) 38 | { 39 | return new Recipe($this->post('recipes', $data)['recipe']); 40 | } 41 | 42 | /** 43 | * Update the given recipe. 44 | * 45 | * @param string $recipeId 46 | * @return \Laravel\Forge\Resources\Recipe 47 | */ 48 | public function updateRecipe($recipeId, array $data) 49 | { 50 | return new Recipe($this->put("recipes/$recipeId", $data)['recipe']); 51 | } 52 | 53 | /** 54 | * Delete the given recipe. 55 | * 56 | * @param string $recipeId 57 | * @return void 58 | */ 59 | public function deleteRecipe($recipeId) 60 | { 61 | $this->delete("recipes/$recipeId"); 62 | } 63 | 64 | /** 65 | * Run the given recipe. 66 | * 67 | * @param string $recipeId 68 | * @return void 69 | */ 70 | public function runRecipe($recipeId, array $data) 71 | { 72 | $this->post("recipes/$recipeId/run", $data); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Actions/ManagesJobs.php: -------------------------------------------------------------------------------- 1 | transformCollection( 18 | $this->get("servers/$serverId/jobs")['jobs'], 19 | Job::class, 20 | ['server_id' => $serverId] 21 | ); 22 | } 23 | 24 | /** 25 | * Get a job instance. 26 | * 27 | * @param int $serverId 28 | * @param int $jobId 29 | * @return \Laravel\Forge\Resources\Job 30 | */ 31 | public function job($serverId, $jobId) 32 | { 33 | return new Job( 34 | $this->get("servers/$serverId/jobs/$jobId")['job'] + ['server_id' => $serverId], $this 35 | ); 36 | } 37 | 38 | /** 39 | * Create a new job. 40 | * 41 | * @param int $serverId 42 | * @param bool $wait 43 | * @return \Laravel\Forge\Resources\Job 44 | */ 45 | public function createJob($serverId, array $data, $wait = true) 46 | { 47 | $job = $this->post("servers/$serverId/jobs", $data)['job']; 48 | 49 | if ($wait) { 50 | return $this->retry($this->getTimeout(), function () use ($serverId, $job) { 51 | $job = $this->job($serverId, $job['id']); 52 | 53 | return $job->status == 'installed' ? $job : null; 54 | }); 55 | } 56 | 57 | return new Job($job + ['server_id' => $serverId], $this); 58 | } 59 | 60 | /** 61 | * Delete the given job. 62 | * 63 | * @param int $serverId 64 | * @param int $jobId 65 | * @return void 66 | */ 67 | public function deleteJob($serverId, $jobId) 68 | { 69 | $this->delete("servers/$serverId/jobs/$jobId"); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Actions/ManagesSSHKeys.php: -------------------------------------------------------------------------------- 1 | transformCollection( 18 | $this->get("servers/$serverId/keys")['keys'], 19 | SSHKey::class, 20 | ['server_id' => $serverId] 21 | ); 22 | } 23 | 24 | /** 25 | * Get an SSH key instance. 26 | * 27 | * @param int $serverId 28 | * @param int $keyId 29 | * @return \Laravel\Forge\Resources\SSHKey 30 | */ 31 | public function sshKey($serverId, $keyId) 32 | { 33 | return new SSHKey( 34 | $this->get("servers/$serverId/keys/$keyId")['key'] + ['server_id' => $serverId], $this 35 | ); 36 | } 37 | 38 | /** 39 | * Create a new SSH key. 40 | * 41 | * @param int $serverId 42 | * @param bool $wait 43 | * @return \Laravel\Forge\Resources\SSHKey 44 | */ 45 | public function createSSHKey($serverId, array $data, $wait = true) 46 | { 47 | $key = $this->post("servers/$serverId/keys", $data)['key']; 48 | 49 | if ($wait) { 50 | return $this->retry($this->getTimeout(), function () use ($serverId, $key) { 51 | $key = $this->sshKey($serverId, $key['id']); 52 | 53 | return $key->status == 'installed' ? $key : null; 54 | }); 55 | } 56 | 57 | return new SSHKey($key + ['server_id' => $serverId], $this); 58 | } 59 | 60 | /** 61 | * Delete the given key. 62 | * 63 | * @param int $serverId 64 | * @param int $keyId 65 | * @return void 66 | */ 67 | public function deleteSSHKey($serverId, $keyId) 68 | { 69 | $this->delete("servers/$serverId/keys/$keyId"); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Actions/ManagesWebhooks.php: -------------------------------------------------------------------------------- 1 | transformCollection( 19 | $this->get("servers/$serverId/sites/$siteId/webhooks")['webhooks'], 20 | Webhook::class, 21 | ['server_id' => $serverId, 'site_id' => $siteId] 22 | ); 23 | } 24 | 25 | /** 26 | * Get a webhook instance. 27 | * 28 | * @param int $serverId 29 | * @param int $siteId 30 | * @param int $webhookId 31 | * @return \Laravel\Forge\Resources\Webhook 32 | */ 33 | public function webhook($serverId, $siteId, $webhookId) 34 | { 35 | return new Webhook( 36 | $this->get("servers/$serverId/sites/$siteId/webhooks/$webhookId")['webhook'] 37 | + ['server_id' => $serverId, 'site_id' => $siteId], $this 38 | ); 39 | } 40 | 41 | /** 42 | * Create a new webhook. 43 | * 44 | * @param int $serverId 45 | * @param int $siteId 46 | * @return \Laravel\Forge\Resources\Webhook 47 | */ 48 | public function createWebhook($serverId, $siteId, array $data) 49 | { 50 | return new Webhook( 51 | $this->post("servers/$serverId/sites/$siteId/webhooks", $data)['webhook'] 52 | + ['server_id' => $serverId, 'site_id' => $siteId], $this 53 | ); 54 | } 55 | 56 | /** 57 | * Delete the given webhook. 58 | * 59 | * @param int $serverId 60 | * @param int $siteId 61 | * @param int $webhookId 62 | * @return void 63 | */ 64 | public function deleteWebhook($serverId, $siteId, $webhookId) 65 | { 66 | $this->delete("servers/$serverId/sites/$siteId/webhooks/$webhookId"); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Resources/Backup.php: -------------------------------------------------------------------------------- 1 | forge->restoreBackup($this->serverId, $this->backupConfigurationId, $this->id); 92 | } 93 | 94 | /** 95 | * Delete this backup. 96 | * 97 | * @return void 98 | */ 99 | public function delete() 100 | { 101 | $this->forge->deleteBackup($this->serverId, $this->backupConfigurationId, $this->id); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/Actions/ManagesFirewallRules.php: -------------------------------------------------------------------------------- 1 | transformCollection( 18 | $this->get("servers/$serverId/firewall-rules")['rules'], 19 | FirewallRule::class, 20 | ['server_id' => $serverId] 21 | ); 22 | } 23 | 24 | /** 25 | * Get a firewall rule instance. 26 | * 27 | * @param int $serverId 28 | * @param int $ruleId 29 | * @return \Laravel\Forge\Resources\FirewallRule 30 | */ 31 | public function firewallRule($serverId, $ruleId) 32 | { 33 | return new FirewallRule( 34 | $this->get("servers/$serverId/firewall-rules/$ruleId")['rule'] + ['server_id' => $serverId], $this 35 | ); 36 | } 37 | 38 | /** 39 | * Create a new firewall rule. 40 | * 41 | * @param int $serverId 42 | * @param bool $wait 43 | * @return \Laravel\Forge\Resources\FirewallRule 44 | */ 45 | public function createFirewallRule($serverId, array $data, $wait = true) 46 | { 47 | $rule = $this->post("servers/$serverId/firewall-rules", $data)['rule']; 48 | 49 | if ($wait) { 50 | return $this->retry($this->getTimeout(), function () use ($serverId, $rule) { 51 | $rule = $this->firewallRule($serverId, $rule['id']); 52 | 53 | return $rule->status == 'installed' ? $rule : null; 54 | }); 55 | } 56 | 57 | return new FirewallRule($rule + ['server_id' => $serverId], $this); 58 | } 59 | 60 | /** 61 | * Delete the given firewall rule. 62 | * 63 | * @param int $serverId 64 | * @param int $ruleId 65 | * @return void 66 | */ 67 | public function deleteFirewallRule($serverId, $ruleId) 68 | { 69 | $this->delete("servers/$serverId/firewall-rules/$ruleId"); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Resources/Resource.php: -------------------------------------------------------------------------------- 1 | attributes = $attributes; 32 | $this->forge = $forge; 33 | 34 | $this->fill(); 35 | } 36 | 37 | /** 38 | * Fill the resource with the array of attributes. 39 | * 40 | * @return void 41 | */ 42 | protected function fill() 43 | { 44 | foreach ($this->attributes as $key => $value) { 45 | $key = $this->camelCase($key); 46 | 47 | $this->{$key} = $value; 48 | } 49 | } 50 | 51 | /** 52 | * Convert the key name to camel case. 53 | * 54 | * @param string $key 55 | * @return string 56 | */ 57 | protected function camelCase($key) 58 | { 59 | $parts = explode('_', $key); 60 | 61 | foreach ($parts as $i => $part) { 62 | if ($i !== 0) { 63 | $parts[$i] = ucfirst($part); 64 | } 65 | } 66 | 67 | return str_replace(' ', '', implode(' ', $parts)); 68 | } 69 | 70 | /** 71 | * Transform the items of the collection to the given class. 72 | * 73 | * @param string $class 74 | * @return array 75 | */ 76 | protected function transformCollection(array $collection, $class, array $extraData = []) 77 | { 78 | return array_map(function ($data) use ($class, $extraData) { 79 | return new $class($data + $extraData, $this->forge); 80 | }, $collection); 81 | } 82 | 83 | /** 84 | * Transform the collection of tags to a string. 85 | * 86 | * @param string|null $separator 87 | * @return string 88 | */ 89 | protected function transformTags(array $tags, $separator = null) 90 | { 91 | $separator = $separator ?: ', '; 92 | 93 | return implode($separator, array_column($tags ?? [], 'name')); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/Resources/Worker.php: -------------------------------------------------------------------------------- 1 | forge->restartWorker($this->serverId, $this->siteId, $this->id, $wait); 107 | } 108 | 109 | /** 110 | * Delete the given worker. 111 | * 112 | * @return void 113 | */ 114 | public function delete() 115 | { 116 | $this->forge->deleteWorker($this->serverId, $this->siteId, $this->id); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/Actions/ManagesRedirectRules.php: -------------------------------------------------------------------------------- 1 | transformCollection( 19 | $this->get("servers/$serverId/sites/$siteId/redirect-rules")['redirect_rules'], 20 | RedirectRule::class, 21 | ['server_id' => $serverId, 'site_id' => $siteId] 22 | ); 23 | } 24 | 25 | /** 26 | * Get a redirect rule instance. 27 | * 28 | * @param int $serverId 29 | * @param int $siteId 30 | * @param int $ruleId 31 | * @return \Laravel\Forge\Resources\RedirectRule 32 | */ 33 | public function redirectRule($serverId, $siteId, $ruleId) 34 | { 35 | return new RedirectRule( 36 | $this->get("servers/$serverId/sites/$siteId/redirect-rules/$ruleId")['redirect_rule'] 37 | + ['server_id' => $serverId, 'site_id' => $siteId], $this 38 | ); 39 | } 40 | 41 | /** 42 | * Create a new redirect rule. 43 | * 44 | * @param int $serverId 45 | * @param int $siteId 46 | * @param bool $wait 47 | * @return \Laravel\Forge\Resources\RedirectRule 48 | */ 49 | public function createRedirectRule($serverId, $siteId, array $data, $wait = true) 50 | { 51 | $redirectRule = $this->post("servers/$serverId/sites/$siteId/redirect-rules", $data)['redirect_rule']; 52 | 53 | if ($wait) { 54 | return $this->retry($this->getTimeout(), function () use ($serverId, $siteId, $redirectRule) { 55 | $redirectRule = $this->redirectRule($serverId, $siteId, $redirectRule['id']); 56 | 57 | return $redirectRule->status == 'installed' ? $redirectRule : null; 58 | }); 59 | } 60 | 61 | return new RedirectRule($redirectRule + ['server_id' => $serverId, 'site_id' => $siteId], $this); 62 | } 63 | 64 | /** 65 | * Delete the given redirect rule. 66 | * 67 | * @param int $serverId 68 | * @param int $siteId 69 | * @param int $ruleId 70 | * @return void 71 | */ 72 | public function deleteRedirectRule($serverId, $siteId, $ruleId) 73 | { 74 | $this->delete("servers/$serverId/sites/$siteId/redirect-rules/$ruleId"); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Actions/ManagesSecurityRules.php: -------------------------------------------------------------------------------- 1 | transformCollection( 19 | $this->get("servers/$serverId/sites/$siteId/security-rules")['security_rules'], 20 | SecurityRule::class, 21 | ['server_id' => $serverId, 'site_id' => $siteId] 22 | ); 23 | } 24 | 25 | /** 26 | * Get a security rule instance. 27 | * 28 | * @param int $serverId 29 | * @param int $siteId 30 | * @param int $ruleId 31 | * @return \Laravel\Forge\Resources\SecurityRule 32 | */ 33 | public function securityRule($serverId, $siteId, $ruleId) 34 | { 35 | return new SecurityRule( 36 | $this->get("servers/$serverId/sites/$siteId/security-rules/$ruleId")['security_rule'] 37 | + ['server_id' => $serverId, 'site_id' => $siteId], $this 38 | ); 39 | } 40 | 41 | /** 42 | * Create a new security rule. 43 | * 44 | * @param int $serverId 45 | * @param int $siteId 46 | * @param bool $wait 47 | * @return \Laravel\Forge\Resources\SecurityRule 48 | */ 49 | public function createSecurityRule($serverId, $siteId, array $data, $wait = true) 50 | { 51 | $securityRule = $this->post("servers/$serverId/sites/$siteId/security-rules", $data)['security_rule']; 52 | 53 | if ($wait) { 54 | return $this->retry($this->getTimeout(), function () use ($serverId, $siteId, $securityRule) { 55 | $securityRule = $this->securityRule($serverId, $siteId, $securityRule['id']); 56 | 57 | return $securityRule->status == 'installed' ? $securityRule : null; 58 | }); 59 | } 60 | 61 | return new SecurityRule($securityRule + ['server_id' => $serverId, 'site_id' => $siteId], $this); 62 | } 63 | 64 | /** 65 | * Delete the given security rule. 66 | * 67 | * @param int $serverId 68 | * @param int $siteId 69 | * @param int $ruleId 70 | * @return void 71 | */ 72 | public function deleteSecurityRule($serverId, $siteId, $ruleId) 73 | { 74 | $this->delete("servers/$serverId/sites/$siteId/security-rules/$ruleId"); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Resources/User.php: -------------------------------------------------------------------------------- 1 | transformCollection( 18 | $this->get("servers/$serverId/database-users")['users'], 19 | DatabaseUser::class, 20 | ['server_id' => $serverId] 21 | ); 22 | } 23 | 24 | /** 25 | * Get a Database User instance. 26 | * 27 | * @param int $serverId 28 | * @param int $userId 29 | * @return \Laravel\Forge\Resources\DatabaseUser 30 | */ 31 | public function databaseUser($serverId, $userId) 32 | { 33 | return new DatabaseUser( 34 | $this->get("servers/$serverId/database-users/$userId")['user'] + ['server_id' => $serverId], $this 35 | ); 36 | } 37 | 38 | /** 39 | * Create a new Database User. 40 | * 41 | * @param int $serverId 42 | * @param bool $wait 43 | * @return \Laravel\Forge\Resources\DatabaseUser 44 | */ 45 | public function createDatabaseUser($serverId, array $data, $wait = true) 46 | { 47 | $user = $this->post("servers/$serverId/database-users", $data)['user']; 48 | 49 | if ($wait) { 50 | return $this->retry($this->getTimeout(), function () use ($serverId, $user) { 51 | $user = $this->databaseUser($serverId, $user['id']); 52 | 53 | return $user->status == 'installed' ? $user : null; 54 | }); 55 | } 56 | 57 | return new DatabaseUser($user + ['server_id' => $serverId], $this); 58 | } 59 | 60 | /** 61 | * Update the given Database User. 62 | * 63 | * @param int $serverId 64 | * @param int $userId 65 | * @return \Laravel\Forge\Resources\DatabaseUser 66 | */ 67 | public function updateDatabaseUser($serverId, $userId, array $data) 68 | { 69 | return new DatabaseUser( 70 | $this->put("servers/$serverId/database-users/$userId", $data)['user'] 71 | + ['server_id' => $serverId], $this 72 | ); 73 | } 74 | 75 | /** 76 | * Delete the given user. 77 | * 78 | * @param int $serverId 79 | * @param int $userId 80 | * @return void 81 | */ 82 | public function deleteDatabaseUser($serverId, $userId) 83 | { 84 | $this->delete("servers/$serverId/database-users/$userId"); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Actions/ManagesDaemons.php: -------------------------------------------------------------------------------- 1 | transformCollection( 18 | $this->get("servers/$serverId/daemons")['daemons'], 19 | Daemon::class, 20 | ['server_id' => $serverId] 21 | ); 22 | } 23 | 24 | /** 25 | * Get a daemon instance. 26 | * 27 | * @param int $serverId 28 | * @param int $daemonId 29 | * @return \Laravel\Forge\Resources\Daemon 30 | */ 31 | public function daemon($serverId, $daemonId) 32 | { 33 | return new Daemon( 34 | $this->get("servers/$serverId/daemons/$daemonId")['daemon'] + ['server_id' => $serverId], $this 35 | ); 36 | } 37 | 38 | /** 39 | * Create a new daemon. 40 | * 41 | * @param int $serverId 42 | * @param bool $wait 43 | * @return \Laravel\Forge\Resources\Daemon 44 | */ 45 | public function createDaemon($serverId, array $data, $wait = true) 46 | { 47 | $daemon = $this->post("servers/$serverId/daemons", $data)['daemon']; 48 | 49 | if ($wait) { 50 | return $this->retry($this->getTimeout(), function () use ($serverId, $daemon) { 51 | $daemon = $this->daemon($serverId, $daemon['id']); 52 | 53 | return $daemon->status == 'installed' ? $daemon : null; 54 | }); 55 | } 56 | 57 | return new Daemon($daemon + ['server_id' => $serverId], $this); 58 | } 59 | 60 | /** 61 | * Restart the given daemon. 62 | * 63 | * @param int $serverId 64 | * @param int $daemonId 65 | * @param bool $wait 66 | * @return void 67 | */ 68 | public function restartDaemon($serverId, $daemonId, $wait = true) 69 | { 70 | $this->post("servers/$serverId/daemons/$daemonId/restart"); 71 | 72 | if ($wait) { 73 | $this->retry($this->getTimeout(), function () use ($serverId, $daemonId) { 74 | $daemon = $this->daemon($serverId, $daemonId); 75 | 76 | return $daemon->status == 'installed'; 77 | }); 78 | } 79 | } 80 | 81 | /** 82 | * Delete the given daemon. 83 | * 84 | * @param int $serverId 85 | * @param int $daemonId 86 | * @return void 87 | */ 88 | public function deleteDaemon($serverId, $daemonId) 89 | { 90 | $this->delete("servers/$serverId/daemons/$daemonId"); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Resources/Certificate.php: -------------------------------------------------------------------------------- 1 | forge->deleteCertificate($this->serverId, $this->siteId, $this->id); 92 | } 93 | 94 | /** 95 | * Get the SSL certificate signing request for the site. 96 | * 97 | * @return string 98 | */ 99 | public function getSigningRequest() 100 | { 101 | return $this->forge->getCertificateSigningRequest($this->serverId, $this->siteId, $this->id); 102 | } 103 | 104 | /** 105 | * Install the given certificate for the site. 106 | * 107 | * @param bool $wait 108 | * @return void 109 | */ 110 | public function install(array $data, $wait = true) 111 | { 112 | $this->forge->installCertificate($this->serverId, $this->siteId, $this->id, $data, $wait); 113 | } 114 | 115 | /** 116 | * Activate the given certificate for the site. 117 | * 118 | * @param bool $wait 119 | * @return void 120 | */ 121 | public function activate($wait = true) 122 | { 123 | $this->forge->activateCertificate($this->serverId, $this->siteId, $this->id, $wait); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/Actions/ManagesDatabases.php: -------------------------------------------------------------------------------- 1 | transformCollection( 18 | $this->get("servers/$serverId/databases")['databases'], 19 | Database::class, 20 | ['server_id' => $serverId] 21 | ); 22 | } 23 | 24 | /** 25 | * Get a Database instance. 26 | * 27 | * @param int $serverId 28 | * @param int $databaseId 29 | * @return \Laravel\Forge\Resources\Database 30 | */ 31 | public function database($serverId, $databaseId) 32 | { 33 | return new Database( 34 | $this->get("servers/$serverId/databases/$databaseId")['database'] + ['server_id' => $serverId], $this 35 | ); 36 | } 37 | 38 | /** 39 | * Create a new Database. 40 | * 41 | * @param int $serverId 42 | * @param bool $wait 43 | * @return \Laravel\Forge\Resources\Database 44 | */ 45 | public function createDatabase($serverId, array $data, $wait = true) 46 | { 47 | $database = $this->post("servers/$serverId/databases", $data)['database']; 48 | 49 | if ($wait) { 50 | return $this->retry($this->getTimeout(), function () use ($serverId, $database) { 51 | $database = $this->database($serverId, $database['id']); 52 | 53 | return $database->status == 'installed' ? $database : null; 54 | }); 55 | } 56 | 57 | return new Database($database + ['server_id' => $serverId], $this); 58 | } 59 | 60 | /** 61 | * Update the given Database. 62 | * 63 | * @param int $serverId 64 | * @param int $databaseId 65 | * @return \Laravel\Forge\Resources\Database 66 | */ 67 | public function updateDatabase($serverId, $databaseId, array $data) 68 | { 69 | return new Database( 70 | $this->put("servers/$serverId/databases/$databaseId", $data)['database'] 71 | + ['server_id' => $serverId], $this 72 | ); 73 | } 74 | 75 | /** 76 | * Delete the given Database. 77 | * 78 | * @param int $serverId 79 | * @param int $databaseId 80 | * @return void 81 | */ 82 | public function deleteDatabase($serverId, $databaseId) 83 | { 84 | $this->delete("servers/$serverId/databases/$databaseId"); 85 | } 86 | 87 | /** 88 | * Sync the databases. 89 | * 90 | * @param int $serverId 91 | * @return void 92 | */ 93 | public function syncDatabases($serverId) 94 | { 95 | $this->post("servers/$serverId/databases/sync"); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/Actions/ManagesNginxTemplates.php: -------------------------------------------------------------------------------- 1 | transformCollection( 18 | $this->get("servers/$serverId/nginx/templates")['templates'], 19 | NginxTemplate::class 20 | ); 21 | } 22 | 23 | /** 24 | * Get a Nginx Template instance. 25 | * 26 | * @param int $serverId 27 | * @param int $templateId 28 | * @return \Laravel\Forge\Resources\NginxTemplate 29 | */ 30 | public function nginxTemplate($serverId, $templateId) 31 | { 32 | return new NginxTemplate( 33 | $this->get("servers/$serverId/nginx/templates/$templateId")['template'], $this 34 | ); 35 | } 36 | 37 | /** 38 | * Get a Nginx Default Template instance. 39 | * 40 | * @param int $serverId 41 | * @return \Laravel\Forge\Resources\NginxTemplate 42 | */ 43 | public function nginxDefaultTemplate($serverId) 44 | { 45 | return new NginxTemplate( 46 | $this->get("servers/$serverId/nginx/templates/default"), $this 47 | ); 48 | } 49 | 50 | /** 51 | * Create a new Nginx Template. 52 | * 53 | * @param int $serverId 54 | * @param bool $wait 55 | * @return \Laravel\Forge\Resources\NginxTemplate 56 | */ 57 | public function createNginxTemplate($serverId, array $data, $wait = true) 58 | { 59 | $template = $this->post("servers/$serverId/nginx/templates", $data)['template']; 60 | 61 | if ($wait) { 62 | return $this->retry($this->getTimeout(), function () use ($serverId, $template) { 63 | return $this->nginxTemplate($serverId, $template['id']); 64 | }); 65 | } 66 | 67 | return new NginxTemplate($template, $this); 68 | } 69 | 70 | /** 71 | * Update the given Nginx Template. 72 | * 73 | * @param int $serverId 74 | * @param int $templateId 75 | * @return \Laravel\Forge\Resources\NginxTemplate 76 | */ 77 | public function updateNginxTemplate($serverId, $templateId, array $data) 78 | { 79 | return new NginxTemplate( 80 | $this->put("servers/$serverId/nginx/templates/$templateId", $data)['template'], $this 81 | ); 82 | } 83 | 84 | /** 85 | * Delete the given Nginx Template. 86 | * 87 | * @param int $serverId 88 | * @param int $templateId 89 | * @return void 90 | */ 91 | public function deleteNginxTemplate($serverId, $templateId) 92 | { 93 | $this->delete("servers/$serverId/nginx/templates/$templateId"); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/Actions/ManagesWorkers.php: -------------------------------------------------------------------------------- 1 | transformCollection( 19 | $this->get("servers/$serverId/sites/$siteId/workers")['workers'], 20 | Worker::class, 21 | ['server_id' => $serverId, 'site_id' => $siteId] 22 | ); 23 | } 24 | 25 | /** 26 | * Get a worker instance. 27 | * 28 | * @param int $serverId 29 | * @param int $siteId 30 | * @param int $workerId 31 | * @return \Laravel\Forge\Resources\Worker 32 | */ 33 | public function worker($serverId, $siteId, $workerId) 34 | { 35 | return new Worker( 36 | $this->get("servers/$serverId/sites/$siteId/workers/$workerId")['worker'] 37 | + ['server_id' => $serverId, 'site_id' => $siteId], $this 38 | ); 39 | } 40 | 41 | /** 42 | * Create a new worker. 43 | * 44 | * @param int $serverId 45 | * @param int $siteId 46 | * @param bool $wait 47 | * @return \Laravel\Forge\Resources\Worker 48 | */ 49 | public function createWorker($serverId, $siteId, array $data, $wait = true) 50 | { 51 | $worker = $this->post("servers/$serverId/sites/$siteId/workers", $data)['worker']; 52 | 53 | if ($wait) { 54 | return $this->retry($this->getTimeout(), function () use ($serverId, $siteId, $worker) { 55 | $worker = $this->worker($serverId, $siteId, $worker['id']); 56 | 57 | return $worker->status == 'installed' ? $worker : null; 58 | }); 59 | } 60 | 61 | return new Worker($worker + ['server_id' => $serverId, 'site_id' => $siteId], $this); 62 | } 63 | 64 | /** 65 | * Delete the given worker. 66 | * 67 | * @param int $serverId 68 | * @param int $siteId 69 | * @param int $workerId 70 | * @return void 71 | */ 72 | public function deleteWorker($serverId, $siteId, $workerId) 73 | { 74 | $this->delete("servers/$serverId/sites/$siteId/workers/$workerId"); 75 | } 76 | 77 | /** 78 | * Restart the given worker. 79 | * 80 | * @param int $serverId 81 | * @param int $siteId 82 | * @param int $workerId 83 | * @param bool $wait 84 | * @return void 85 | */ 86 | public function restartWorker($serverId, $siteId, $workerId, $wait = true) 87 | { 88 | $this->post("servers/$serverId/sites/$siteId/workers/$workerId/restart"); 89 | 90 | if ($wait) { 91 | $this->retry($this->getTimeout(), function () use ($serverId, $siteId, $workerId) { 92 | $key = $this->worker($serverId, $siteId, $workerId); 93 | 94 | return $key->status == 'installed'; 95 | }); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/Resources/BackupConfiguration.php: -------------------------------------------------------------------------------- 1 | databases = $this->transformCollection( 91 | $this->databases ?: [], 92 | Database::class, 93 | ['server_id' => $this->serverId] 94 | ); 95 | 96 | $this->backups = $this->transformCollection( 97 | $this->backups ?: [], 98 | Backup::class, 99 | ['server_id' => $this->serverId] 100 | ); 101 | } 102 | 103 | /** 104 | * Update the given configuration. 105 | * 106 | * @return void 107 | */ 108 | public function update(array $data) 109 | { 110 | $this->forge->updateBackupConfiguration($this->serverId, $this->id, $data); 111 | } 112 | 113 | /** 114 | * Delete the given configuration. 115 | * 116 | * @return void 117 | */ 118 | public function delete() 119 | { 120 | $this->forge->deleteBackupConfiguration($this->serverId, $this->id); 121 | } 122 | 123 | /** 124 | * Restore a backup for this configuration. 125 | * 126 | * @param int $backupId 127 | * @return void 128 | */ 129 | public function restoreBackup($backupId) 130 | { 131 | $this->forge->restoreBackup($this->serverId, $this->id, $backupId); 132 | } 133 | 134 | /** 135 | * Delete the given backup. 136 | * 137 | * @param int $backupId 138 | * @return void 139 | */ 140 | public function deleteBackup($backupId) 141 | { 142 | $this->forge->deleteBackup($this->serverId, $this->id, $backupId); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/Actions/ManagesBackups.php: -------------------------------------------------------------------------------- 1 | transformCollection( 18 | $this->get("servers/$serverId/backup-configs")['backups'], 19 | BackupConfiguration::class, 20 | ['server_id' => $serverId] 21 | ); 22 | } 23 | 24 | /** 25 | * Get a backup configuration. 26 | * 27 | * @param string $serverId 28 | * @param string $backupConfigurationId 29 | * @return \Laravel\Forge\Resources\BackupConfiguration 30 | */ 31 | public function backupConfiguration($serverId, $backupConfigurationId) 32 | { 33 | return new BackupConfiguration( 34 | $this->get("servers/{$serverId}/backup-configs/{$backupConfigurationId}")['backup'] 35 | + ['server_id' => $serverId], $this); 36 | } 37 | 38 | /** 39 | * Create a new backup configuration. 40 | * 41 | * @param string $serverId 42 | * @return \Laravel\Forge\Resources\BackupConfiguration 43 | */ 44 | public function createBackupConfiguration($serverId, array $data) 45 | { 46 | $response = $this->post("servers/{$serverId}/backup-configs", $data); 47 | 48 | return new BackupConfiguration($response['backup'] + ['server_id' => $serverId], $this); 49 | } 50 | 51 | /** 52 | * Update the given backup configuration. 53 | * 54 | * @param int $serverId 55 | * @param int $backupConfigurationId 56 | * @return \Laravel\Forge\Resources\BackupConfiguration 57 | */ 58 | public function updateBackupConfiguration($serverId, $backupConfigurationId, array $data) 59 | { 60 | return new BackupConfiguration( 61 | $this->put("servers/$serverId/backup-configs/$backupConfigurationId", $data)['backup'] 62 | + ['server_id' => $serverId], $this 63 | ); 64 | } 65 | 66 | /** 67 | * Delete a backup configuration. 68 | * 69 | * @param string $serverId 70 | * @param string $backupConfigurationId 71 | * @return void 72 | */ 73 | public function deleteBackupConfiguration($serverId, $backupConfigurationId) 74 | { 75 | $this->delete("servers/{$serverId}/backup-configs/{$backupConfigurationId}"); 76 | } 77 | 78 | /** 79 | * Restore a backup. 80 | * 81 | * @param string $serverId 82 | * @param string $backupConfigurationId 83 | * @param string $backupId 84 | * @return void 85 | */ 86 | public function restoreBackup($serverId, $backupConfigurationId, $backupId) 87 | { 88 | $this->post("servers/{$serverId}/backup-configs/{$backupConfigurationId}/backups/{$backupId}"); 89 | } 90 | 91 | /** 92 | * Delete a backup. 93 | * 94 | * @param string $serverId 95 | * @param string $backupConfigurationId 96 | * @param string $backupId 97 | * @return void 98 | */ 99 | public function deleteBackup($serverId, $backupConfigurationId, $backupId) 100 | { 101 | $this->delete("servers/{$serverId}/backup-configs/{$backupConfigurationId}/backups/{$backupId}"); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/Forge.php: -------------------------------------------------------------------------------- 1 | setApiKey($apiKey, $guzzle); 61 | } 62 | 63 | if (! is_null($guzzle)) { 64 | $this->guzzle = $guzzle; 65 | } 66 | } 67 | 68 | /** 69 | * Transform the items of the collection to the given class. 70 | * 71 | * @param array $collection 72 | * @param string $class 73 | * @param array $extraData 74 | * @return array 75 | */ 76 | protected function transformCollection($collection, $class, $extraData = []) 77 | { 78 | return array_map(function ($data) use ($class, $extraData) { 79 | return new $class($data + $extraData, $this); 80 | }, $collection); 81 | } 82 | 83 | /** 84 | * Set the api key and setup the guzzle request object. 85 | * 86 | * @param \GuzzleHttp\Client|null $guzzle 87 | * @return $this 88 | */ 89 | public function setApiKey(string $apiKey, $guzzle = null) 90 | { 91 | $this->apiKey = $apiKey; 92 | 93 | $this->guzzle = $guzzle ?: new HttpClient([ 94 | 'base_uri' => 'https://forge.laravel.com/api/v1/', 95 | 'http_errors' => false, 96 | 'headers' => [ 97 | 'Authorization' => 'Bearer '.$this->apiKey, 98 | 'Accept' => 'application/json', 99 | 'Content-Type' => 'application/json', 100 | 'User-Agent' => 'Laravel Forge PHP/3.0', 101 | ], 102 | ]); 103 | 104 | return $this; 105 | } 106 | 107 | /** 108 | * Set a new timeout. 109 | * 110 | * @param int $timeout 111 | * @return $this 112 | */ 113 | public function setTimeout($timeout) 114 | { 115 | $this->timeout = $timeout; 116 | 117 | return $this; 118 | } 119 | 120 | /** 121 | * Get the timeout. 122 | * 123 | * @return int 124 | */ 125 | public function getTimeout() 126 | { 127 | return $this->timeout; 128 | } 129 | 130 | /** 131 | * Get an authenticated user instance. 132 | * 133 | * @return \Laravel\Forge\Resources\User 134 | */ 135 | public function user() 136 | { 137 | return new User($this->get('user')['user']); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/MakesHttpRequests.php: -------------------------------------------------------------------------------- 1 | request('GET', $uri); 25 | } 26 | 27 | /** 28 | * Make a POST request to Forge servers and return the response. 29 | * 30 | * @param string $uri 31 | * @return mixed 32 | */ 33 | public function post($uri, array $payload = []) 34 | { 35 | return $this->request('POST', $uri, $payload); 36 | } 37 | 38 | /** 39 | * Make a PUT request to Forge servers and return the response. 40 | * 41 | * @param string $uri 42 | * @return mixed 43 | */ 44 | public function put($uri, array $payload = []) 45 | { 46 | return $this->request('PUT', $uri, $payload); 47 | } 48 | 49 | /** 50 | * Make a DELETE request to Forge servers and return the response. 51 | * 52 | * @param string $uri 53 | * @return mixed 54 | */ 55 | public function delete($uri, array $payload = []) 56 | { 57 | return $this->request('DELETE', $uri, $payload); 58 | } 59 | 60 | /** 61 | * Make request to Forge servers and return the response. 62 | * 63 | * @param string $verb 64 | * @param string $uri 65 | * @return mixed 66 | */ 67 | protected function request($verb, $uri, array $payload = []) 68 | { 69 | if (isset($payload['json'])) { 70 | $payload = ['json' => $payload['json']]; 71 | } else { 72 | $payload = empty($payload) ? [] : ['form_params' => $payload]; 73 | } 74 | 75 | $response = $this->guzzle->request($verb, $uri, $payload); 76 | 77 | $statusCode = $response->getStatusCode(); 78 | 79 | if ($statusCode < 200 || $statusCode > 299) { 80 | return $this->handleRequestError($response); 81 | } 82 | 83 | $responseBody = (string) $response->getBody(); 84 | 85 | return json_decode($responseBody, true) ?: $responseBody; 86 | } 87 | 88 | /** 89 | * Handle the request error. 90 | * 91 | * @return void 92 | * 93 | * @throws \Exception 94 | * @throws \Laravel\Forge\Exceptions\FailedActionException 95 | * @throws \Laravel\Forge\Exceptions\ForbiddenException 96 | * @throws \Laravel\Forge\Exceptions\NotFoundException 97 | * @throws \Laravel\Forge\Exceptions\ValidationException 98 | * @throws \Laravel\Forge\Exceptions\RateLimitExceededException 99 | */ 100 | protected function handleRequestError(ResponseInterface $response) 101 | { 102 | if ($response->getStatusCode() == 422) { 103 | throw new ValidationException(json_decode((string) $response->getBody(), true)); 104 | } 105 | 106 | if ($response->getStatusCode() === 403) { 107 | throw new ForbiddenException((string) $response->getBody()); 108 | } 109 | 110 | if ($response->getStatusCode() == 404) { 111 | throw new NotFoundException; 112 | } 113 | 114 | if ($response->getStatusCode() == 400) { 115 | throw new FailedActionException((string) $response->getBody()); 116 | } 117 | 118 | if ($response->getStatusCode() === 429) { 119 | throw new RateLimitExceededException( 120 | $response->hasHeader('x-ratelimit-reset') 121 | ? (int) $response->getHeader('x-ratelimit-reset')[0] 122 | : null 123 | ); 124 | } 125 | 126 | throw new Exception((string) $response->getBody()); 127 | } 128 | 129 | /** 130 | * Retry the callback or fail after x seconds. 131 | * 132 | * @param int $timeout 133 | * @param callable $callback 134 | * @param int $sleep 135 | * @return mixed 136 | * 137 | * @throws \Laravel\Forge\Exceptions\TimeoutException 138 | */ 139 | public function retry($timeout, $callback, $sleep = 5) 140 | { 141 | $start = time(); 142 | 143 | beginning: 144 | 145 | if ($output = $callback()) { 146 | return $output; 147 | } 148 | 149 | if (time() - $start < $timeout) { 150 | sleep($sleep); 151 | 152 | goto beginning; 153 | } 154 | 155 | if ($output === null || $output === false) { 156 | $output = []; 157 | } 158 | 159 | if (! is_array($output)) { 160 | $output = [$output]; 161 | } 162 | 163 | throw new TimeoutException($output); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/Actions/ManagesCertificates.php: -------------------------------------------------------------------------------- 1 | transformCollection( 19 | $this->get("servers/$serverId/sites/$siteId/certificates")['certificates'], 20 | Certificate::class, 21 | ['server_id' => $serverId, 'site_id' => $siteId] 22 | ); 23 | } 24 | 25 | /** 26 | * Get a certificate instance. 27 | * 28 | * @param int $serverId 29 | * @param int $siteId 30 | * @param int $certificateId 31 | * @return \Laravel\Forge\Resources\Certificate 32 | */ 33 | public function certificate($serverId, $siteId, $certificateId) 34 | { 35 | return new Certificate( 36 | $this->get("servers/$serverId/sites/$siteId/certificates/$certificateId")['certificate'] 37 | + ['server_id' => $serverId, 'site_id' => $siteId], $this 38 | ); 39 | } 40 | 41 | /** 42 | * Create a new certificate. 43 | * 44 | * @param int $serverId 45 | * @param int $siteId 46 | * @param bool $wait 47 | * @return \Laravel\Forge\Resources\Certificate 48 | */ 49 | public function createCertificate($serverId, $siteId, array $data, $wait = true) 50 | { 51 | $certificate = $this->post("servers/$serverId/sites/$siteId/certificates", $data)['certificate']; 52 | 53 | if ($wait) { 54 | return $this->retry($this->getTimeout(), function () use ($serverId, $siteId, $certificate) { 55 | $certificate = $this->certificate($serverId, $siteId, $certificate['id']); 56 | 57 | return $certificate->status == 'installed' ? $certificate : null; 58 | }); 59 | } 60 | 61 | return new Certificate($certificate + ['server_id' => $serverId, 'site_id' => $siteId], $this); 62 | } 63 | 64 | /** 65 | * Delete the given certificate. 66 | * 67 | * @param int $serverId 68 | * @param int $siteId 69 | * @param int $certificateId 70 | * @return void 71 | */ 72 | public function deleteCertificate($serverId, $siteId, $certificateId) 73 | { 74 | $this->delete("servers/$serverId/sites/$siteId/certificates/$certificateId"); 75 | } 76 | 77 | /** 78 | * Get the SSL certificate signing request for the site. 79 | * 80 | * @param int $serverId 81 | * @param int $siteId 82 | * @param int $certificateId 83 | * @return string 84 | */ 85 | public function getCertificateSigningRequest($serverId, $siteId, $certificateId) 86 | { 87 | return $this->get("servers/$serverId/sites/$siteId/certificates/$certificateId/csr"); 88 | } 89 | 90 | /** 91 | * Install the given certificate for the site. 92 | * 93 | * @param int $serverId 94 | * @param int $siteId 95 | * @param int $certificateId 96 | * @param bool $wait 97 | * @return void 98 | */ 99 | public function installCertificate($serverId, $siteId, $certificateId, array $data, $wait = true) 100 | { 101 | $this->post("servers/$serverId/sites/$siteId/certificates/$certificateId/install", $data); 102 | 103 | if ($wait) { 104 | $this->retry($this->getTimeout(), function () use ($serverId, $siteId, $certificateId) { 105 | $certificate = $this->certificate($serverId, $siteId, $certificateId); 106 | 107 | return $certificate->status == 'installed'; 108 | }); 109 | } 110 | } 111 | 112 | /** 113 | * Activate the given certificate for the site. 114 | * 115 | * @param int $serverId 116 | * @param int $siteId 117 | * @param int $certificateId 118 | * @param bool $wait 119 | * @return void 120 | */ 121 | public function activateCertificate($serverId, $siteId, $certificateId, $wait = true) 122 | { 123 | $this->post("servers/$serverId/sites/$siteId/certificates/$certificateId/activate"); 124 | 125 | if ($wait) { 126 | $this->retry($this->getTimeout(), function () use ($serverId, $siteId, $certificateId) { 127 | $certificate = $this->certificate($serverId, $siteId, $certificateId); 128 | 129 | return $certificate->activationStatus == 'activated'; 130 | }); 131 | } 132 | } 133 | 134 | /** 135 | * Add a LetsEncrypt certificate to a given site. 136 | * 137 | * @param int $serverId 138 | * @param int $siteId 139 | * @param bool $wait 140 | * @return \Laravel\Forge\Resources\Certificate 141 | */ 142 | public function obtainLetsEncryptCertificate($serverId, $siteId, array $data, $wait = true) 143 | { 144 | $certificate = $this->post("servers/$serverId/sites/$siteId/certificates/letsencrypt", $data)['certificate']; 145 | 146 | if ($wait) { 147 | return $this->retry($this->getTimeout(), function () use ($serverId, $siteId, $certificate) { 148 | $certificate = $this->certificate($serverId, $siteId, $certificate['id']); 149 | 150 | return $certificate->status == 'installed' ? $certificate : null; 151 | }); 152 | } 153 | 154 | return new Certificate($certificate + ['server_id' => $serverId, 'site_id' => $siteId], $this); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/Resources/Server.php: -------------------------------------------------------------------------------- 1 | forge->updateServer($this->id, $data); 148 | } 149 | 150 | /** 151 | * Delete the given server. 152 | * 153 | * @return void 154 | */ 155 | public function delete() 156 | { 157 | $this->forge->deleteServer($this->id); 158 | } 159 | 160 | /** 161 | * Reboot the server. 162 | * 163 | * @return void 164 | */ 165 | public function reboot() 166 | { 167 | $this->forge->rebootServer($this->id); 168 | } 169 | 170 | /** 171 | * Revoke forge access to the server. 172 | * 173 | * @return void 174 | */ 175 | public function revokeAccess() 176 | { 177 | $this->forge->revokeAccessToServer($this->id); 178 | } 179 | 180 | /** 181 | * Reconnect the server to Forge with a new key. 182 | * 183 | * @return void 184 | */ 185 | public function reconnect() 186 | { 187 | $this->forge->reconnectToServer($this->id); 188 | } 189 | 190 | /** 191 | * Reactivate a revoked server. 192 | * 193 | * @return void 194 | */ 195 | public function reactivate() 196 | { 197 | $this->forge->reactivateToServer($this->id); 198 | } 199 | 200 | /** 201 | * Reboot MySQL on the server. 202 | * 203 | * @return void 204 | */ 205 | public function rebootMysql() 206 | { 207 | $this->forge->rebootMysql($this->id); 208 | } 209 | 210 | /** 211 | * Stop MySQL on the server. 212 | * 213 | * @return void 214 | */ 215 | public function stopMysql() 216 | { 217 | $this->forge->stopMysql($this->id); 218 | } 219 | 220 | /** 221 | * Reboot Postgres on the server. 222 | * 223 | * @return void 224 | */ 225 | public function rebootPostgres() 226 | { 227 | $this->forge->rebootPostgres($this->id); 228 | } 229 | 230 | /** 231 | * Stop Postgres on the server. 232 | * 233 | * @return void 234 | */ 235 | public function stopPostgres() 236 | { 237 | $this->forge->stopPostgres($this->id); 238 | } 239 | 240 | /** 241 | * Reboot Nginx on the server. 242 | * 243 | * @return void 244 | */ 245 | public function rebootNginx() 246 | { 247 | $this->forge->rebootNginx($this->id); 248 | } 249 | 250 | /** 251 | * Stop Nginx on the server. 252 | * 253 | * @return void 254 | */ 255 | public function stopNginx() 256 | { 257 | $this->forge->stopNginx($this->id); 258 | } 259 | 260 | /** 261 | * Reboot PHP on the server. 262 | * 263 | * @return void 264 | */ 265 | public function rebootPHP(array $data) 266 | { 267 | $this->forge->rebootPHP($this->id, $data); 268 | } 269 | 270 | /** 271 | * Install Blackfire on the server. 272 | * 273 | * @return void 274 | */ 275 | public function installBlackfire(array $data) 276 | { 277 | $this->forge->installBlackfire($this->id, $data); 278 | } 279 | 280 | /** 281 | * Remove Blackfire from the server. 282 | * 283 | * @return void 284 | */ 285 | public function removeBlackfire() 286 | { 287 | $this->forge->removeBlackfire($this->id); 288 | } 289 | 290 | /** 291 | * Install Papertrail on the server. 292 | * 293 | * @return void 294 | */ 295 | public function installPapertrail(array $data) 296 | { 297 | $this->forge->installPapertrail($this->id, $data); 298 | } 299 | 300 | /** 301 | * Remove Papertrail from the server. 302 | * 303 | * @return void 304 | */ 305 | public function removePapertrail() 306 | { 307 | $this->forge->removePapertrail($this->id); 308 | } 309 | 310 | /** 311 | * Enable OPCache on the server. 312 | * 313 | * @return void 314 | */ 315 | public function enableOPCache() 316 | { 317 | $this->forge->enableOPCache($this->id); 318 | } 319 | 320 | /** 321 | * Disable OPCache on the server. 322 | * 323 | * @return void 324 | */ 325 | public function disableOPCache() 326 | { 327 | $this->forge->disableOPCache($this->id); 328 | } 329 | 330 | /** 331 | * Get the collection of PHP Versions. 332 | * 333 | * @return \Laravel\Forge\Resources\PHPVersion[] 334 | */ 335 | public function phpVersions() 336 | { 337 | return $this->forge->phpVersions($this->id); 338 | } 339 | 340 | /** 341 | * Install a version of PHP. 342 | * 343 | * @param string $version 344 | * @return void 345 | */ 346 | public function installPHP($version) 347 | { 348 | $this->forge->installPHP($this->id, $version); 349 | } 350 | 351 | /** 352 | * Patch the version of PHP. 353 | * 354 | * @param string $version 355 | * @return void 356 | */ 357 | public function updatePHP($version) 358 | { 359 | $this->forge->updatePHP($this->id, $version); 360 | } 361 | 362 | /** 363 | * Return the tags associated with the server. 364 | * 365 | * @param string|null $separator 366 | * @return string 367 | */ 368 | public function tags($separator = null) 369 | { 370 | return $this->transformTags($this->tags, $separator); 371 | } 372 | } 373 | -------------------------------------------------------------------------------- /src/Actions/ManagesServers.php: -------------------------------------------------------------------------------- 1 | transformCollection( 19 | $this->get('servers')['servers'], Server::class 20 | ); 21 | } 22 | 23 | /** 24 | * Get a server instance. 25 | * 26 | * @param string $serverId 27 | * @return \Laravel\Forge\Resources\Server 28 | */ 29 | public function server($serverId) 30 | { 31 | return new Server($this->get("servers/$serverId")['server'], $this); 32 | } 33 | 34 | /** 35 | * Create a new server. API recommends a 2 minute delay between checks. 36 | * 37 | * @param bool $wait 38 | * @param int $timeout 39 | * @return \Laravel\Forge\Resources\Server 40 | */ 41 | public function createServer(array $data, $wait = false, $timeout = 900) 42 | { 43 | $response = $this->post('servers', $data); 44 | 45 | $server = $response['server']; 46 | $initialSudoPassword = $response['sudo_password'] ?? null; 47 | $initialDatabasePassword = $response['database_password'] ?? null; 48 | $initialMeilisearchPassword = $response['meilisearch_password'] ?? null; 49 | $initialProvisionCommand = $response['provision_command'] ?? null; 50 | 51 | $server['sudo_password'] = $initialSudoPassword; 52 | $server['database_password'] = $initialDatabasePassword; 53 | $server['meilisearch_password'] = $initialMeilisearchPassword; 54 | $server['provision_command'] = $initialProvisionCommand; 55 | 56 | if ($wait) { 57 | return $this->retry($timeout, function () use ($server, $initialSudoPassword, $initialDatabasePassword, $initialMeilisearchPassword, $initialProvisionCommand) { 58 | $server = $this->server($server['id']); 59 | $server->sudoPassword = $initialSudoPassword; 60 | $server->databasePassword = $initialDatabasePassword; 61 | $server->meilisearchPassword = $initialMeilisearchPassword; 62 | $server->provisionCommand = $initialProvisionCommand; 63 | 64 | return $server->isReady ? $server : null; 65 | }, 120); 66 | } 67 | 68 | return new Server($server, $this); 69 | } 70 | 71 | /** 72 | * Update the given server. 73 | * 74 | * @param string $serverId 75 | * @return \Laravel\Forge\Resources\Server 76 | */ 77 | public function updateServer($serverId, array $data) 78 | { 79 | return $this->put("servers/$serverId", $data)['server']; 80 | } 81 | 82 | /** 83 | * Delete the given server. 84 | * 85 | * @param string $serverId 86 | * @return void 87 | */ 88 | public function deleteServer($serverId) 89 | { 90 | $this->delete("servers/$serverId"); 91 | } 92 | 93 | /** 94 | * Revoke forge access to the server. 95 | * 96 | * @param string $serverId 97 | * @return void 98 | */ 99 | public function revokeAccessToServer($serverId) 100 | { 101 | $this->post("servers/$serverId/revoke"); 102 | } 103 | 104 | /** 105 | * Reconnect the server to Forge with a new key. 106 | * 107 | * @param string $serverId 108 | * @return void 109 | */ 110 | public function reconnectToServer($serverId) 111 | { 112 | $this->post("servers/$serverId/reconnect")['public_key']; 113 | } 114 | 115 | /** 116 | * Reactivate a revoked server. 117 | * 118 | * @param string $serverId 119 | * @return void 120 | */ 121 | public function reactivateToServer($serverId) 122 | { 123 | $this->post("servers/$serverId/reactivate"); 124 | } 125 | 126 | /** 127 | * Reboot the server. 128 | * 129 | * @param string $serverId 130 | * @return void 131 | */ 132 | public function rebootServer($serverId) 133 | { 134 | $this->post("servers/$serverId/reboot"); 135 | } 136 | 137 | /** 138 | * Reboot MySQL on the server. 139 | * 140 | * @param string $serverId 141 | * @return void 142 | */ 143 | public function rebootMysql($serverId) 144 | { 145 | $this->post("servers/$serverId/mysql/reboot"); 146 | } 147 | 148 | /** 149 | * Stop MySQL on the server. 150 | * 151 | * @param string $serverId 152 | * @return void 153 | */ 154 | public function stopMysql($serverId) 155 | { 156 | $this->post("servers/$serverId/mysql/stop"); 157 | } 158 | 159 | /** 160 | * Reboot Postgres on the server. 161 | * 162 | * @param string $serverId 163 | * @return void 164 | */ 165 | public function rebootPostgres($serverId) 166 | { 167 | $this->post("servers/$serverId/postgres/reboot"); 168 | } 169 | 170 | /** 171 | * Stop Postgres on the server. 172 | * 173 | * @param string $serverId 174 | * @return void 175 | */ 176 | public function stopPostgres($serverId) 177 | { 178 | $this->post("servers/$serverId/postgres/stop"); 179 | } 180 | 181 | /** 182 | * Reboot Nginx on the server. 183 | * 184 | * @param string $serverId 185 | * @return void 186 | */ 187 | public function rebootNginx($serverId) 188 | { 189 | $this->post("servers/$serverId/nginx/reboot"); 190 | } 191 | 192 | /** 193 | * Stop Nginx on the server. 194 | * 195 | * @param string $serverId 196 | * @return void 197 | */ 198 | public function stopNginx($serverId) 199 | { 200 | $this->post("servers/$serverId/nginx/stop"); 201 | } 202 | 203 | /** 204 | * Reboot PHP on the server. 205 | * 206 | * @param string $serverId 207 | * @param array $data 208 | * @return void 209 | */ 210 | public function rebootPHP($serverId, $data) 211 | { 212 | $this->post("servers/$serverId/php/reboot", $data); 213 | } 214 | 215 | /** 216 | * Install Blackfire on the server. 217 | * 218 | * @param string $serverId 219 | * @return void 220 | */ 221 | public function installBlackfire($serverId, array $data) 222 | { 223 | $this->post("servers/$serverId/blackfire/install", $data); 224 | } 225 | 226 | /** 227 | * Remove Blackfire from the server. 228 | * 229 | * @param string $serverId 230 | * @return void 231 | */ 232 | public function removeBlackfire($serverId) 233 | { 234 | $this->delete("servers/$serverId/blackfire/remove"); 235 | } 236 | 237 | /** 238 | * Install Papertrail on the server. 239 | * 240 | * @param string $serverId 241 | * @return void 242 | */ 243 | public function installPapertrail($serverId, array $data) 244 | { 245 | $this->post("servers/$serverId/papertrail/install", $data); 246 | } 247 | 248 | /** 249 | * Remove Papertrail from the server. 250 | * 251 | * @param string $serverId 252 | * @return void 253 | */ 254 | public function removePapertrail($serverId) 255 | { 256 | $this->delete("servers/$serverId/papertrail/remove"); 257 | } 258 | 259 | /** 260 | * Enable OPCache on the server. 261 | * 262 | * @param string $serverId 263 | * @return void 264 | */ 265 | public function enableOPCache($serverId) 266 | { 267 | $this->post("servers/$serverId/php/opcache"); 268 | } 269 | 270 | /** 271 | * Disable OPCache on the server. 272 | * 273 | * @param string $serverId 274 | * @return void 275 | */ 276 | public function disableOPCache($serverId) 277 | { 278 | $this->delete("servers/$serverId/php/opcache"); 279 | } 280 | 281 | /** 282 | * Get the collection of PHP Versions. 283 | * 284 | * @param int $serverId 285 | * @return \Laravel\Forge\Resources\PHPVersion[] 286 | */ 287 | public function phpVersions($serverId) 288 | { 289 | return $this->transformCollection( 290 | $this->get("servers/$serverId/php"), 291 | PHPVersion::class 292 | ); 293 | } 294 | 295 | /** 296 | * Install a version of PHP. 297 | * 298 | * @param string $serverId 299 | * @param string $version 300 | * @return void 301 | */ 302 | public function installPHP($serverId, $version) 303 | { 304 | $this->post("servers/$serverId/php", ['version' => $version]); 305 | } 306 | 307 | /** 308 | * Patch the PHP version. 309 | * 310 | * @param string $serverId 311 | * @param string $version 312 | * @return void 313 | */ 314 | public function updatePHP($serverId, $version) 315 | { 316 | $this->post("servers/$serverId/php/update", ['version' => $version]); 317 | } 318 | 319 | /** 320 | * Get recent events. 321 | * 322 | * @param string|null $serverId 323 | * @return \Laravel\Forge\Resources\Event[] 324 | */ 325 | public function events($serverId = null) 326 | { 327 | $endpoint = is_null($serverId) ? 'servers/events' : 'servers/events?server_id='.$serverId; 328 | 329 | return $this->transformCollection( 330 | $this->get($endpoint), 331 | Event::class 332 | ); 333 | } 334 | 335 | /** 336 | * Get event details 337 | * 338 | * @param string $serverId 339 | * @param string $eventId 340 | * @return \Laravel\Forge\Resources\Event 341 | */ 342 | public function event($serverId, $eventId) 343 | { 344 | return new Event($this->get("servers/$serverId/events/$eventId"), $this); 345 | } 346 | } 347 | -------------------------------------------------------------------------------- /src/Resources/Site.php: -------------------------------------------------------------------------------- 1 | forge->refreshSiteToken($this->serverId, $this->id); 218 | } 219 | 220 | /** 221 | * Delete the given site. 222 | * 223 | * @return void 224 | */ 225 | public function delete() 226 | { 227 | $this->forge->deleteSite($this->serverId, $this->id); 228 | } 229 | 230 | /** 231 | * Install a git repository on the given site. 232 | * 233 | * @param bool $wait 234 | * @return \Laravel\Forge\Resources\Site 235 | */ 236 | public function installGitRepository(array $data, $wait = true) 237 | { 238 | return $this->forge->installGitRepositoryOnSite($this->serverId, $this->id, $data, $wait); 239 | } 240 | 241 | /** 242 | * Update the site's git repository parameters. 243 | * 244 | * @return void 245 | */ 246 | public function updateGitRepository(array $data) 247 | { 248 | $this->forge->updateSiteGitRepository($this->serverId, $this->id, $data); 249 | } 250 | 251 | /** 252 | * Destroy the git-based project installed on the site. 253 | * 254 | * @param bool $wait 255 | * @return void 256 | */ 257 | public function destroyGitRepository($wait = true) 258 | { 259 | $this->forge->destroySiteGitRepository($this->serverId, $this->id, $wait); 260 | } 261 | 262 | /** 263 | * Create a new deploy key on the site. 264 | * 265 | * @return array 266 | */ 267 | public function createDeployKey() 268 | { 269 | return $this->forge->createSiteDeployKey($this->serverId, $this->id); 270 | } 271 | 272 | /** 273 | * Destroy the deploy key on the site. 274 | * 275 | * @return void 276 | */ 277 | public function destroyDeployKey() 278 | { 279 | $this->forge->destroySiteDeployKey($this->serverId, $this->id); 280 | } 281 | 282 | /** 283 | * Get the content of the site's deployment script. 284 | * 285 | * @return string 286 | */ 287 | public function getDeploymentScript() 288 | { 289 | return $this->forge->siteDeploymentScript($this->serverId, $this->id); 290 | } 291 | 292 | /** 293 | * Update the content of the site's deployment script. 294 | * 295 | * @param string $content 296 | * @param bool $autoSource 297 | * @return void 298 | */ 299 | public function updateDeploymentScript($content, $autoSource = false) 300 | { 301 | $this->forge->updateSiteDeploymentScript($this->serverId, $this->id, $content, $autoSource); 302 | } 303 | 304 | /** 305 | * Enable "Quick Deploy" for the given site. 306 | * 307 | * @return void 308 | */ 309 | public function enableQuickDeploy() 310 | { 311 | $this->forge->enableQuickDeploy($this->serverId, $this->id); 312 | } 313 | 314 | /** 315 | * Disable "Quick Deploy" for the given site. 316 | * 317 | * @return void 318 | */ 319 | public function disableQuickDeploy() 320 | { 321 | $this->forge->disableQuickDeploy($this->serverId, $this->id); 322 | } 323 | 324 | /** 325 | * Deploy the given site. 326 | * 327 | * @param bool $wait 328 | * @return \Laravel\Forge\Resources\Site 329 | */ 330 | public function deploySite($wait = true) 331 | { 332 | return $this->forge->deploySite($this->serverId, $this->id, $wait); 333 | } 334 | 335 | /** 336 | * Reset deployment status for a given site. 337 | * 338 | * @return void 339 | */ 340 | public function resetDeploymentState() 341 | { 342 | return $this->forge->resetDeploymentState($this->serverId, $this->id); 343 | } 344 | 345 | /** 346 | * Get the last deployment log of the site. 347 | * 348 | * @return string 349 | */ 350 | public function siteDeploymentLog() 351 | { 352 | return $this->forge->siteDeploymentLog($this->serverId, $this->id); 353 | } 354 | 355 | /** 356 | * Get the deployments history of the site. 357 | * 358 | * @return string 359 | */ 360 | public function getDeploymentHistory() 361 | { 362 | return $this->forge->deploymentHistory($this->serverId, $this->id); 363 | } 364 | 365 | /** 366 | * Get a single deployment from the deployment history of a site. 367 | * 368 | * @param int $deploymentId 369 | * @return string 370 | */ 371 | public function getDeploymentHistoryDeployment($deploymentId) 372 | { 373 | return $this->forge->deploymentHistoryDeployment($this->serverId, $this->id, $deploymentId); 374 | } 375 | 376 | /** 377 | * Get the output for a deployment of the site. 378 | * 379 | * @param int $deploymentId 380 | * @return string 381 | */ 382 | public function getDeploymentHistoryOutput($deploymentId) 383 | { 384 | return $this->forge->deploymentHistoryOutput($this->serverId, $this->id, $deploymentId); 385 | } 386 | 387 | /** 388 | * Enable Hipchat Notifications for the given site. 389 | * 390 | * @return void 391 | */ 392 | public function enableHipchatNotifications(array $data) 393 | { 394 | $this->forge->enableHipchatNotifications($this->serverId, $this->id, $data); 395 | } 396 | 397 | /** 398 | * Disable Hipchat Notifications for the given site. 399 | * 400 | * @return void 401 | */ 402 | public function disableHipchatNotifications() 403 | { 404 | $this->forge->disableHipchatNotifications($this->serverId, $this->id); 405 | } 406 | 407 | /** 408 | * Set the deployment failure emails for a site. 409 | * 410 | * @return void 411 | */ 412 | public function setDeploymentFailureEmails(array $data) 413 | { 414 | $this->forge->setDeploymentFailureEmails($this->serverId, $this->id, $data); 415 | } 416 | 417 | /** 418 | * Install a new WordPress project. 419 | * 420 | * @return void 421 | */ 422 | public function installWordPress(array $data) 423 | { 424 | $this->forge->installWordPress($this->serverId, $this->id, $data); 425 | } 426 | 427 | /** 428 | * Remove the WordPress project installed on the site. 429 | * 430 | * @return void 431 | */ 432 | public function removeWordPress() 433 | { 434 | $this->forge->removeWordPress($this->serverId, $this->id); 435 | } 436 | 437 | /** 438 | * Install a new phpMyAdmin project. 439 | * 440 | * @return void 441 | */ 442 | public function installPhpMyAdmin(array $data) 443 | { 444 | $this->forge->installPhpMyAdmin($this->serverId, $this->id, $data); 445 | } 446 | 447 | /** 448 | * Remove phpMyAdmin and revert the site back to a default state. 449 | * 450 | * @return void 451 | */ 452 | public function removePhpMyAdmin() 453 | { 454 | $this->forge->removePhpMyAdmin($this->serverId, $this->id); 455 | } 456 | 457 | /** 458 | * Change the site's PHP version. 459 | * 460 | * @param string $version 461 | * @return void 462 | */ 463 | public function changePHPVersion($version) 464 | { 465 | $this->forge->changeSitePHPVersion($this->serverId, $this->id, $version); 466 | } 467 | 468 | /** 469 | * Return the aliases associated with the site. 470 | * 471 | * @param string|null $separator 472 | * @return string 473 | */ 474 | public function tags($separator = null) 475 | { 476 | return $this->transformTags($this->tags, $separator); 477 | } 478 | 479 | /** 480 | * Get the log for this site. 481 | * 482 | * @return string 483 | */ 484 | public function siteLog() 485 | { 486 | return $this->forge->siteLog($this->serverId, $this->id); 487 | } 488 | 489 | /** 490 | * Remove the log for this site. 491 | * 492 | * @return void 493 | */ 494 | public function deleteSiteLog() 495 | { 496 | return $this->forge->deleteSiteLog($this->serverId, $this->id); 497 | } 498 | } 499 | -------------------------------------------------------------------------------- /src/Facades/Forge.php: -------------------------------------------------------------------------------- 1 | transformCollection( 18 | $this->get("servers/$serverId/sites")['sites'], 19 | Site::class, 20 | ['server_id' => $serverId] 21 | ); 22 | } 23 | 24 | /** 25 | * Get a site instance. 26 | * 27 | * @param int $serverId 28 | * @param int $siteId 29 | * @return \Laravel\Forge\Resources\Site 30 | */ 31 | public function site($serverId, $siteId) 32 | { 33 | return new Site( 34 | $this->get("servers/$serverId/sites/$siteId")['site'] + ['server_id' => $serverId], $this 35 | ); 36 | } 37 | 38 | /** 39 | * Create a new site. 40 | * 41 | * @param int $serverId 42 | * @param bool $wait 43 | * @return \Laravel\Forge\Resources\Site 44 | */ 45 | public function createSite($serverId, array $data, $wait = true) 46 | { 47 | $site = $this->post("servers/$serverId/sites", $data)['site']; 48 | 49 | if ($wait) { 50 | return $this->retry($this->getTimeout(), function () use ($serverId, $site) { 51 | $site = $this->site($serverId, $site['id']); 52 | 53 | return $site->status == 'installed' ? $site : null; 54 | }); 55 | } 56 | 57 | return new Site($site + ['server_id' => $serverId], $this); 58 | } 59 | 60 | /** 61 | * Update the given site. 62 | * 63 | * @param int $serverId 64 | * @param int $siteId 65 | * @return \Laravel\Forge\Resources\Site 66 | */ 67 | public function updateSite($serverId, $siteId, array $data) 68 | { 69 | return new Site( 70 | $this->request('PUT', "servers/$serverId/sites/$siteId", ['json' => $data])['site'] 71 | + ['server_id' => $serverId], $this 72 | ); 73 | } 74 | 75 | /** 76 | * Add Site Aliases. 77 | * 78 | * @param int $serverId 79 | * @param int $siteId 80 | * @return \Laravel\Forge\Resources\Site 81 | */ 82 | public function addSiteAliases($serverId, $siteId, array $aliases) 83 | { 84 | return new Site( 85 | $this->put("servers/$serverId/sites/$siteId/aliases", compact('aliases'))['site'] 86 | + ['server_id' => $serverId], $this 87 | ); 88 | } 89 | 90 | /** 91 | * Refresh the site token. 92 | * 93 | * @param int $serverId 94 | * @param int $siteId 95 | * @return void 96 | */ 97 | public function refreshSiteToken($serverId, $siteId) 98 | { 99 | $this->post("servers/$serverId/sites/$siteId/refresh"); 100 | } 101 | 102 | /** 103 | * Delete the given site. 104 | * 105 | * @param int $serverId 106 | * @param int $siteId 107 | * @return void 108 | */ 109 | public function deleteSite($serverId, $siteId) 110 | { 111 | $this->delete("servers/$serverId/sites/$siteId"); 112 | } 113 | 114 | /** 115 | * Get the content of the site's Nginx configuration file. 116 | * 117 | * @param int $serverId 118 | * @param int $siteId 119 | * @return string 120 | */ 121 | public function siteNginxFile($serverId, $siteId) 122 | { 123 | return $this->get("servers/$serverId/sites/$siteId/nginx"); 124 | } 125 | 126 | /** 127 | * Update the content of the site's Nginx configuration file. 128 | * 129 | * @param int $serverId 130 | * @param int $siteId 131 | * @param string $content 132 | * @return void 133 | */ 134 | public function updateSiteNginxFile($serverId, $siteId, $content) 135 | { 136 | $this->put("servers/$serverId/sites/$siteId/nginx", compact('content')); 137 | } 138 | 139 | /** 140 | * Get the content of the site's Environment file. 141 | * 142 | * @param int $serverId 143 | * @param int $siteId 144 | * @return string 145 | */ 146 | public function siteEnvironmentFile($serverId, $siteId) 147 | { 148 | return $this->get("servers/$serverId/sites/$siteId/env"); 149 | } 150 | 151 | /** 152 | * Update the content of the site's Environment file. 153 | * 154 | * @param int $serverId 155 | * @param int $siteId 156 | * @param string $content 157 | * @return void 158 | */ 159 | public function updateSiteEnvironmentFile($serverId, $siteId, $content) 160 | { 161 | $this->put("servers/$serverId/sites/$siteId/env", compact('content')); 162 | } 163 | 164 | /** 165 | * Install a git repository on the given site. 166 | * 167 | * @param int $serverId 168 | * @param int $siteId 169 | * @param bool $wait 170 | * @return Site 171 | */ 172 | public function installGitRepositoryOnSite($serverId, $siteId, array $data, $wait = true) 173 | { 174 | $site = $this->post("servers/$serverId/sites/$siteId/git", $data); 175 | 176 | if ($wait) { 177 | return $this->retry($this->getTimeout(), function () use ($serverId, $siteId) { 178 | $site = $this->site($serverId, $siteId); 179 | 180 | return $site->repositoryStatus === 'installed' ? $site : null; 181 | }); 182 | } 183 | 184 | return new Site($site + ['server_id' => $serverId], $this); 185 | } 186 | 187 | /** 188 | * Update the site's git repository parameters. 189 | * 190 | * @param int $serverId 191 | * @param int $siteId 192 | * @return void 193 | */ 194 | public function updateSiteGitRepository($serverId, $siteId, array $data) 195 | { 196 | $this->put("servers/$serverId/sites/$siteId/git", $data); 197 | } 198 | 199 | /** 200 | * Destroy the git-based project installed on the site. 201 | * 202 | * @param int $serverId 203 | * @param int $siteId 204 | * @param bool $wait 205 | * @return void 206 | */ 207 | public function destroySiteGitRepository($serverId, $siteId, $wait = true) 208 | { 209 | $this->delete("servers/$serverId/sites/$siteId/git"); 210 | 211 | if ($wait) { 212 | $this->retry($this->getTimeout(), function () use ($serverId, $siteId) { 213 | return is_null($this->site($serverId, $siteId)->repositoryStatus); 214 | }); 215 | } 216 | } 217 | 218 | /** 219 | * Create a new deploy key on the site. 220 | * 221 | * @param int $serverId 222 | * @param int $siteId 223 | * @return array 224 | */ 225 | public function createSiteDeployKey($serverId, $siteId) 226 | { 227 | return $this->post("servers/$serverId/sites/$siteId/deploy-key"); 228 | } 229 | 230 | /** 231 | * Destroy the deploy key on the site. 232 | * 233 | * @param mixed $serverId 234 | * @param mixed $siteId 235 | * @return void 236 | */ 237 | public function destroySiteDeployKey($serverId, $siteId) 238 | { 239 | $this->delete("servers/$serverId/sites/$siteId/deploy-key"); 240 | } 241 | 242 | /** 243 | * Get the content of the site's deployment script. 244 | * 245 | * @param int $serverId 246 | * @param int $siteId 247 | * @return string 248 | */ 249 | public function siteDeploymentScript($serverId, $siteId) 250 | { 251 | return $this->get("servers/$serverId/sites/$siteId/deployment/script"); 252 | } 253 | 254 | /** 255 | * Update the content of the site's deployment script. 256 | * 257 | * @param int $serverId 258 | * @param int $siteId 259 | * @param string $content 260 | * @param bool $autoSource 261 | * @return void 262 | */ 263 | public function updateSiteDeploymentScript($serverId, $siteId, $content, $autoSource = false) 264 | { 265 | $this->put("servers/$serverId/sites/$siteId/deployment/script", [ 266 | 'content' => $content, 267 | 'auto_source' => $autoSource, 268 | ]); 269 | } 270 | 271 | /** 272 | * Enable "Quick Deploy" for the given site. 273 | * 274 | * @param int $serverId 275 | * @param int $siteId 276 | * @return void 277 | */ 278 | public function enableQuickDeploy($serverId, $siteId) 279 | { 280 | $this->post("servers/$serverId/sites/$siteId/deployment"); 281 | } 282 | 283 | /** 284 | * Disable "Quick Deploy" for the given site. 285 | * 286 | * @param int $serverId 287 | * @param int $siteId 288 | * @return void 289 | */ 290 | public function disableQuickDeploy($serverId, $siteId) 291 | { 292 | $this->delete("servers/$serverId/sites/$siteId/deployment"); 293 | } 294 | 295 | /** 296 | * Deploy the given site. 297 | * 298 | * @param int $serverId 299 | * @param int $siteId 300 | * @param bool $wait 301 | * @return \Laravel\Forge\Resources\Site 302 | */ 303 | public function deploySite($serverId, $siteId, $wait = true) 304 | { 305 | $site = $this->post("servers/$serverId/sites/$siteId/deployment/deploy"); 306 | 307 | if ($wait) { 308 | return $this->retry($this->getTimeout(), function () use ($serverId, $siteId) { 309 | $site = $this->site($serverId, $siteId); 310 | 311 | return is_null($site->deploymentStatus) ? $site : null; 312 | }); 313 | } 314 | 315 | return new Site($site + ['server_id' => $serverId], $this); 316 | } 317 | 318 | /** 319 | * Reset the deployment state of the given site. 320 | * 321 | * @param int $serverId 322 | * @param int $siteId 323 | * @return void 324 | */ 325 | public function resetDeploymentState($serverId, $siteId) 326 | { 327 | $this->post("servers/$serverId/sites/$siteId/deployment/reset"); 328 | } 329 | 330 | /** 331 | * Get the last deployment log of the site. 332 | * 333 | * @param int $serverId 334 | * @param int $siteId 335 | * @return string 336 | */ 337 | public function siteDeploymentLog($serverId, $siteId) 338 | { 339 | return $this->get("servers/$serverId/sites/$siteId/deployment/log"); 340 | } 341 | 342 | /** 343 | * Get the deployment history of the site. 344 | * 345 | * @param int $serverId 346 | * @param int $siteId 347 | * @return string 348 | */ 349 | public function deploymentHistory($serverId, $siteId) 350 | { 351 | return $this->get("/api/v1/servers/$serverId/sites/$siteId/deployment-history"); 352 | } 353 | 354 | /** 355 | * Get a single deployment from the deployment history of a site. 356 | * 357 | * @param int $serverId 358 | * @param int $siteId 359 | * @param int $deploymentId 360 | * @return string 361 | */ 362 | public function deploymentHistoryDeployment($serverId, $siteId, $deploymentId) 363 | { 364 | return $this->get("/api/v1/servers/$serverId/sites/$siteId/deployment-history/$deploymentId"); 365 | } 366 | 367 | /** 368 | * Get the output for a deployment of the site. 369 | * 370 | * @param int $serverId 371 | * @param int $siteId 372 | * @param int $deploymentId 373 | * @return string 374 | */ 375 | public function deploymentHistoryOutput($serverId, $siteId, $deploymentId) 376 | { 377 | return $this->get("/api/v1/servers/$serverId/sites/$siteId/deployment-history/$deploymentId/output"); 378 | } 379 | 380 | /** 381 | * Enable Hipchat Notifications for the given site. 382 | * 383 | * @param int $serverId 384 | * @param int $siteId 385 | * @return void 386 | */ 387 | public function enableHipchatNotifications($serverId, $siteId, array $data) 388 | { 389 | $this->post("servers/$serverId/sites/$siteId/notify/hipchat", $data); 390 | } 391 | 392 | /** 393 | * Disable Hipchat Notifications for the given site. 394 | * 395 | * @param int $serverId 396 | * @param int $siteId 397 | * @return void 398 | */ 399 | public function disableHipchatNotifications($serverId, $siteId) 400 | { 401 | $this->delete("servers/$serverId/sites/$siteId/notify/hipchat"); 402 | } 403 | 404 | /** 405 | * Set the deployment failure emails for the given site. 406 | * 407 | * @param int $serverId 408 | * @param int $siteId 409 | * @return void 410 | */ 411 | public function setDeploymentFailureEmails($serverId, $siteId, array $data) 412 | { 413 | $this->post("servers/$serverId/sites/$siteId/deployment-failure-emails", $data); 414 | } 415 | 416 | /** 417 | * Install a new WordPress project. 418 | * 419 | * @param int $serverId 420 | * @param int $siteId 421 | * @return void 422 | */ 423 | public function installWordPress($serverId, $siteId, array $data) 424 | { 425 | $this->post("servers/$serverId/sites/$siteId/wordpress", $data); 426 | } 427 | 428 | /** 429 | * Remove the WordPress project installed on the site. 430 | * 431 | * @param int $serverId 432 | * @param int $siteId 433 | * @return void 434 | */ 435 | public function removeWordPress($serverId, $siteId) 436 | { 437 | $this->delete("servers/$serverId/sites/$siteId/wordpress"); 438 | } 439 | 440 | /** 441 | * Install a new phpMyAdmin project. 442 | * 443 | * @param int $serverId 444 | * @param int $siteId 445 | * @return void 446 | */ 447 | public function installPhpMyAdmin($serverId, $siteId, array $data) 448 | { 449 | $this->post("servers/$serverId/sites/$siteId/phpmyadmin", $data); 450 | } 451 | 452 | /** 453 | * Remove phpMyAdmin and revert the site back to a default state. 454 | * 455 | * @param int $serverId 456 | * @param int $siteId 457 | * @return void 458 | */ 459 | public function removePhpMyAdmin($serverId, $siteId) 460 | { 461 | $this->delete("servers/$serverId/sites/$siteId/phpmyadmin"); 462 | } 463 | 464 | /** 465 | * Change the given site's PHP version. 466 | * 467 | * @param int $serverId 468 | * @param int $siteId 469 | * @param string $version 470 | * @return void 471 | */ 472 | public function changeSitePHPVersion($serverId, $siteId, $version) 473 | { 474 | $this->put("servers/$serverId/sites/$siteId/php", ['version' => $version]); 475 | } 476 | 477 | /** 478 | * Update the given site's balanced nodes. 479 | * 480 | * @param int $serverId 481 | * @param int $siteId 482 | * @return void 483 | */ 484 | public function updateNodeBalancingConfiguration($serverId, $siteId, array $data) 485 | { 486 | $this->put("servers/$serverId/sites/$siteId/balancing", $data); 487 | } 488 | 489 | /** 490 | * Get the given site's log. 491 | * 492 | * @param int $serverId 493 | * @param int $siteId 494 | * @return string 495 | */ 496 | public function siteLog($serverId, $siteId) 497 | { 498 | return $this->get("servers/$serverId/sites/$siteId/logs"); 499 | } 500 | 501 | /** 502 | * Remove the given site's log when the log formatting is single. 503 | * 504 | * @param int $serverId 505 | * @param int $siteId 506 | * @return void 507 | */ 508 | public function deleteSiteLog($serverId, $siteId) 509 | { 510 | return $this->delete("servers/$serverId/sites/$siteId/logs"); 511 | } 512 | } 513 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Forge SDK 2 | 3 | Build Status 4 | Total Downloads 5 | Latest Stable Version 6 | License 7 | 8 | ## Introduction 9 | 10 | The [Laravel Forge](https://forge.laravel.com) SDK provides an expressive interface for interacting with Forge's API and managing Laravel Forge servers. 11 | 12 | ## Official Documentation 13 | 14 | ### Installation 15 | 16 | To install the SDK in your project you need to require the package via composer: 17 | 18 | ```bash 19 | composer require laravel/forge-sdk 20 | ``` 21 | 22 | ### Upgrading 23 | 24 | When upgrading to a new major version of Forge SDK, it's important that you carefully review [the upgrade guide](https://github.com/laravel/forge-sdk/blob/master/UPGRADE.md). 25 | 26 | ### Basic Usage 27 | 28 | You can create an instance of the SDK like so: 29 | 30 | ```php 31 | $forge = new Laravel\Forge\Forge(TOKEN_HERE); 32 | ``` 33 | 34 | Using the `Forge` instance you may perform multiple actions as well as retrieve the different resources Forge's API provides: 35 | 36 | ```php 37 | $servers = $forge->servers(); 38 | ``` 39 | 40 | This will give you an array of servers that you have access to, where each server is represented by an instance of `Laravel\Forge\Resources\Server`, this instance has multiple public properties like `$name`, `$id`, `$size`, `$region`, and others. 41 | 42 | You may also retrieve a single server using: 43 | 44 | ```php 45 | $server = $forge->server(SERVER_ID_HERE); 46 | ``` 47 | 48 | On multiple actions supported by this SDK you may need to pass some parameters, for example when creating a new server: 49 | 50 | ```php 51 | $server = $forge->createServer([ 52 | "provider"=> ServerProviders::DIGITAL_OCEAN, 53 | "credential_id"=> 1, 54 | "name"=> "test-via-api", 55 | "type"=> ServerTypes::APP, 56 | "size"=> "01", 57 | "database"=> "test123", 58 | "database_type" => InstallableServices::POSTGRES, 59 | "php_version"=> InstallableServices::PHP_85, 60 | "region"=> "ams2" 61 | ]); 62 | ``` 63 | 64 | These parameters will be used in the POST request sent to Forge servers, you can find more information about the parameters needed for each action on 65 | [Forge's official API documentation](https://forge.laravel.com/api-documentation). 66 | 67 | Notice that this request for example will only start the server creation process, your server might need a few minutes before it completes provisioning, you'll need to check the server's `$isReady` property to know if it's ready or not yet. 68 | 69 | Some SDK methods however wait for the action to complete on Forge's end, we do this by periodically contacting Forge servers and checking if our action has completed, for example: 70 | 71 | ```php 72 | $forge->createSite(SERVER_ID, [SITE_PARAMETERS]); 73 | ``` 74 | 75 | This method will ping Forge servers every 5 seconds and see if the newly created Site's status is `installed` and only return when it's so, in case the waiting exceeded 30 seconds a `Laravel\Forge\Exceptions\TimeoutException` will be thrown. 76 | 77 | You can easily stop this behaviour by setting the `$wait` argument to false: 78 | 79 | ```php 80 | $forge->createSite(SERVER_ID, [SITE_PARAMETERS], false); 81 | ``` 82 | 83 | You can also set the desired timeout value: 84 | 85 | ```php 86 | $forge->setTimeout(120)->createSite(SERVER_ID, [SITE_PARAMETERS]); 87 | ``` 88 | 89 | ### Authenticated User 90 | 91 | ```php 92 | $forge->user(); 93 | ``` 94 | 95 | ### Managing Servers 96 | 97 | ```php 98 | $forge->servers(); 99 | $forge->server($serverId); 100 | $forge->createServer(array $data); 101 | $forge->updateServer($serverId, array $data); 102 | $forge->deleteServer($serverId); 103 | $forge->rebootServer($serverId); 104 | 105 | // Server access 106 | $forge->revokeAccessToServer($serverId); 107 | $forge->reconnectToServer($serverId); 108 | $forge->reactivateToServer($serverId); 109 | ``` 110 | 111 | On a `Server` instance you may also call: 112 | 113 | ```php 114 | $server->update(array $data); 115 | $server->delete(); 116 | $server->reboot(); 117 | $server->revokeAccess(); 118 | $server->reconnect(); 119 | $server->reactivate(); 120 | $server->rebootMysql(); 121 | $server->stopMysql(); 122 | $server->rebootPostgres(); 123 | $server->stopPostgres(); 124 | $server->rebootNginx(); 125 | $server->stopNginx(); 126 | $server->installBlackfire(array $data); 127 | $server->removeBlackfire(); 128 | $server->installPapertrail(array $data); 129 | $server->removePapertrail(); 130 | $server->enableOPCache(); 131 | $server->disableOPCache(); 132 | $server->phpVersions(); 133 | $server->installPHP($version); 134 | $server->updatePHP($version); 135 | ``` 136 | 137 | ### Server SSH Keys 138 | 139 | ```php 140 | $forge->keys($serverId); 141 | $forge->sshKey($serverId, $keyId); 142 | $forge->createSSHKey($serverId, array $data, $wait = true); 143 | $forge->deleteSSHKey($serverId, $keyId); 144 | ``` 145 | 146 | On a `SSHKey` instance you may also call: 147 | 148 | ```php 149 | $sshKey->delete(); 150 | ``` 151 | 152 | ### Server Scheduled Jobs 153 | 154 | ```php 155 | $forge->jobs($serverId); 156 | $forge->job($serverId, $jobId); 157 | $forge->createJob($serverId, array $data, $wait = true); 158 | $forge->deleteJob($serverId, $jobId); 159 | ``` 160 | 161 | On a `Job` instance you may also call: 162 | 163 | ```php 164 | $job->delete(); 165 | ``` 166 | 167 | ### Server Events 168 | 169 | ```php 170 | $forge->events(); 171 | $forge->events($serverId); 172 | ``` 173 | 174 | ### Managing Services 175 | 176 | ```php 177 | // MySQL 178 | $forge->rebootMysql($serverId); 179 | $forge->stopMysql($serverId); 180 | 181 | // Postgres 182 | $forge->rebootPostgres($serverId); 183 | $forge->stopPostgres($serverId); 184 | 185 | // Nginx 186 | $forge->rebootNginx($serverId); 187 | $forge->stopNginx($serverId); 188 | $forge->siteNginxFile($serverId, $siteId); 189 | $forge->updateSiteNginxFile($serverId, $siteId, $content); 190 | 191 | // Blackfire 192 | $forge->installBlackfire($serverId, array $data); 193 | $forge->removeBlackfire($serverId); 194 | 195 | // Papertrail 196 | $forge->installPapertrail($serverId, array $data); 197 | $forge->removePapertrail($serverId); 198 | 199 | // OPCache 200 | $forge->enableOPCache($serverId); 201 | $forge->disableOPCache($serverId); 202 | ``` 203 | 204 | ### Server Daemons 205 | 206 | ```php 207 | $forge->daemons($serverId); 208 | $forge->daemon($serverId, $daemonId); 209 | $forge->createDaemon($serverId, array $data, $wait = true); 210 | $forge->restartDaemon($serverId, $daemonId, $wait = true); 211 | $forge->deleteDaemon($serverId, $daemonId); 212 | ``` 213 | 214 | On a `Daemon` instance you may also call: 215 | 216 | ```php 217 | $daemon->restart($wait = true); 218 | $daemon->delete(); 219 | ``` 220 | 221 | ### Server Firewall Rules 222 | 223 | ```php 224 | $forge->firewallRules($serverId); 225 | $forge->firewallRule($serverId, $ruleId); 226 | $forge->createFirewallRule($serverId, array $data, $wait = true); 227 | $forge->deleteFirewallRule($serverId, $ruleId); 228 | ``` 229 | 230 | On a `FirewallRule` instance you may also call: 231 | 232 | ```php 233 | $rule->delete(); 234 | ``` 235 | 236 | ### Managing Sites 237 | 238 | ```php 239 | $forge->sites($serverId); 240 | $forge->site($serverId, $siteId); 241 | $forge->createSite($serverId, array $data, $wait = true); 242 | $forge->updateSite($serverId, $siteId, array $data); 243 | $forge->refreshSiteToken($serverId, $siteId); 244 | $forge->deleteSite($serverId, $siteId); 245 | 246 | // Add Site Aliases 247 | $forge->addSiteAliases($serverId, $siteId, array $aliases); 248 | 249 | // Environment File 250 | $forge->siteEnvironmentFile($serverId, $siteId); 251 | $forge->updateSiteEnvironmentFile($serverId, $siteId, $content); 252 | 253 | // Site Repositories and Deployments 254 | $forge->installGitRepositoryOnSite($serverId, $siteId, array $data, $wait = false); 255 | $forge->updateSiteGitRepository($serverId, $siteId, array $data); 256 | $forge->destroySiteGitRepository($serverId, $siteId, $wait = false); 257 | $forge->createSiteDeployKey($serverId, $siteId); 258 | $forge->destroySiteDeployKey($serverId, $siteId); 259 | $forge->siteDeploymentScript($serverId, $siteId); 260 | $forge->updateSiteDeploymentScript($serverId, $siteId, $content); 261 | $forge->enableQuickDeploy($serverId, $siteId); 262 | $forge->disableQuickDeploy($serverId, $siteId); 263 | $forge->deploySite($serverId, $siteId, $wait = false); 264 | $forge->resetDeploymentState($serverId, $siteId); 265 | $forge->siteDeploymentLog($serverId, $siteId); 266 | $forge->deploymentHistory($serverId, $siteId); 267 | $forge->deploymentHistoryDeployment($serverId, $siteId, $deploymentId); 268 | $forge->deploymentHistoryOutput($serverId, $siteId, $deploymentId); 269 | 270 | // PHP Version 271 | $forge->changeSitePHPVersion($serverId, $siteId, $version); 272 | 273 | // Installing Wordpress 274 | $forge->installWordPress($serverId, $siteId, array $data); 275 | $forge->removeWordPress($serverId, $siteId); 276 | 277 | // Installing phpMyAdmin 278 | $forge->installPhpMyAdmin($serverId, $siteId, array $data); 279 | $forge->removePhpMyAdmin($serverId, $siteId); 280 | 281 | // Updating Node balancing Configuration 282 | $forge->updateNodeBalancingConfiguration($serverId, $siteId, array $data); 283 | ``` 284 | 285 | On a `Site` instance you may also call: 286 | 287 | ```php 288 | $site->refreshToken(); 289 | $site->delete(); 290 | $site->installGitRepository(array $data, $wait = false); 291 | $site->updateGitRepository(array $data); 292 | $site->destroyGitRepository($wait = false); 293 | $site->createDeployKey(); 294 | $site->destroyDeployKey(); 295 | $site->getDeploymentScript(); 296 | $site->updateDeploymentScript($content); 297 | $site->enableQuickDeploy(); 298 | $site->disableQuickDeploy(); 299 | $site->deploySite($wait = false); 300 | $site->resetDeploymentState(); 301 | $site->siteDeploymentLog(); 302 | $site->getDeploymentHistory(); 303 | $site->getDeploymentHistoryDeployment($deploymentId); 304 | $site->getDeploymentHistoryOutput($deploymentId); 305 | $site->installWordPress($data); 306 | $site->removeWordPress(); 307 | $site->installPhpMyAdmin($data); 308 | $site->removePhpMyAdmin(); 309 | $site->changePHPVersion($version); 310 | $site->siteLog(); 311 | $site->deleteSiteLog(); 312 | ``` 313 | 314 | ### Site Workers 315 | 316 | ```php 317 | $forge->workers($serverId, $siteId); 318 | $forge->worker($serverId, $siteId, $workerId); 319 | $forge->createWorker($serverId, $siteId, array $data, $wait = true); 320 | $forge->deleteWorker($serverId, $siteId, $workerId); 321 | $forge->restartWorker($serverId, $siteId, $workerId, $wait = true); 322 | ``` 323 | 324 | On a `Worker` instance you may also call: 325 | 326 | ```php 327 | $worker->delete(); 328 | $worker->restart($wait = true); 329 | ``` 330 | 331 | ### Security Rules 332 | 333 | ```php 334 | $forge->securityRules($serverId, $siteId); 335 | $forge->securityRule($serverId, $siteId, $ruleId); 336 | $forge->createSecurityRule($serverId, $siteId, array $data); 337 | $forge->deleteSecurityRule($serverId, $siteId, $ruleId); 338 | ``` 339 | 340 | On a `SecurityRule` instance you may also call: 341 | 342 | ```php 343 | $securityRule->delete(); 344 | ``` 345 | 346 | ### Site Webhooks 347 | 348 | ```php 349 | $forge->webhooks($serverId, $siteId); 350 | $forge->webhook($serverId, $siteId, $webhookId); 351 | $forge->createWebhook($serverId, $siteId, array $data); 352 | $forge->deleteWebhook($serverId, $siteId, $webhookId); 353 | ``` 354 | 355 | On a `Webhook` instance you may also call: 356 | 357 | ```php 358 | $webhook->delete(); 359 | ``` 360 | 361 | ### Site Commands 362 | 363 | ```php 364 | $forge->executeSiteCommand($serverId, $siteId, array $data); 365 | $forge->listCommandHistory($serverId, $siteId); 366 | $forge->getSiteCommand($serverId, $siteId, $commandId); 367 | ``` 368 | 369 | ### Site SSL Certificates 370 | 371 | ```php 372 | $forge->certificates($serverId, $siteId); 373 | $forge->certificate($serverId, $siteId, $certificateId); 374 | $forge->createCertificate($serverId, $siteId, array $data, $wait = true); 375 | $forge->deleteCertificate($serverId, $siteId, $certificateId); 376 | $forge->getCertificateSigningRequest($serverId, $siteId, $certificateId); 377 | $forge->installCertificate($serverId, $siteId, $certificateId, array $data, $wait = true); 378 | $forge->activateCertificate($serverId, $siteId, $certificateId, $wait = true); 379 | $forge->obtainLetsEncryptCertificate($serverId, $siteId, $data, $wait = true); 380 | ``` 381 | 382 | On a `Certificate` instance you may also call: 383 | 384 | ```php 385 | $certificate->delete(); 386 | $certificate->getSigningRequest(); 387 | $certificate->install($wait = true); 388 | $certificate->activate($wait = true); 389 | ``` 390 | ### Nginx Templates 391 | 392 | ```php 393 | $forge->nginxTemplates($serverId); 394 | $forge->nginxDefaultTemplate($serverId); 395 | $forge->nginxTemplate($serverId, $templateId); 396 | $forge->createNginxTemplate($serverId, array $data); 397 | $forge->updateNginxTemplate($serverId, $templateId, array $data); 398 | $forge->deleteNginxTemplate($serverId, $templateId); 399 | ``` 400 | 401 | On a `NginxTemplate` instance you may also call: 402 | 403 | ```php 404 | $nginxTemplate->update(array $data); 405 | $nginxTemplate->delete(); 406 | ``` 407 | 408 | ### Managing Databases 409 | 410 | ```php 411 | $forge->databases($serverId); 412 | $forge->database($serverId, $databaseId); 413 | $forge->createDatabase($serverId, array $data, $wait = true); 414 | $forge->updateDatabase($serverId, $databaseId, array $data); 415 | $forge->deleteDatabase($serverId, $databaseId); 416 | $forge->syncDatabases($serverId); 417 | 418 | // Users 419 | $forge->databaseUsers($serverId); 420 | $forge->databaseUser($serverId, $userId); 421 | $forge->createDatabaseUser($serverId, array $data, $wait = true); 422 | $forge->updateDatabaseUser($serverId, $userId, array $data); 423 | $forge->deleteDatabaseUser($serverId, $userId); 424 | ``` 425 | 426 | On a `Database` instance you may also call: 427 | 428 | ```php 429 | $database->update(array $data); 430 | $database->delete(); 431 | ``` 432 | 433 | On a `DatabaseUser` instance you may also call: 434 | 435 | ```php 436 | $databaseUser->update(array $data); 437 | $databaseUser->delete(); 438 | ``` 439 | 440 | ### Managing Recipes 441 | 442 | ```php 443 | $forge->recipes(); 444 | $forge->recipe($recipeId); 445 | $forge->createRecipe(array $data); 446 | $forge->updateRecipe($recipeId, array $data); 447 | $forge->deleteRecipe($recipeId); 448 | $forge->runRecipe($recipeId, array $data); 449 | ``` 450 | 451 | On a `Recipe` instance you may also call: 452 | 453 | ```php 454 | $recipe->update(array $data); 455 | $recipe->delete(); 456 | $recipe->run(array $data); 457 | ``` 458 | 459 | ### Managing Backups 460 | 461 | ```php 462 | $forge->backupConfigurations($serverId); 463 | $forge->createBackupConfiguration($serverId, array $data); 464 | $forge->updateBackupConfiguration($serverId, $backupConfigurationId, array $data); 465 | $forge->backupConfiguration($serverId, $backupConfigurationId); 466 | $forge->deleteBackupConfiguration($serverId, $backupConfigurationId); 467 | $forge->restoreBackup($serverId, $backupConfigurationId, $backupId); 468 | $forge->deleteBackup($serverId, $backupConfigurationId, $backupId); 469 | ``` 470 | 471 | On a `BackupConfiguration` instance you may also call: 472 | 473 | ```php 474 | $extendedConfig = $backupConfig->get(); // Load the databases also 475 | $backupConfig->update(array $data); 476 | $backupConfig->delete(); 477 | $backupConfig->restoreBackup($backupId); 478 | $backupConfig->deleteBackup($backupId); 479 | ``` 480 | 481 | On a `Backup` instance you may also call: 482 | 483 | ```php 484 | $backupConfig->delete(); 485 | $backupConfig->restore(); 486 | ``` 487 | 488 | ### Managing Redirects 489 | 490 | ```php 491 | $forge->redirectRules($serverId, $siteId); 492 | $forge->redirectRule($serverId, $siteId, $ruleId); 493 | $forge->createRedirectRule($serverId, $siteId, array $data, $wait = true); 494 | $forge->deleteRedirectRule($serverId, $siteId, $ruleId); 495 | ``` 496 | 497 | On a `RedirectRule` instance you may also call: 498 | 499 | ```php 500 | $redirectRule->delete(); 501 | ``` 502 | 503 | ## Contributing 504 | 505 | Thank you for considering contributing to Forge SDK! You can read the contribution guide [here](.github/CONTRIBUTING.md). 506 | 507 | ## Code of Conduct 508 | 509 | In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). 510 | 511 | ## Security Vulnerabilities 512 | 513 | Please review [our security policy](https://github.com/laravel/forge-sdk/security/policy) on how to report security vulnerabilities. 514 | 515 | ## License 516 | 517 | Laravel Forge SDK is open-sourced software licensed under the [MIT license](LICENSE.md). 518 | --------------------------------------------------------------------------------