├── .github └── workflows │ └── php_test.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── phpstan-ignore.php ├── phpstan.neon ├── phpunit.xml ├── src └── Ploi │ ├── Exceptions │ ├── Http │ │ ├── InternalServerError.php │ │ ├── NotAllowed.php │ │ ├── NotFound.php │ │ ├── NotValid.php │ │ ├── PerformingMaintenance.php │ │ ├── TooManyAttempts.php │ │ └── Unauthenticated.php │ └── Resource │ │ ├── RequiresId.php │ │ └── Server │ │ └── Service │ │ └── RequiresServiceName.php │ ├── Http │ └── Response.php │ ├── Ploi.php │ ├── Resources │ ├── Alias.php │ ├── App.php │ ├── AuthUser.php │ ├── Certificate.php │ ├── Cronjob.php │ ├── Daemon.php │ ├── Database.php │ ├── DatabaseBackup.php │ ├── DatabaseUser.php │ ├── Deployment.php │ ├── Environment.php │ ├── FastCgi.php │ ├── FileBackup.php │ ├── Incident.php │ ├── Insight.php │ ├── LoadBalancer.php │ ├── Monitors.php │ ├── NetworkRule.php │ ├── NginxConfiguration.php │ ├── Opcache.php │ ├── Project.php │ ├── Queue.php │ ├── Redirect.php │ ├── Repository.php │ ├── Resource.php │ ├── Robot.php │ ├── Script.php │ ├── Server.php │ ├── Service.php │ ├── Site.php │ ├── SshKey.php │ ├── StatusPage.php │ ├── Synchronize.php │ ├── SystemUser.php │ ├── Tenant.php │ ├── User.php │ └── WebserverTemplate.php │ └── Traits │ ├── HasHistory.php │ ├── HasPagination.php │ └── HasSearch.php └── tests ├── .env.sample ├── BaseTest.php └── Ploi ├── PloiTest.php ├── Resources ├── AliasTest.php ├── ServerTest.php ├── SiteTest.php └── SshKeyTest.php └── Traits └── HistoryTest.php /.github/workflows/php_test.yml: -------------------------------------------------------------------------------- 1 | name: PHP Composer 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | strategy: 12 | fail-fast: false 13 | matrix: 14 | php: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ] 15 | 16 | name: PHP ${{ matrix.php }} 17 | steps: 18 | - name: Checkout code 19 | uses: actions/checkout@v2 20 | 21 | - name: Setup PHP 22 | uses: shivammathur/setup-php@v2 23 | with: 24 | php-version: ${{ matrix.php }} 25 | 26 | - name: Validate composer.json and composer.lock 27 | run: composer validate --strict 28 | 29 | - name: Install dependencies 30 | run: composer install --prefer-dist --no-progress 31 | 32 | - name: Run linter 33 | run: vendor/bin/phpstan analyse -c phpstan.neon 34 | 35 | #- name: Run test suite 36 | # env: 37 | # API_TOKEN: ${{ secrets.TEST_API_KEY }} 38 | # run: composer test 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | vendor 3 | composer.lock 4 | .env 5 | .phpunit.result.cache 6 | .prettierignore 7 | .DS_Store 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Config file for https://travis-ci.org/ 2 | # Validate this file here - http://lint.travis-ci.org/ 3 | 4 | language: php 5 | 6 | # Define the php versions against we want to test our code 7 | php: 8 | - 7.3 9 | - 7.4 10 | - 8.0 11 | 12 | # Note: Code coverage requires php-xDebug extension enabled on CI server 13 | 14 | install: 15 | # Install composer packages 16 | - travis_retry composer install --no-interaction --no-suggest 17 | # Install coveralls.phar 18 | - wget -c -nc --retry-connrefused --tries=0 https://github.com/php-coveralls/php-coveralls/releases/download/v2.0.0/php-coveralls.phar -O coveralls.phar 19 | - chmod +x coveralls.phar 20 | - php coveralls.phar --version 21 | 22 | # Create a storage folder for coverage report 23 | before_script: 24 | - mkdir -p build/logs 25 | - cp tests/.env.sample tests/.env 26 | 27 | # Testing the app (see phpunit.xml) for configs, generating Code Coverage report 28 | script: 29 | - ./vendor/bin/phpcs --standard=PSR2 src 30 | - ./vendor/bin/phpunit --coverage-clover build/logs/clover.xml 31 | 32 | #after_script: 33 | after_success: 34 | # Submit coverage report to Coveralls servers, see .coveralls.yml 35 | - travis_retry php coveralls.phar -v 36 | # Submit coverage report to codecov.io 37 | - bash <(curl -s https://codecov.io/bash) 38 | 39 | #after_failure: 40 | 41 | # Tell Travis CI to monitor only 'master' branch 42 | branches: 43 | only: master 44 | 45 | # You can delete the cache using travis-ci web interface 46 | cache: 47 | directories: 48 | - vendor 49 | - $HOME/.cache/composer 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2022 Ploi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ploi PHP SDK :rocket: 2 | 3 | The future is now - so stop the hassle, you’re running behind. Quick and easy site deployment with Ploi. Awesome features for awesome developers. Check it out at https://ploi.io 4 | 5 | This SDK is meant for PHP applications to be able to communicate with our API. 6 | You can find our documentation at https://developers.ploi.io 7 | 8 | ## Installation 9 | 10 | ```bash 11 | composer require ploi/ploi-php-sdk 12 | ``` 13 | 14 | ## Usage 15 | 16 | First you need to call a new Ploi instance 17 | 18 | ```php 19 | $ploi = new \Ploi\Ploi($apiToken); 20 | // or 21 | $ploi = new \Ploi\Ploi(); 22 | $ploi->setApiToken($token); 23 | ``` 24 | 25 | ### Responses 26 | When calling a resource, it will return a `Ploi\Http\Response` object containing decoded JSON as well as the original response from the Guzzle client. 27 | 28 | You can also only retrieve the JSON, use the `getJson()` method to only get the JSON back: 29 | 30 | `$ploi->user()->get()->getJson()` 31 | 32 | However, when you want to only get the data, use the `getData()` method: 33 | 34 | `$ploi->user()->get()->getData()` 35 | 36 | ### Resources 37 | 38 | Resources are what you call to access a feature or function. 39 | 40 | You can get all the resources or get a specific one by its ID, for example with servers: 41 | ```php 42 | // List servers 43 | $ploi->servers()->get(); 44 | 45 | // Get a specific server with ID 123 46 | $ploi->servers(123)->get(); 47 | // or 48 | $ploi->servers()->get(123); 49 | ``` 50 | 51 | Some actions will require the resource's ID to be set before they can be used: 52 | ```php 53 | // Throws Ploi\Exceptions\Resource\RequiresId 54 | $ploi->servers()->delete(); 55 | 56 | // Will attempt to delete server by ID 57 | $ploi->servers()->delete(123); 58 | // or 59 | $ploi->servers(123)->delete(); 60 | ``` 61 | 62 | ### Servers 63 | 64 | You create a new server by: 65 | ```php 66 | $ploi->servers()->create( 67 | $serverName, 68 | $providerId, 69 | $region, 70 | $plan, 71 | $options = [] 72 | ); 73 | ``` 74 | 75 | Or you can create a custom server with a provider not set up in Ploi 76 | ```php 77 | $ploi->servers()->createCustom($ip, $options); 78 | ``` 79 | After running this request, you will have to add the public key of the Ploi worker to your server. 80 | This is included in the response with a 1-line command within the `ssh_command` key. 81 | Once this is done, you can trigger the URL from the response with the `start_installation_url` key or by passing in the server ID. 82 | 83 | ```php 84 | $ploi->servers()->startInstallation($installationUrl); 85 | // or 86 | $ploi->servers(123)->startInstallation(); 87 | ``` 88 | 89 | Other methods for servers: 90 | ```php 91 | // Get server list 92 | $ploi->servers()->get(); 93 | 94 | // Paginate servers 95 | $ploi->servers()->perPage($amountPerPage)->page($pageNumber); 96 | // or 97 | $ploi->servers()->page($pageNumber, $amountPerPage); 98 | 99 | // Get server 100 | $ploi->servers(123)->get(); 101 | 102 | // Delete server 103 | $ploi->servers(123)->delete(); 104 | 105 | // Get server logs 106 | $ploi->servers(123)->logs(); 107 | 108 | // Restart server 109 | $ploi->servers(123)->restart(); 110 | 111 | // Get server monitoring 112 | $ploi->servers(123)->monitoring(); 113 | 114 | // Get PHP versions installed on server 115 | $ploi->servers(123)->phpVersions(); 116 | 117 | // Enable opcache 118 | $ploi->servers(123)->opcache()->enable(); 119 | 120 | // Disable opcache 121 | $ploi->servers(123)->opcache()->disable(); 122 | 123 | // Refresh opcache 124 | $ploi->servers(123)->opcache()->refresh(); 125 | ``` 126 | 127 | ### Sites 128 | 129 | Available methods for sites: 130 | ```php 131 | //Create site 132 | $ploi->servers(123)->sites()->create( 133 | $domain, 134 | $webDirectory = '/public', 135 | $projectDirectory = '/', 136 | $systemUser = 'ploi', 137 | $systemUserPassword = null, 138 | $webserverTemplate = null, 139 | $projectType = null 140 | ); 141 | 142 | // List sites 143 | $ploi->servers(123)->sites()->get(); 144 | 145 | // Paginate sites 146 | $ploi->servers(123)->sites()->perPage(15)->page(1); 147 | 148 | // Get site 149 | $ploi->servers(123)->sites(123)->get(); 150 | 151 | // Delete site 152 | $ploi->servers(123)->sites(123)->delete(); 153 | 154 | // Update site 155 | $ploi->servers(123)->sites(123)->update($rootDomain); 156 | 157 | // Get site logs 158 | $ploi->servers(123)->sites(123)->logs(); 159 | 160 | // Set PHP version for site to use 161 | $ploi->servers(123)->sites(123)->phpVersion($phpVersion); 162 | 163 | // Enable test domain on site 164 | $ploi->servers(123)->sites(123)->enableTestDomain(); 165 | // Disable test domain on site 166 | $ploi->servers(123)->sites(123)->disableTestDomain(); 167 | // Get test domain details for site 168 | $ploi->servers(123)->sites(123)->testDomain(); 169 | 170 | // Suspend site 171 | $ploi->servers(123)->sites(123)->suspend($id = null, $reason = null); 172 | // Resume site 173 | $ploi->servers(123)->sites(123)->resume(); 174 | 175 | // Get Laravel Horizon statistics 176 | $ploi->servers(123)->sites(123)->horizonStatistics($type); 177 | ``` 178 | 179 | ### Databases 180 | 181 | Available methods for databases: 182 | ```php 183 | // Create database 184 | $ploi->servers(123)->databases()->create( 185 | $databaseName, 186 | $databaseUser, 187 | $databaseUserPassword, 188 | $description = null, 189 | $siteId = null 190 | ); 191 | 192 | // List databases 193 | $ploi->servers(123)->databases()->get(); 194 | 195 | // Paginate databases 196 | $ploi->servers(123)->databases()->perPage($amountPerPage)->page($pageNumber); 197 | 198 | // Get database 199 | $ploi->servers(123)->databases(123)->get(); 200 | 201 | // Delete database 202 | $ploi->servers(123)->databases(123)->delete(); 203 | 204 | // Acknowledge database 205 | $ploi->servers(123)->databases()->acknowledge($databaseName); 206 | 207 | // Forget database 208 | $ploi->servers(123)->databases(123)->forget(); 209 | 210 | // Duplicate database 211 | $ploi->servers(123)->databases(123)->duplicate($name, $user = null, $password = null); 212 | ``` 213 | 214 | ### Database Backups 215 | 216 | Available methods for database backups: 217 | ```php 218 | // Create database backup 219 | $ploi->servers(123)->databases(123)->backups()->create( 220 | $interval, 221 | $type, 222 | $table_exclusions = null, 223 | $locations = null, 224 | $path = null 225 | ); 226 | 227 | // List database backups 228 | $ploi->servers(123)->databases(123)->backups()->get(); 229 | 230 | // Paginate database backups 231 | $ploi->servers(123)->databases(123)->backups()->perPage($amountPerPage)->page($pageNumber); 232 | 233 | // Get database backup 234 | $ploi->servers(123)->databases(123)->backups(123)->get(); 235 | 236 | // Delete database backup 237 | $ploi->servers(123)->databases(123)->backups(123)->delete(); 238 | 239 | // Toggle database backup 240 | $ploi->servers(123)->databases(123)->backups(123)->toggle(); 241 | ``` 242 | 243 | ### File Backups 244 | 245 | Available methods for file backups: 246 | ```php 247 | // List site file backups 248 | $ploi->fileBackups()->get(); 249 | 250 | // Paginate file backups 251 | $ploi->fileBackups()->perPage($amountPerPage)->page($pageNumber); 252 | 253 | // Get specific file backup 254 | $ploi->fileBackups(123)->get(); 255 | 256 | // Create file backup 257 | $ploi->fileBackups()->create( 258 | $backup_configuration, 259 | $server, 260 | $sites, 261 | $interval, 262 | $path, 263 | $locations = null, 264 | $keep_backup_amount = null, 265 | $custom_name = null, 266 | $password = null 267 | ); 268 | 269 | // Run file backup 270 | $ploi->fileBackups(123)->run(); 271 | 272 | // Delete file backup 273 | $ploi->fileBackups(123)->delete(); 274 | ``` 275 | 276 | ### Database Users 277 | 278 | Available methods for database users: 279 | ```php 280 | // Create database user 281 | $ploi->servers(123)->databases(123)->users()->create( 282 | $user, 283 | $password, 284 | ); 285 | 286 | // List database users 287 | $ploi->servers(123)->databases(123)->users()->get(); 288 | 289 | // Paginate database users 290 | $ploi->servers(123)->databases(123)->users()->perPage($amountPerPage)->page($pageNumber); 291 | 292 | // Get database user 293 | $ploi->servers(123)->databases(123)->users(123)->get(); 294 | 295 | // Delete database user 296 | $ploi->servers(123)->databases(123)->users(123)->delete(); 297 | ``` 298 | 299 | ### Cronjobs 300 | 301 | Available methods for cronjobs: 302 | ```php 303 | // Create cronjob 304 | $ploi->servers(123)->cronjobs()->create( 305 | $command, 306 | $frequency, 307 | $user = 'ploi' 308 | ); 309 | 310 | // List cronjobs 311 | $ploi->servers(123)->cronjobs()->get(); 312 | 313 | // Paginate cronjobs 314 | $ploi->servers(123)->cronjobs()->perPage($amountPerPage)->page($pageNumber); 315 | 316 | // Get cronjob 317 | $ploi->servers(123)->cronjobs(123)->get(); 318 | 319 | // Delete cronjob 320 | $ploi->servers(123)->cronjobs(123)->delete(); 321 | ``` 322 | 323 | ### Network Rules 324 | 325 | Available methods for network rules: 326 | ```php 327 | // Create network rule 328 | $ploi->servers(123)->networkRules()->create( 329 | $name, 330 | $port, 331 | $type = 'tcp', 332 | $fromIpAddress = null, 333 | $ruleType = 'allow' 334 | ); 335 | 336 | // List network rules 337 | $ploi->servers(123)->networkRules()->get(); 338 | 339 | // Paginate network rules 340 | $ploi->servers(123)->networkRules()->perPage($amountPerPage)->page($pageNumber); 341 | 342 | // Get network rule 343 | $ploi->servers(123)->networkRules(123)->get(); 344 | 345 | // Delete network rule 346 | $ploi->servers(123)->networkRules(123)->delete(); 347 | ``` 348 | 349 | ### Queues 350 | 351 | Available methods for queues: 352 | ```php 353 | // Create queue 354 | $ploi->servers(123)->sites(123)->queues()->create( 355 | $connection = 'database', 356 | $queue = 'default', 357 | $maximumSeconds = 60, 358 | $sleep = 30, 359 | $processes = 1, 360 | $maximumTries = 1 361 | ); 362 | 363 | // List queues 364 | $ploi->servers(123)->sites(123)->queues()->get(); 365 | 366 | // Paginate queues 367 | $ploi->servers(123)->sites(123)->queues()->perPage($amountPerPage)->page($pageNumber); 368 | 369 | // Get queue 370 | $ploi->servers(123)->sites(123)->queues(123)->get(); 371 | 372 | // Delete queue 373 | $ploi->servers(123)->sites(123)->queues(123)->delete(); 374 | 375 | // Pause queue 376 | $ploi->servers(123)->sites(123)->queues(123)->pause(); 377 | 378 | // Restart queue 379 | $ploi->servers(123)->sites(123)->queues(123)->restart(); 380 | ``` 381 | 382 | ### Certificates 383 | 384 | Available methods for certificates: 385 | ```php 386 | // Create certificate 387 | $ploi->servers(123)->sites(123)->certificates()->create( 388 | $certificate, 389 | $type = 'letsencrypt' 390 | ); 391 | 392 | // List certificates 393 | $ploi->servers(123)->sites(123)->certificates()->get(); 394 | 395 | // Paginate certificates 396 | $ploi->servers(123)->sites(123)->certificates()->perPage($amountPerPage)->page($pageNumber); 397 | 398 | // Get certificate 399 | $ploi->servers(123)->sites(123)->certificates(123)->get(); 400 | 401 | // Delete certificate 402 | $ploi->servers(123)->sites(123)->certificates(123)->delete(); 403 | ``` 404 | 405 | ### NGINX Configuration 406 | 407 | Available methods for NGINX configuration: 408 | ```php 409 | // Get NGINX configuration 410 | $ploi->servers(123)->sites(123)->nginxConfiguration()->get(); 411 | 412 | // Update NGINX configuration 413 | $ploi->servers(123)->sites(123)->nginxConfiguration()->update($configuration); 414 | ``` 415 | 416 | ### Load Balancers 417 | 418 | Available methods for load balancers 419 | ```php 420 | // Request certificate 421 | $ploi->servers(123)->loadBalancer()->requestCertificate($domain); 422 | 423 | // Revoke certificate 424 | $ploi->servers(123)->loadBalancer()->revokeCertificate($domain); 425 | 426 | ``` 427 | 428 | ### Auth Users 429 | 430 | Available methods for auth users: 431 | ```php 432 | // Create auth user 433 | $ploi->servers(123)->sites(123)->authUser()->create( 434 | $name, 435 | $password 436 | ); 437 | 438 | // List auth users 439 | $ploi->servers(123)->sites(123)->authUser()->get(); 440 | 441 | // Paginate auth users 442 | $ploi->servers(123)->sites(123)->authUser()->perPage($amountPerPage)->page($pageNumber); 443 | 444 | // Get auth user 445 | $ploi->servers(123)->sites(123)->authUser(123)->get(); 446 | 447 | // Delete auth user 448 | $ploi->servers(123)->sites(123)->authUser(123)->delete(); 449 | ``` 450 | 451 | ### Deployments 452 | 453 | Available methods for deployments 454 | ```php 455 | // Get default deploy script 456 | $ploi->servers(123)->sites(123)->deployment()->deployScript(); 457 | 458 | // Update default deploy script 459 | $ploi->servers(123)->sites(123)->deployment()->updateDeployScript($script = ''); 460 | 461 | // Deploy a site 462 | $ploi->servers(123)->sites(123)->deployment()->deploy(); 463 | 464 | // Deploy a staging site to production 465 | $ploi->servers(123)->sites(123)->deployment()->deployToProduction(); 466 | ``` 467 | 468 | ### Environments 469 | 470 | Available methods for environments 471 | ```php 472 | // Get .env for site 473 | $ploi->servers(123)->sites(123)->environment()->get(); 474 | 475 | // Update .env for site 476 | $ploi->servers(123)->sites(123)->environment()->update($content); 477 | ``` 478 | 479 | ### Repositories 480 | 481 | Available methods for repositories: 482 | ```php 483 | // Install repository 484 | $ploi->servers(123)->sites(123)->repository()->install( 485 | $provider, 486 | $branch, 487 | $name 488 | ); 489 | 490 | // Get repository 491 | $ploi->servers(123)->sites(123)->repository()->get(); 492 | 493 | // Delete repository 494 | $ploi->servers(123)->sites(123)->repository()->delete(); 495 | 496 | // Toggle quick deploy on repository 497 | $ploi->servers(123)->sites(123)->repository()->toggleQuickDeploy(); 498 | ``` 499 | 500 | ### Redirects 501 | 502 | ```php 503 | // Create redirect 504 | $ploi->servers(123)->sites(123)->redirects()->create( 505 | $redirectFrom, 506 | $redirectTo, 507 | $type = 'redirect' 508 | ); 509 | 510 | // List redirects 511 | $ploi->servers(123)->sites(123)->redirects()->get(); 512 | 513 | // Paginate redirects 514 | $ploi->servers(123)->sites(123)->redirects()->perPage($amountPerPage)->page($pageNumber); 515 | 516 | // Get redirect 517 | $ploi->servers(123)->sites(123)->redirects(123)->get(); 518 | 519 | // Delete redirect 520 | $ploi->servers(123)->sites(123)->redirects(123)->delete(); 521 | ``` 522 | 523 | ### Aliases 524 | 525 | ```php 526 | // Create aliases 527 | $ploi->servers(123)->sites(123)->aliases()->create($aliases); 528 | 529 | // List aliases 530 | $ploi->servers(123)->sites(123)->aliases()->get(); 531 | 532 | // Delete alias 533 | $ploi->servers(123)->sites(123)->aliases()->delete($alias); 534 | ``` 535 | 536 | ### FastCGI Cache 537 | 538 | ```php 539 | // Enable FastCGI cache 540 | $ploi->servers(123)->sites(123)->fastCgi()->enable(); 541 | 542 | // Disable FastCGI cache 543 | $ploi->servers(123)->sites(123)->fastCgi()->disable(); 544 | 545 | // Flush FastCGI cache 546 | $ploi->servers(123)->sites(123)->fastCgi()->flush(); 547 | ``` 548 | 549 | ### Tenants 550 | 551 | ```php 552 | // Create tenant 553 | $ploi->servers(123)->sites(123)->tenants()->create($tenants); 554 | 555 | // List tenants 556 | $ploi->servers(123)->sites(123)->tenants()->get(); 557 | 558 | // Delete tenant 559 | $ploi->servers(123)->sites(123)->tenants()->delete($tenant); 560 | 561 | // Request tenant certificate 562 | $ploi->servers(123)->sites(123)->tenants()->requestCertificate($tenant); 563 | 564 | // Revoke tenant certificate 565 | $ploi->servers(123)->sites(123)->tenants()->revokeCertificate($tenant); 566 | ``` 567 | 568 | ### Robot Access 569 | 570 | ```php 571 | // Allow robot access 572 | $ploi->servers(123)->sites(123)->robots()->allow(); 573 | 574 | // Block robot access 575 | $ploi->servers(123)->sites(123)->robots()->block(); 576 | ``` 577 | 578 | ### Monitors 579 | 580 | ```php 581 | // List monitors 582 | $ploi->servers(123)->sites(123)->monitors()->get(); 583 | 584 | // Paginate monitors 585 | $ploi->servers(123)->sites(123)->monitors()->perPage($amountPerPage)->page($pageNumber); 586 | 587 | // Get specific monitor 588 | $ploi->servers(123)->sites(123)->monitors(123)->get(); 589 | 590 | // Get uptime responses 591 | $ploi->servers(123)->sites(123)->monitors(123)->uptimeResponses(); 592 | ``` 593 | 594 | ### Scripts 595 | 596 | Available methods for scripts: 597 | ```php 598 | // Create script 599 | $ploi->scripts()->create($label, $user, $content); 600 | 601 | // List scripts 602 | $ploi->scripts()->get(); 603 | 604 | // Paginate scripts 605 | $ploi->scripts()->perPage($amountPerPage)->page($pageNumber); 606 | 607 | // Get script 608 | $ploi->scripts(123)->get(); 609 | 610 | // Delete script 611 | $ploi->scripts(123)->delete(); 612 | 613 | // Run script 614 | $ploi->scripts(123)->run($id = null, $serverIds = []); 615 | ``` 616 | 617 | ### Daemons 618 | 619 | Available methods for daemons: 620 | ```php 621 | // Create daemon 622 | $ploi->servers(123)->daemons()->create( 623 | $command, 624 | $systemUser, 625 | $processes, 626 | $directory = null 627 | ); 628 | 629 | // List daemons 630 | $ploi->servers(123)->daemons()->get(); 631 | 632 | // Paginate daemons 633 | $ploi->servers(123)->daemons()->perPage($amountPerPage)->page($pageNumber); 634 | 635 | // Get daemon 636 | $ploi->servers(123)->daemons(123)->get(); 637 | 638 | // Delete daemon 639 | $ploi->servers(123)->daemons(123)->delete(); 640 | 641 | // Pause daemon 642 | $ploi->servers(123)->daemons(123)->pause(); 643 | 644 | // Restart daemon 645 | $ploi->servers(123)->daemons(123)->restart(); 646 | ``` 647 | 648 | ### Services 649 | ```php 650 | // Restart service 651 | $ploi->servers(123)->services($name)->restart(); 652 | ``` 653 | 654 | ### System Users 655 | 656 | Available methods for system users: 657 | ```php 658 | // Create system user 659 | $ploi->servers(123)->systemUsers()->create( 660 | $name, 661 | $sudo = false 662 | ); 663 | 664 | // List system users 665 | $ploi->servers(123)->systemUsers()->get(); 666 | 667 | // Paginate system users 668 | $ploi->servers(123)->systemUsers()->perPage($amountPerPage)->page($pageNumber); 669 | 670 | // Get system users 671 | $ploi->servers(123)->systemUsers(123)->get(); 672 | 673 | // Delete system user 674 | $ploi->servers(123)->systemUsers(123)->delete(); 675 | ``` 676 | 677 | ### SSH Keys 678 | 679 | Available methods for SSH keys: 680 | ```php 681 | // Create SSH key 682 | $ploi->servers(123)->sshKeys()->create( 683 | $name = 'ssh key name', 684 | $key = 'ssh key here', 685 | $systemUser = 'ploi' 686 | ); 687 | 688 | // List SSH keys 689 | $ploi->servers(123)->sshKeys()->get(); 690 | 691 | // Paginate SSH keys 692 | $ploi->servers(123)->sshKeys()->perPage($amountPerPage)->page($pageNumber); 693 | 694 | // Get SSH key 695 | $ploi->servers(123)->sshKeys(123)->get(); 696 | 697 | // Delete SSH key 698 | $ploi->servers(123)->sshKeys(123)->delete(); 699 | ``` 700 | 701 | ### Insights 702 | ```php 703 | // List insights 704 | $ploi->servers(123)->insights()->get(); 705 | 706 | // Paginate insights 707 | $ploi->servers(123)->insights()->perPage($amountPerPage)->page($pageNumber); 708 | 709 | // Get insight 710 | $ploi->servers(123)->insights(123)->get(); 711 | 712 | // Get insight detail 713 | $ploi->servers(123)->insights(123)->detail(); 714 | 715 | // Automatically fix insight 716 | $ploi->servers(123)->insights(123)->automaticallyFix(); 717 | 718 | // Ignore insight 719 | $ploi->servers(123)->insights(123)->ignore(); 720 | 721 | // Delete insight 722 | $ploi->servers(123)->insights(123)->delete(); 723 | ``` 724 | 725 | ### User 726 | 727 | Available methods for user: 728 | ```php 729 | // Get own user information 730 | $ploi->user()->get(); 731 | 732 | // List server providers 733 | $ploi->user()->serverProviders(); 734 | 735 | // Get server providers 736 | $ploi->user()->serverProviders($providerId); 737 | ``` 738 | 739 | ### Status Pages 740 | 741 | Available methods for status pages: 742 | ```php 743 | // List status pages 744 | $ploi->statusPage()->get(); 745 | 746 | // Paginate status pages 747 | $ploi->statusPage()->perPage($amountPerPage)->page($pageNumber); 748 | 749 | // Get status page 750 | $ploi->statusPage(123)->get(); 751 | ``` 752 | 753 | ### Status Page Incidents 754 | 755 | Available methods for status page incidents: 756 | ```php 757 | // Create incident 758 | $ploi->statusPage(123)->incident()->create( 759 | $title, 760 | $description, 761 | $severity 762 | ); 763 | 764 | // List incidents 765 | $ploi->statusPage(123)->incident()->get(); 766 | 767 | // Paginate incidents 768 | $ploi->statusPage(123)->incident()->perPage($amountPerPage)->page($pageNumber); 769 | 770 | // Delete incident 771 | $ploi->statusPage(123)->incident(123)->delete(); 772 | ``` 773 | 774 | ### Webserver Templates 775 | 776 | Available methods for webserver templates: 777 | ```php 778 | // List webserver templates 779 | $ploi->webserverTemplates()->get(); 780 | 781 | // Paginate webserver templates 782 | $ploi->webserverTemplates()->perPage($amountPerPage)->page($pageNumber); 783 | 784 | // Get webserver template 785 | $ploi->webserverTemplates(123)->get(); 786 | ``` 787 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ploi/ploi-php-sdk", 3 | "description": "Ploi.io for easy site deployments", 4 | "authors": [ 5 | { 6 | "name": "Dennis Smink", 7 | "email": "info@ploi.io" 8 | }, 9 | { 10 | "name": "Simon White", 11 | "email": "simondotwhite@gmail.com" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=7.3", 16 | "ext-json": "*", 17 | "guzzlehttp/guzzle": "^7.0.1" 18 | }, 19 | "require-dev": { 20 | "squizlabs/php_codesniffer": "3.*", 21 | "psy/psysh": "@stable", 22 | "phpunit/phpunit": "^9", 23 | "vlucas/phpdotenv": "^5.2", 24 | "phpstan/phpstan": "^1.12 || ^2.1" 25 | }, 26 | "license": "MIT", 27 | "minimum-stability": "stable", 28 | "autoload": { 29 | "psr-0": { 30 | "Ploi": "src/" 31 | } 32 | }, 33 | "autoload-dev": { 34 | "psr-0": { 35 | "Ploi": "src/" 36 | }, 37 | "psr-4": { 38 | "Tests\\": "tests/" 39 | } 40 | }, 41 | "scripts": { 42 | "standards": "./vendor/bin/phpcs --standard=PSR2 --colors src", 43 | "test": "./vendor/bin/phpunit tests" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /phpstan-ignore.php: -------------------------------------------------------------------------------- 1 | = 80400) { 6 | $config['parameters']['ignoreErrors'] = [['identifier' => 'parameter.implicitlyNullable']]; 7 | } 8 | 9 | return $config; 10 | -------------------------------------------------------------------------------- /phpstan.neon: -------------------------------------------------------------------------------- 1 | includes: 2 | - phpstan-ignore.php 3 | parameters: 4 | level: 5 5 | paths: 6 | - src 7 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | src/ 17 | 18 | 19 | 20 | 21 | tests 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Ploi/Exceptions/Http/InternalServerError.php: -------------------------------------------------------------------------------- 1 | setResponse($response); 33 | $this->decodeJson(); 34 | } 35 | 36 | /** 37 | * Sets the Response from the Guzzle Client 38 | * 39 | * @param ResponseInterface $response 40 | * @return self 41 | */ 42 | private function setResponse(ResponseInterface $response): self 43 | { 44 | $this->response = $response; 45 | 46 | return $this; 47 | } 48 | 49 | /** 50 | * Returns the Response from the Guzzle Client 51 | * 52 | * @return ResponseInterface 53 | */ 54 | public function getResponse(): ResponseInterface 55 | { 56 | return $this->response; 57 | } 58 | 59 | /** 60 | * Recodes the body from the response 61 | * 62 | * @return self 63 | */ 64 | private function decodeJson(): self 65 | { 66 | $json = json_decode($this->getResponse()->getBody()); 67 | 68 | return $this->setJson($json); 69 | } 70 | 71 | /** 72 | * Sets the decoded JSON 73 | * 74 | * @param stdClass|null $json 75 | * @return self 76 | */ 77 | public function setJson(?stdClass $json = null): self 78 | { 79 | $this->json = $json; 80 | 81 | return $this; 82 | } 83 | 84 | /** 85 | * Gets the decoded json 86 | * 87 | * @return null|stdClass 88 | */ 89 | public function getJson(): ?stdClass 90 | { 91 | return $this->json; 92 | } 93 | 94 | /** 95 | * Gets the 'data' key from the json object 96 | * 97 | * @return null|stdClass|array 98 | */ 99 | public function getData() 100 | { 101 | return $this->getJson()->data ?? $this->getJson(); 102 | } 103 | 104 | /** 105 | * Returns the JSON and Response as an array 106 | * 107 | * @return array{json: ?stdClass, response: ResponseInterface} 108 | */ 109 | public function toArray(): array 110 | { 111 | return [ 112 | 'json' => $this->getJson(), 113 | 'response' => $this->getResponse(), 114 | ]; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/Ploi/Ploi.php: -------------------------------------------------------------------------------- 1 | setApiToken($token); 61 | } 62 | } 63 | 64 | /** 65 | * @param string $token 66 | * @return self 67 | */ 68 | public function setApiToken($token): self 69 | { 70 | // Set the token 71 | $this->apiToken = $token; 72 | 73 | // Generate a new Guzzle client 74 | $this->guzzle = new Client([ 75 | 'base_uri' => $this->url, 76 | 'http_errors' => false, 77 | 'headers' => [ 78 | 'Authorization' => 'Bearer ' . $this->getApiToken(), 79 | 'Accept' => 'application/json', 80 | 'Content-Type' => 'application/json', 81 | ], 82 | ]); 83 | 84 | return $this; 85 | } 86 | 87 | /** 88 | * Returns the API Token 89 | * 90 | * @return string 91 | */ 92 | public function getApiToken(): string 93 | { 94 | return $this->apiToken; 95 | } 96 | 97 | /** 98 | * @param string $url 99 | * @param string $method 100 | * @param array $options 101 | * @return Response 102 | * @throws NotFound 103 | * @throws NotAllowed 104 | * @throws TooManyAttempts 105 | * @throws PerformingMaintenance 106 | * @throws InternalServerError 107 | * @throws NotValid 108 | * @throws Exception 109 | */ 110 | public function makeAPICall(string $url, string $method = 'get', array $options = []): Response 111 | { 112 | if (!in_array($method, ['get', 'post', 'patch', 'delete'])) { 113 | throw new Exception('Invalid method type'); 114 | } 115 | 116 | /** 117 | * Because we're calling the method dynamically PHPStorm doesn't 118 | * know that we're getting a response back, so we manually 119 | * tell it what is returned. 120 | * 121 | * @var ResponseInterface $response 122 | */ 123 | $response = $this->guzzle->{$method}($url, $options); 124 | 125 | switch ($response->getStatusCode()) { 126 | case 401: 127 | throw new Unauthenticated($response->getBody()); 128 | case 404: 129 | throw new NotFound($response->getBody()); 130 | case 405: 131 | throw new NotAllowed($response->getBody()); 132 | case 422: 133 | throw new NotValid($response->getBody()); 134 | case 429: 135 | throw new TooManyAttempts($response->getBody()); 136 | case 500: 137 | throw new InternalServerError($response->getBody()); 138 | case 503: 139 | throw new PerformingMaintenance($response->getBody()); 140 | } 141 | 142 | return new Response($response); 143 | } 144 | 145 | /** 146 | * Returns a server resource 147 | * 148 | * @param int|null $id 149 | * @return Server 150 | */ 151 | public function server(?int $id = null): Server 152 | { 153 | return new Server($this, $id); 154 | } 155 | 156 | public function servers(?int $id = null): Server 157 | { 158 | return $this->server($id); 159 | } 160 | 161 | public function project(?int $id = null): Project 162 | { 163 | return new Project($this, $id); 164 | } 165 | 166 | public function projects(?int $id = null): Project 167 | { 168 | return $this->project($id); 169 | } 170 | 171 | public function scripts(?int $id = null): Script 172 | { 173 | return new Script($this, $id); 174 | } 175 | 176 | public function statusPage(?int $id = null): StatusPage 177 | { 178 | return new StatusPage($this, $id); 179 | } 180 | 181 | public function user(): User 182 | { 183 | return new User($this); 184 | } 185 | 186 | public function webserverTemplates(?int $id = null): WebserverTemplate 187 | { 188 | return new WebserverTemplate($this, $id); 189 | } 190 | 191 | /** 192 | * Returns a file backup resource 193 | * 194 | * @param int|null $id 195 | * @return FileBackup 196 | */ 197 | public function fileBackup(?int $id = null): FileBackup 198 | { 199 | return new FileBackup($this, $id); 200 | } 201 | 202 | /** 203 | * Returns a file backup resource 204 | * 205 | * @param int|null $id 206 | * @return FileBackup 207 | */ 208 | public function fileBackups(?int $id = null): FileBackup 209 | { 210 | return $this->fileBackup($id); 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Alias.php: -------------------------------------------------------------------------------- 1 | getPloi()); 14 | 15 | $this->setServer($server); 16 | $this->setSite($site); 17 | 18 | $this->buildEndpoint(); 19 | } 20 | 21 | public function buildEndpoint(): self 22 | { 23 | $this->setEndpoint($this->getSite()->getEndpoint() . '/aliases'); 24 | 25 | return $this; 26 | } 27 | 28 | public function get(): Response 29 | { 30 | return $this->getPloi()->makeAPICall($this->getEndpoint()); 31 | } 32 | 33 | public function create(array $aliases): Response 34 | { 35 | $options = [ 36 | 'body' => json_encode([ 37 | 'aliases' => $aliases, 38 | ]), 39 | ]; 40 | 41 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 42 | } 43 | 44 | public function delete(string $alias): Response 45 | { 46 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/' . $alias , 'delete'); 47 | } 48 | } -------------------------------------------------------------------------------- /src/Ploi/Resources/App.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 13 | 14 | $this->setServer($server); 15 | $this->setSite($site); 16 | 17 | $this->buildEndpoint(); 18 | } 19 | 20 | public function buildEndpoint(): self 21 | { 22 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/sites/' . $this->getSite()->getId()); 23 | 24 | if ($this->getId()) { 25 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 26 | } 27 | 28 | return $this; 29 | } 30 | 31 | public function get(?int $id = null) 32 | { 33 | if ($id) { 34 | $this->setId($id); 35 | } 36 | 37 | // Make sure the endpoint is built 38 | $this->buildEndpoint(); 39 | 40 | return $this->getPloi()->makeAPICall($this->getEndpoint()); 41 | } 42 | 43 | public function install(string $type = 'wordpress', array $options = []): stdClass 44 | { 45 | // Remove the id 46 | $this->setId(null); 47 | 48 | // Set the options 49 | $options = [ 50 | 'body' => json_encode([ 51 | 'create_database' => $options['create_database'] ?? false 52 | ]), 53 | ]; 54 | 55 | try { 56 | $response = $this->getPloi()->makeAPICall($this->getEndpoint() . '/' . $type, 'post', $options); 57 | } catch (NotValid $exception) { 58 | return json_decode($exception->getMessage()); 59 | } 60 | 61 | // Set the id of the site 62 | $this->setId($response->getJson()->data->id); 63 | 64 | // Return the data 65 | return $response->getJson()->data; 66 | } 67 | 68 | public function uninstall($type): bool 69 | { 70 | $this->buildEndpoint(); 71 | 72 | $response = $this->getPloi()->makeAPICall($this->getEndpoint() . '/' . $type, 'delete'); 73 | 74 | return $response->getResponse()->getStatusCode() === 200; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Ploi/Resources/AuthUser.php: -------------------------------------------------------------------------------- 1 | getPloi()); 15 | 16 | $this->setServer($server); 17 | $this->setSite($site); 18 | 19 | if ($id) { 20 | $this->setId($id); 21 | } 22 | 23 | $this->buildEndpoint(); 24 | } 25 | 26 | public function buildEndpoint(): self 27 | { 28 | $endpoint = $this->getSite()->getEndpoint() . '/auth-users'; 29 | 30 | if ($this->getId()) { 31 | $endpoint .= '/' . $this->getId(); 32 | } 33 | 34 | $this->setEndpoint($endpoint); 35 | 36 | return $this; 37 | } 38 | 39 | public function get(?int $id = null): Response 40 | { 41 | if ($id) { 42 | $this->setId($id); 43 | } 44 | 45 | $this->buildEndpoint(); 46 | 47 | return (is_null($this->getId())) 48 | ? $this->page() 49 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 50 | } 51 | 52 | public function create(string $name, string $password): Response 53 | { 54 | $options = [ 55 | 'body' => json_encode([ 56 | 'name' => $name, 57 | 'password' => $password, 58 | ]), 59 | ]; 60 | 61 | $this->buildEndpoint(); 62 | 63 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 64 | } 65 | 66 | public function delete(?int $id = null): Response 67 | { 68 | $this->setIdOrFail($id); 69 | 70 | $this->buildEndpoint(); 71 | 72 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 73 | } 74 | 75 | } -------------------------------------------------------------------------------- /src/Ploi/Resources/Certificate.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 15 | 16 | $this->setServer($server); 17 | $this->setSite($site); 18 | 19 | $this->buildEndpoint(); 20 | } 21 | 22 | public function buildEndpoint(): self 23 | { 24 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/sites/' . $this->getSite()->getId() . '/certificates'); 25 | 26 | if ($this->getId()) { 27 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 28 | } 29 | 30 | return $this; 31 | } 32 | 33 | public function get(?int $id = null): Response 34 | { 35 | if ($id) { 36 | $this->setId($id); 37 | } 38 | 39 | // Make sure the endpoint is built 40 | $this->buildEndpoint(); 41 | 42 | return (is_null($this->getId())) 43 | ? $this->page() 44 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 45 | } 46 | 47 | public function create(string $certificate, string $type = 'letsencrypt', bool $force = false): Response 48 | { 49 | // Remove the id 50 | $this->setId(null); 51 | 52 | // Set the options 53 | $options = [ 54 | 'body' => json_encode([ 55 | 'certificate' => $certificate, 56 | 'type' => $type, 57 | 'force' => $force, 58 | ]), 59 | ]; 60 | 61 | // Build the endpoint 62 | $this->buildEndpoint(); 63 | 64 | $response = $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 65 | 66 | $this->setId($response->getJson()->data->id); 67 | 68 | // Return the response 69 | return $response; 70 | } 71 | 72 | public function delete(?int $id = null): Response 73 | { 74 | $this->setIdOrFail($id); 75 | 76 | $this->buildEndpoint(); 77 | 78 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Cronjob.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 15 | 16 | $this->setServer($server); 17 | 18 | $this->buildEndpoint(); 19 | } 20 | 21 | public function buildEndpoint(): self 22 | { 23 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/crontabs'); 24 | 25 | if ($this->getId()) { 26 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 27 | } 28 | 29 | return $this; 30 | } 31 | 32 | public function get(?int $id = null): Response 33 | { 34 | if ($id) { 35 | $this->setId($id); 36 | } 37 | 38 | // Make sure the endpoint is built 39 | $this->buildEndpoint(); 40 | 41 | return (is_null($this->getId())) 42 | ? $this->page() 43 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 44 | } 45 | 46 | public function create(string $command, string $frequency, string $user = 'ploi'): Response 47 | { 48 | // Remove the id 49 | $this->setId(null); 50 | 51 | // Set the options 52 | $options = [ 53 | 'body' => json_encode([ 54 | 'command' => $command, 55 | 'frequency' => $frequency, 56 | 'user' => $user, 57 | ]), 58 | ]; 59 | 60 | // Build the endpoint 61 | $this->buildEndpoint(); 62 | 63 | // Make the request 64 | $response = $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 65 | 66 | // Set the id of the cronjob 67 | $this->setId($response->getJson()->data->id); 68 | 69 | // Return the data 70 | return $response; 71 | } 72 | 73 | public function delete(?int $id = null): Response 74 | { 75 | if ($id) { 76 | $this->setId($id); 77 | } 78 | 79 | $this->buildEndpoint(); 80 | 81 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Daemon.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 15 | 16 | $this->setServer($server); 17 | 18 | $this->buildEndpoint(); 19 | } 20 | 21 | public function buildEndpoint(): self 22 | { 23 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/daemons'); 24 | 25 | if ($this->getId()) { 26 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 27 | } 28 | 29 | return $this; 30 | } 31 | 32 | public function get(?int $id = null): Response 33 | { 34 | if ($id) { 35 | $this->setId($id); 36 | } 37 | 38 | // Make sure the endpoint is built 39 | $this->buildEndpoint(); 40 | 41 | return (is_null($this->getId())) 42 | ? $this->page() 43 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 44 | } 45 | 46 | public function create(string $command, string $systemUser, int $processes, ?string $directory = null): Response 47 | { 48 | // Remove the id 49 | $this->setId(null); 50 | 51 | // Set the options 52 | $options = [ 53 | 'body' => json_encode([ 54 | 'command' => $command, 55 | 'system_user' => $systemUser, 56 | 'processes' => $processes, 57 | 'directory' => $directory, 58 | ]), 59 | ]; 60 | 61 | // Build the endpoint 62 | $this->buildEndpoint(); 63 | 64 | // Make the request 65 | $response = $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 66 | 67 | $this->setId($response->getJson()->data->id); 68 | 69 | // Return the data 70 | return $response; 71 | } 72 | 73 | public function restart(?int $id = null): Response 74 | { 75 | $this->setIdOrFail($id); 76 | 77 | // Build the endpoint 78 | $this->buildEndpoint(); 79 | 80 | $this->setEndpoint($this->getEndpoint() . '/restart'); 81 | 82 | // Make the request 83 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post'); 84 | } 85 | 86 | public function pause(?int $id = null): Response 87 | { 88 | $this->setIdOrFail($id); 89 | 90 | // Build the endpoint 91 | $this->buildEndpoint(); 92 | 93 | $this->setEndpoint($this->getEndpoint() . '/toggle-pause'); 94 | 95 | // Make the request 96 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post'); 97 | } 98 | 99 | public function delete(?int $id = null): Response 100 | { 101 | // Remove the id 102 | $this->setIdOrFail($id); 103 | 104 | // Build the endpoint 105 | $this->buildEndpoint(); 106 | 107 | // Make the request 108 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Database.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 15 | 16 | $this->setServer($server); 17 | 18 | $this->buildEndpoint(); 19 | } 20 | 21 | public function buildEndpoint(): self 22 | { 23 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/databases'); 24 | 25 | if ($this->getId()) { 26 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 27 | } 28 | 29 | if ($this->getAction()) { 30 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getAction()); 31 | } 32 | 33 | return $this; 34 | } 35 | 36 | public function get(?int $id = null): Response 37 | { 38 | if ($id) { 39 | $this->setId($id); 40 | } 41 | 42 | // Make sure the endpoint is built 43 | $this->buildEndpoint(); 44 | 45 | return (is_null($this->getId())) 46 | ? $this->page() 47 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 48 | } 49 | 50 | public function create(string $name, string $user, string $password, $description = null, $siteId = null): Response 51 | { 52 | // Remove the id 53 | $this->setId(null); 54 | 55 | // Set the options 56 | $options = [ 57 | 'body' => json_encode([ 58 | 'name' => $name, 59 | 'user' => $user, 60 | 'password' => $password, 61 | 'description' => $description, 62 | 'site_id' => $siteId, 63 | ]), 64 | ]; 65 | 66 | // Build the endpoint 67 | $this->buildEndpoint(); 68 | 69 | // Make the request 70 | $response = $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 71 | 72 | // Set the id of the site 73 | $this->setId($response->getJson()->data->id); 74 | 75 | // Return the data 76 | return $response; 77 | } 78 | 79 | public function delete(?int $id = null): Response 80 | { 81 | if ($id) { 82 | $this->setId($id); 83 | } 84 | 85 | $this->buildEndpoint(); 86 | 87 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 88 | } 89 | 90 | public function acknowledge(string $name): Response 91 | { 92 | // Remove the id 93 | $this->setId(null); 94 | 95 | // Set the action 96 | $this->setAction('acknowledge'); 97 | 98 | // Set the options 99 | $options = [ 100 | 'body' => json_encode([ 101 | 'name' => $name, 102 | ]), 103 | ]; 104 | 105 | // Build the endpoint 106 | $this->buildEndpoint(); 107 | 108 | // Make the request 109 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 110 | } 111 | 112 | public function forget(?int $id = null): Response 113 | { 114 | if ($id) { 115 | $this->setId($id); 116 | } 117 | 118 | // Set the action 119 | $this->setAction('forget'); 120 | 121 | $this->buildEndpoint(); 122 | 123 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 124 | } 125 | 126 | public function duplicate(string $name, ?string $user = null, ?string $password = null): Response 127 | { 128 | $this->setIdOrFail(); 129 | 130 | $options = [ 131 | 'body' => json_encode([ 132 | 'name' => $name, 133 | 'user' => $user, 134 | 'password' => $password, 135 | ]), 136 | ]; 137 | 138 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/duplicate', 'post', $options); 139 | } 140 | 141 | public function backups($id = null): DatabaseBackup 142 | { 143 | return new DatabaseBackup($this->getServer(),$this,$id); 144 | } 145 | 146 | public function users(?int $id = null): DatabaseUser 147 | { 148 | return new DatabaseUser($this->getServer(), $this, $id); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/Ploi/Resources/DatabaseBackup.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 16 | 17 | $this->setServer($server); 18 | 19 | $this->setDatabase($database); 20 | 21 | $this->buildEndpoint(); 22 | } 23 | 24 | public function buildEndpoint(): self 25 | { 26 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/databases/' . $this->getDatabase()->getId() . '/backups'); 27 | 28 | if ($this->getId()) { 29 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 30 | } 31 | 32 | if ($this->getAction()) { 33 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getAction()); 34 | } 35 | 36 | return $this; 37 | } 38 | 39 | public function get(?int $id = null): Response 40 | { 41 | if ($id) { 42 | $this->setId($id); 43 | } 44 | 45 | // Make sure the endpoint is built 46 | $this->buildEndpoint(); 47 | 48 | return (is_null($this->getId())) 49 | ? $this->page() 50 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 51 | } 52 | 53 | public function create( 54 | int $interval, 55 | string $type, 56 | ?string $table_exclusions = null, 57 | ?string $locations = null, 58 | ?string $path = null 59 | ): Response 60 | { 61 | // Remove the id 62 | $this->setId(null); 63 | 64 | // Set the options 65 | $options = [ 66 | 'body' => json_encode([ 67 | 'interval' => $interval, 68 | 'type' => $type, 69 | 'table_exclusions' => $table_exclusions, 70 | 'locations' => $locations, 71 | 'path' => $path 72 | ]), 73 | ]; 74 | 75 | $this->buildEndpoint(); 76 | 77 | // Make the request 78 | $response = $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 79 | 80 | $this->setId($response->getJson()->data->id); 81 | 82 | // Return the response 83 | return $response; 84 | } 85 | 86 | public function delete(?int $id = null): Response 87 | { 88 | $this->setIdOrFail($id); 89 | 90 | $this->buildEndpoint(); 91 | 92 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 93 | } 94 | 95 | public function toggle(?int $id = null): Response 96 | { 97 | $this->setIdOrFail($id); 98 | 99 | $this->buildEndpoint(); 100 | 101 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/toggle', 'patch'); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/Ploi/Resources/DatabaseUser.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 16 | 17 | $this->setDatabase($database); 18 | 19 | $this->buildEndpoint(); 20 | } 21 | 22 | public function buildEndpoint(): self 23 | { 24 | $this->setEndpoint($this->getDatabase()->getEndpoint() . '/users'); 25 | 26 | if ($this->getId()) { 27 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 28 | } 29 | 30 | return $this; 31 | } 32 | 33 | public function get(?int $id = null): Response 34 | { 35 | if ($id) { 36 | $this->setId($id); 37 | } 38 | 39 | $this->buildEndpoint(); 40 | 41 | return (is_null($this->getId())) 42 | ? $this->page() 43 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 44 | } 45 | 46 | public function create(string $user, string $password, bool $remote = false, string $remoteIp = '%', bool $readOnly = false): Response 47 | { 48 | $this->setId(null); 49 | 50 | $options = [ 51 | 'body' => json_encode([ 52 | 'user' => $user, 53 | 'password' => $password, 54 | 'remote' => $remote, 55 | 'remote_ip' => $remoteIp, 56 | 'readonly' => $readOnly 57 | ]), 58 | ]; 59 | 60 | $this->buildEndpoint(); 61 | 62 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 63 | } 64 | 65 | public function delete(?int $id = null): Response 66 | { 67 | $this->setIdOrFail($id); 68 | 69 | $this->buildEndpoint(); 70 | 71 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Deployment.php: -------------------------------------------------------------------------------- 1 | getPloi()); 12 | 13 | $this->setServer($server); 14 | $this->setSite($site); 15 | 16 | $this->buildEndpoint(); 17 | } 18 | 19 | public function buildEndpoint(): self 20 | { 21 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/sites/' . $this->getSite()->getId()); 22 | 23 | return $this; 24 | } 25 | 26 | public function deploy(): Response 27 | { 28 | $this->setEndpoint($this->getEndpoint() . '/deploy'); 29 | 30 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post'); 31 | } 32 | 33 | public function deployToProduction(): Response 34 | { 35 | $this->setEndpoint($this->getEndpoint() . '/deploy-to-production'); 36 | 37 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post'); 38 | } 39 | 40 | public function deployScript(): Response 41 | { 42 | $this->setEndpoint($this->getEndpoint() . '/deploy/script'); 43 | 44 | return $this->getPloi()->makeAPICall($this->getEndpoint()); 45 | } 46 | 47 | public function updateDeployScript($script = ''): Response 48 | { 49 | $options = [ 50 | 'body' => json_encode([ 51 | 'deploy_script' => $script 52 | ]), 53 | ]; 54 | 55 | $this->setEndpoint($this->getEndpoint() . '/deploy/script'); 56 | 57 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'patch', $options); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Environment.php: -------------------------------------------------------------------------------- 1 | getPloi()); 12 | 13 | $this->setServer($server); 14 | $this->setSite($site); 15 | 16 | $this->buildEndpoint(); 17 | } 18 | 19 | public function buildEndpoint(): self 20 | { 21 | $this->setEndpoint( 22 | $this->getServer()->getEndpoint() . 23 | '/' . 24 | $this->getServer()->getId() . 25 | '/sites/' . 26 | $this->getSite()->getId() . 27 | '/env' 28 | ); 29 | 30 | return $this; 31 | } 32 | 33 | public function get(): Response 34 | { 35 | return $this->getPloi()->makeAPICall($this->getEndpoint()); 36 | } 37 | 38 | public function update(string $content): Response 39 | { 40 | // Set the options 41 | $options = [ 42 | 'body' => json_encode([ 43 | 'content' => $content, 44 | ]), 45 | ]; 46 | 47 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'patch', $options); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Ploi/Resources/FastCgi.php: -------------------------------------------------------------------------------- 1 | getPloi()); 12 | 13 | $this->setServer($server); 14 | $this->setSite($site); 15 | 16 | $this->buildEndpoint(); 17 | } 18 | 19 | public function buildEndpoint(): self 20 | { 21 | $this->setEndpoint($this->getSite()->getEndpoint() . '/fastcgi-cache'); 22 | 23 | return $this; 24 | } 25 | 26 | public function enable(): Response 27 | { 28 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/enable', 'post'); 29 | } 30 | 31 | public function disable(): Response 32 | { 33 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/disable', 'delete'); 34 | } 35 | 36 | public function flush(): Response 37 | { 38 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/flush', 'post'); 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /src/Ploi/Resources/FileBackup.php: -------------------------------------------------------------------------------- 1 | buildEndpoint(); 17 | } 18 | 19 | public function buildEndpoint(): self 20 | { 21 | $this->setEndpoint('backups/file'); 22 | 23 | if ($this->getId()) { 24 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 25 | } 26 | 27 | if ($this->getAction()) { 28 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getAction()); 29 | } 30 | 31 | return $this; 32 | } 33 | 34 | /** 35 | * Get all file backups 36 | * 37 | * @param int|null $id 38 | * @return Response 39 | */ 40 | public function get(int $id = null): Response 41 | { 42 | if ($id) { 43 | $this->setId($id); 44 | } 45 | 46 | // Make sure the endpoint is built 47 | $this->buildEndpoint(); 48 | 49 | return (is_null($this->getId())) 50 | ? $this->page() 51 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 52 | } 53 | 54 | /** 55 | * Create a new file backup 56 | * 57 | * @param int $backup_configuration The ID of your backup configuration 58 | * @param int $server The ID of the server 59 | * @param array $sites An array containing the ID's of the sites to back up 60 | * @param int $interval Backup interval (0, 10, 20, 30, 40, 50, 60, 120, 240, 480, 720, 1440) 61 | * @param array $path The paths per site ID to be backed up 62 | * @param string|null $locations Only used for google-drive driver 63 | * @param int|null $keep_backup_amount How many backups should be saved 64 | * @param string|null $custom_name Custom archive name 65 | * @param string|null $password Password for the ZIP archive 66 | * @return Response 67 | */ 68 | public function create( 69 | int $backup_configuration, 70 | int $server, 71 | array $sites, 72 | int $interval, 73 | array $path, 74 | string $locations = null, 75 | int $keep_backup_amount = null, 76 | string $custom_name = null, 77 | string $password = null 78 | ): Response { 79 | // Remove the id 80 | $this->setId(null); 81 | 82 | // Set the options 83 | $options = [ 84 | 'body' => json_encode([ 85 | 'backup_configuration' => $backup_configuration, 86 | 'server' => $server, 87 | 'sites' => $sites, 88 | 'interval' => $interval, 89 | 'path' => $path, 90 | 'locations' => $locations, 91 | 'keep_backup_amount' => $keep_backup_amount, 92 | 'custom_name' => $custom_name, 93 | 'password' => $password 94 | ]), 95 | ]; 96 | 97 | $this->buildEndpoint(); 98 | 99 | // Make the request 100 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 101 | } 102 | 103 | /** 104 | * Run a file backup 105 | * 106 | * @param int|null $id 107 | * @return Response 108 | */ 109 | public function run(int $id = null): Response 110 | { 111 | $this->setIdOrFail($id); 112 | 113 | $this->setAction('run'); 114 | $this->buildEndpoint(); 115 | 116 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post'); 117 | } 118 | 119 | /** 120 | * Delete a file backup 121 | * 122 | * @param int|null $id 123 | * @return Response 124 | */ 125 | public function delete(int $id = null): Response 126 | { 127 | $this->setIdOrFail($id); 128 | 129 | $this->buildEndpoint(); 130 | 131 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Incident.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 17 | 18 | $this->setStatusPage($statusPage); 19 | 20 | $this->buildEndpoint(); 21 | } 22 | 23 | public function setStatusPage(StatusPage $statusPage): self 24 | { 25 | $this->statusPage = $statusPage; 26 | 27 | return $this; 28 | } 29 | 30 | public function getStatusPage(): ?StatusPage 31 | { 32 | return $this->statusPage; 33 | } 34 | 35 | public function buildEndpoint(): self 36 | { 37 | $endpoint = $this->getStatusPage()->getEndpoint() . '/incidents'; 38 | 39 | if ($this->getId()) { 40 | $endpoint .= '/' . $this->getId(); 41 | } 42 | 43 | $this->setEndpoint($endpoint); 44 | 45 | return $this; 46 | } 47 | 48 | public function get(?int $id = null): Response 49 | { 50 | if ($id) { 51 | $this->setId($id); 52 | } 53 | 54 | $this->buildEndpoint(); 55 | 56 | return (is_null($this->getId())) 57 | ? $this->page() 58 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 59 | } 60 | 61 | public function create(string $title, string $description, string $severity): Response 62 | { 63 | 64 | $options = [ 65 | 'body' => json_encode([ 66 | 'title' => $title, 67 | 'description' => $description, 68 | 'severity' => $severity, 69 | ]), 70 | ]; 71 | 72 | $this->buildEndpoint(); 73 | 74 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 75 | } 76 | 77 | public function delete(?int $id = null): Response 78 | { 79 | $this->setIdOrFail($id); 80 | 81 | $this->buildEndpoint(); 82 | 83 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 84 | } 85 | } -------------------------------------------------------------------------------- /src/Ploi/Resources/Insight.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 15 | 16 | $this->setServer($server); 17 | 18 | $this->buildEndpoint(); 19 | } 20 | 21 | public function buildEndpoint(): self 22 | { 23 | $endpoint = $this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/insights'; 24 | 25 | if ($this->getId()) { 26 | $endpoint .= '/' . $this->getId(); 27 | } 28 | 29 | $this->setEndpoint($endpoint); 30 | 31 | return $this; 32 | } 33 | 34 | public function get(?int $id = null): Response 35 | { 36 | if ($id) { 37 | $this->setId($id); 38 | } 39 | 40 | $this->buildEndpoint(); 41 | 42 | return (is_null($this->getId())) 43 | ? $this->page() 44 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 45 | } 46 | 47 | public function detail(?int $id = null): Response 48 | { 49 | $this->setIdOrFail($id); 50 | 51 | $this->buildEndpoint(); 52 | 53 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/detail'); 54 | } 55 | 56 | public function automaticallyFix(?int $id = null): Response 57 | { 58 | $this->setIdOrFail($id); 59 | 60 | $this->buildEndpoint(); 61 | 62 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/automatically-fix', 'post'); 63 | } 64 | 65 | public function ignore(?int $id = null): Response 66 | { 67 | $this->setIdOrFail($id); 68 | 69 | $this->buildEndpoint(); 70 | 71 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/ignore', 'post'); 72 | } 73 | 74 | public function delete(?int $id = null): Response 75 | { 76 | $this->setIdOrFail($id); 77 | 78 | $this->buildEndpoint(); 79 | 80 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 81 | } 82 | } -------------------------------------------------------------------------------- /src/Ploi/Resources/LoadBalancer.php: -------------------------------------------------------------------------------- 1 | getPloi()); 12 | 13 | $this->setServer($server); 14 | 15 | $this->buildEndpoint(); 16 | } 17 | 18 | public function buildEndpoint(): self 19 | { 20 | $this->setEndpoint($this->getServer()->buildEndpoint() . '/load-balancer'); 21 | 22 | return $this; 23 | } 24 | 25 | public function requestCertificate(string $domain): Response 26 | { 27 | $url = $this->getEndpoint() . "/{$domain}/request-certificate"; 28 | return $this->getPloi()->makeAPICall($url, 'post'); 29 | } 30 | 31 | public function revokeCertificate(string $domain): Response 32 | { 33 | $url = $this->getEndpoint() . "/{$domain}/revoke-certificate"; 34 | return $this->getPloi()->makeAPICall($url, 'delete'); 35 | } 36 | } -------------------------------------------------------------------------------- /src/Ploi/Resources/Monitors.php: -------------------------------------------------------------------------------- 1 | getPloi()); 15 | 16 | $this->setSite($site); 17 | 18 | if ($id) { 19 | $this->setId($id); 20 | } 21 | 22 | $this->buildEndpoint(); 23 | } 24 | 25 | public function buildEndpoint(): self 26 | { 27 | $endpoint = $this->getSite()->getEndpoint() . '/monitors'; 28 | 29 | if ($this->getId()) { 30 | $endpoint .= '/' . $this->getId(); 31 | } 32 | 33 | $this->setEndpoint($endpoint); 34 | 35 | return $this; 36 | } 37 | 38 | public function get(?int $id = null): Response 39 | { 40 | if ($id) { 41 | $this->setId($id); 42 | } 43 | 44 | $this->buildEndpoint(); 45 | 46 | return (is_null($this->getId())) 47 | ? $this->page() 48 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 49 | } 50 | 51 | public function uptimeResponses(?int $id = null): Response 52 | { 53 | $this->setIdOrFail($id); 54 | 55 | $this->buildEndpoint(); 56 | 57 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/uptime-responses'); 58 | } 59 | } -------------------------------------------------------------------------------- /src/Ploi/Resources/NetworkRule.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 15 | 16 | $this->setServer($server); 17 | 18 | $this->buildEndpoint(); 19 | } 20 | 21 | public function buildEndpoint(): self 22 | { 23 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/network-rules'); 24 | 25 | if ($this->getId()) { 26 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 27 | } 28 | 29 | return $this; 30 | } 31 | 32 | public function get(?int $id = null): Response 33 | { 34 | if ($id) { 35 | $this->setId($id); 36 | } 37 | 38 | // Make sure the endpoint is built 39 | $this->buildEndpoint(); 40 | 41 | return (is_null($this->getId())) 42 | ? $this->page() 43 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 44 | } 45 | 46 | public function create(string $name, int $port, string $type = 'tcp', ?string $fromIpAddress = null, string $ruleType = 'allow'): Response 47 | { 48 | // Remove the id 49 | $this->setId(null); 50 | 51 | // Set the options 52 | $options = [ 53 | 'body' => json_encode([ 54 | 'name' => $name, 55 | 'port' => $port, 56 | 'type' => $type, 57 | 'rule_type' => $ruleType, 58 | 'from_ip_address' => $fromIpAddress, 59 | ]), 60 | ]; 61 | 62 | // Build the endpoint 63 | $this->buildEndpoint(); 64 | 65 | // Make the request 66 | $response = $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 67 | 68 | $this->setId($response->getJson()->data->id); 69 | 70 | // Return the data 71 | return $response; 72 | } 73 | 74 | public function delete(?int $id = null): Response 75 | { 76 | // Remove the id 77 | $this->setIdOrFail($id); 78 | 79 | // Build the endpoint 80 | $this->buildEndpoint(); 81 | 82 | // Make the request 83 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Ploi/Resources/NginxConfiguration.php: -------------------------------------------------------------------------------- 1 | getPloi()); 12 | 13 | $this->setSite($site); 14 | 15 | $this->buildEndpoint(); 16 | } 17 | 18 | public function buildEndpoint(): self 19 | { 20 | $this->setEndpoint($this->getSite()->getEndpoint() . '/nginx-configuration'); 21 | 22 | return $this; 23 | } 24 | 25 | public function get(): Response 26 | { 27 | return $this->getPloi()->makeAPICall($this->getEndpoint()); 28 | } 29 | 30 | public function update(string $configuration): Response 31 | { 32 | $options = [ 33 | 'body' => json_encode([ 34 | 'content' => $configuration, 35 | ]), 36 | ]; 37 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'patch', $options); 38 | } 39 | } -------------------------------------------------------------------------------- /src/Ploi/Resources/Opcache.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 10 | 11 | $this->setServer($server); 12 | 13 | $this->buildEndpoint(); 14 | } 15 | 16 | public function buildEndpoint(): self 17 | { 18 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId()); 19 | 20 | if ($this->getId()) { 21 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 22 | } 23 | 24 | return $this; 25 | } 26 | 27 | public function refresh() 28 | { 29 | $this->setEndpoint($this->getEndpoint() . '/refresh-opcache'); 30 | 31 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post'); 32 | } 33 | 34 | public function enable() 35 | { 36 | $this->setEndpoint($this->getEndpoint() . '/enable-opcache'); 37 | 38 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post'); 39 | } 40 | 41 | public function disable() 42 | { 43 | $this->setEndpoint($this->getEndpoint() . '/disable-opcache'); 44 | 45 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post'); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Project.php: -------------------------------------------------------------------------------- 1 | setEndpoint($this->endpoint); 20 | } 21 | 22 | public function buildEndpoint(?string $path = null): string 23 | { 24 | $base = $this->endpoint; 25 | 26 | if ($this->getId()) { 27 | $base = "{$base}/{$this->getId()}"; 28 | } 29 | 30 | if (!$path) { 31 | return $base; 32 | } 33 | 34 | if (strpos($path, '/') === 0) { 35 | return $base . $path; 36 | } 37 | 38 | return "{$base}/{$path}"; 39 | } 40 | 41 | public function callApi(?string $path = null, string $method = 'get', array $options = []): Response 42 | { 43 | return $this->getPloi() 44 | ->makeAPICall($this->buildEndpoint($path), $method, $options); 45 | } 46 | 47 | public function get(?int $id = null): Response 48 | { 49 | if ($id) { 50 | $this->setId($id); 51 | } 52 | 53 | // This method do not need the special callApi() method on pagination 54 | // Since its a the simple get of the servers using the $this->endpoint url 55 | 56 | return (is_null($this->getId())) 57 | ? $this->page() 58 | : $this->callApi(); 59 | } 60 | 61 | public function delete(?int $id = null): Response 62 | { 63 | $this->setIdOrFail($id); 64 | 65 | return $this->callApi(null, 'delete'); 66 | } 67 | 68 | public function create( 69 | string $title, 70 | array $servers = [], 71 | array $sites = [], 72 | array $options = [] 73 | ): Response { 74 | 75 | // Remove the id 76 | $this->setId(null); 77 | 78 | $defaults = [ 79 | 'title' => $title, 80 | 'servers' => $servers, 81 | 'sites' => $sites, 82 | ]; 83 | 84 | // Set the options 85 | $options = [ 86 | 'body' => json_encode(array_merge($defaults, $options)), 87 | ]; 88 | 89 | // Make the request 90 | $response = $this->callApi(null, 'post', $options); 91 | 92 | // Set the id of the site 93 | $this->setId($response->getJson()->data->id); 94 | 95 | // Return the response 96 | return $response; 97 | } 98 | 99 | public function update(string $title, array $servers = [], array $sites = []): Response 100 | { 101 | $this->setIdOrFail(); 102 | 103 | $options = [ 104 | 'body' => json_encode([ 105 | 'title' => $title, 106 | 'servers' => $servers, 107 | 'sites' => $sites, 108 | ]), 109 | ]; 110 | 111 | return $this->callApi(null, 'patch', $options); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Queue.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 15 | 16 | $this->setServer($server); 17 | $this->setSite($site); 18 | 19 | $this->buildEndpoint(); 20 | } 21 | 22 | public function buildEndpoint(): self 23 | { 24 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/sites/' . $this->getSite()->getId() . '/queues'); 25 | 26 | if ($this->getId()) { 27 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 28 | } 29 | 30 | return $this; 31 | } 32 | 33 | public function get(?int $id = null): Response 34 | { 35 | if ($id) { 36 | $this->setId($id); 37 | } 38 | 39 | // Make sure the endpoint is built 40 | $this->buildEndpoint(); 41 | 42 | return (is_null($this->getId())) 43 | ? $this->page() 44 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 45 | } 46 | 47 | public function create( 48 | string $connection = 'database', 49 | string $queue = 'default', 50 | int $maximumSeconds = 60, 51 | int $sleep = 30, 52 | int $processes = 1, 53 | int $maximumTries = 1 54 | ): Response { 55 | // Remove the id 56 | $this->setId(null); 57 | 58 | // Set the options 59 | $options = [ 60 | 'body' => json_encode([ 61 | 'connection' => $connection, 62 | 'queue' => $queue, 63 | 'maximum_seconds' => $maximumSeconds, 64 | 'sleep' => $sleep, 65 | 'processes' => $processes, 66 | 'maximum_tries' => $maximumTries 67 | ]), 68 | ]; 69 | 70 | // Build the endpoint 71 | $this->buildEndpoint(); 72 | 73 | // Make the request 74 | $response = $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 75 | 76 | $this->setId($response->getData()->id); 77 | 78 | // Return the data 79 | return $response; 80 | } 81 | 82 | public function restart(?int $id = null): Response 83 | { 84 | $this->setIdOrFail($id); 85 | 86 | // Build the endpoint 87 | $this->buildEndpoint(); 88 | 89 | $this->setEndpoint($this->getEndpoint() . '/restart'); 90 | 91 | // Make the request 92 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post'); 93 | } 94 | 95 | public function pause(?int $id = null): Response 96 | { 97 | $this->setIdOrFail($id); 98 | 99 | // Build the endpoint 100 | $this->buildEndpoint(); 101 | 102 | $this->setEndpoint($this->getEndpoint() . '/toggle-pause'); 103 | 104 | // Make the request 105 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post'); 106 | } 107 | 108 | public function delete(?int $id = null): Response 109 | { 110 | $this->setIdOrFail($id); 111 | 112 | // Build the endpoint 113 | $this->buildEndpoint(); 114 | 115 | // Make the request 116 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Redirect.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 15 | 16 | $this->setServer($server); 17 | $this->setSite($site); 18 | 19 | $this->buildEndpoint(); 20 | } 21 | 22 | public function buildEndpoint(): self 23 | { 24 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/sites/' . $this->getSite()->getId() . '/redirects'); 25 | 26 | if ($this->getId()) { 27 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 28 | } 29 | 30 | return $this; 31 | } 32 | 33 | public function get(?int $id = null): Response 34 | { 35 | if ($id) { 36 | $this->setId($id); 37 | } 38 | 39 | // Make sure the endpoint is built 40 | $this->buildEndpoint(); 41 | 42 | return (is_null($this->getId())) 43 | ? $this->page() 44 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 45 | } 46 | 47 | public function create(string $redirectFrom, string $redirectTo, $type = 'redirect'): Response 48 | { 49 | // Remove the id 50 | $this->setId(null); 51 | 52 | // Set the options 53 | $options = [ 54 | 'body' => json_encode([ 55 | 'redirect_from' => $redirectFrom, 56 | 'redirect_to' => $redirectTo, 57 | 'type' => $type, 58 | ]), 59 | ]; 60 | 61 | // Build the endpoint 62 | $this->buildEndpoint(); 63 | 64 | // Make the request 65 | $response = $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 66 | 67 | // Set the id of the site 68 | $this->setId($response->getJson()->data->id); 69 | 70 | // Return the data 71 | return $response; 72 | } 73 | 74 | public function delete(?int $id = null): Response 75 | { 76 | $this->setIdOrFail($id); 77 | 78 | $this->buildEndpoint(); 79 | 80 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Repository.php: -------------------------------------------------------------------------------- 1 | getPloi()); 12 | 13 | $this->setServer($server); 14 | $this->setSite($site); 15 | 16 | $this->buildEndpoint(); 17 | } 18 | 19 | public function buildEndpoint(): self 20 | { 21 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/sites/' . $this->getSite()->getId() . '/repository'); 22 | 23 | return $this; 24 | } 25 | 26 | public function get(): Response 27 | { 28 | return $this->getPloi()->makeAPICall($this->getEndpoint()); 29 | } 30 | 31 | public function install(string $provider, string $branch, string $name): Response 32 | { 33 | $options = [ 34 | 'body' => json_encode([ 35 | 'provider' => $provider, 36 | 'branch' => $branch, 37 | 'name' => $name 38 | ]) 39 | ]; 40 | 41 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 42 | } 43 | 44 | public function delete(): Response 45 | { 46 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 47 | } 48 | 49 | public function toggleQuickDeploy(): Response 50 | { 51 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/quick-deploy', 'post'); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Resource.php: -------------------------------------------------------------------------------- 1 | setPloi($ploi); 26 | } 27 | 28 | if ($id) { 29 | $this->setId($id); 30 | } 31 | } 32 | 33 | public function setId(?int $id = null): self 34 | { 35 | $this->id = $id; 36 | 37 | $this->addHistory('Resource ID set to ' . $id); 38 | 39 | return $this; 40 | } 41 | 42 | public function setIdOrFail(?int $id = null): self 43 | { 44 | if ($id) { 45 | $this->setId($id); 46 | } 47 | 48 | if (!$this->getId()) { 49 | throw new RequiresId('ID is required for ' . static::class); 50 | } 51 | 52 | return $this; 53 | } 54 | 55 | public function getId(): ?int 56 | { 57 | return $this->id; 58 | } 59 | 60 | public function setPloi(Ploi $ploi): self 61 | { 62 | $this->ploi = $ploi; 63 | 64 | $this->addHistory('Ploi instance set to ' . json_encode($ploi)); 65 | 66 | return $this; 67 | } 68 | 69 | public function getPloi(): ?Ploi 70 | { 71 | return $this->ploi; 72 | } 73 | 74 | public function setEndpoint(string $endpoint): self 75 | { 76 | $this->endpoint = $endpoint; 77 | 78 | return $this; 79 | } 80 | 81 | public function getEndpoint(): ?string 82 | { 83 | return $this->endpoint; 84 | } 85 | 86 | public function getSite(): Site 87 | { 88 | return $this->site; 89 | } 90 | 91 | public function setSite(Site $site): self 92 | { 93 | $this->site = $site; 94 | 95 | return $this; 96 | } 97 | 98 | public function getDatabase(): Database 99 | { 100 | return $this->database; 101 | } 102 | 103 | public function setDatabase(Database $database) 104 | { 105 | $this->database = $database; 106 | 107 | return $this; 108 | } 109 | 110 | public function getServer(): Server 111 | { 112 | return $this->server; 113 | } 114 | 115 | public function setServer(Server $server) 116 | { 117 | $this->server = $server; 118 | 119 | return $this; 120 | } 121 | 122 | public function setAction(string $action): self 123 | { 124 | $this->action = $action; 125 | 126 | return $this; 127 | } 128 | 129 | public function getAction(): ?string 130 | { 131 | return $this->action; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Robot.php: -------------------------------------------------------------------------------- 1 | getPloi()); 12 | 13 | $this->setServer($server); 14 | $this->setSite($site); 15 | 16 | $this->buildEndpoint(); 17 | } 18 | 19 | public function buildEndpoint(): self 20 | { 21 | $this->setEndpoint($this->getSite()->getEndpoint()); 22 | 23 | return $this; 24 | } 25 | 26 | public function allow(): Response 27 | { 28 | $options = [ 29 | 'body' => json_encode([ 30 | 'disable_robots' => false, 31 | ]), 32 | ]; 33 | 34 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'patch', $options); 35 | } 36 | 37 | public function block(): Response 38 | { 39 | $options = [ 40 | 'body' => json_encode([ 41 | 'disable_robots' => true, 42 | ]), 43 | ]; 44 | 45 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'patch', $options); 46 | } 47 | } -------------------------------------------------------------------------------- /src/Ploi/Resources/Script.php: -------------------------------------------------------------------------------- 1 | setEndpoint($this->endpoint); 21 | } 22 | 23 | public function get(?int $id = null): Response 24 | { 25 | if ($id) { 26 | $this->setId($id); 27 | } 28 | 29 | if ($this->getId()) { 30 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 31 | } 32 | 33 | return (is_null($this->getId())) 34 | ? $this->page() 35 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 36 | } 37 | 38 | public function create( 39 | string $label, 40 | string $user, 41 | string $content 42 | ): Response 43 | { 44 | $this->setId(null); 45 | 46 | $options = [ 47 | 'body' => json_encode([ 48 | 'label' => $label, 49 | 'user' => $user, 50 | 'content' => $content, 51 | ]), 52 | ]; 53 | 54 | $response = $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 55 | 56 | $this->setId($response->getJson()->data->id); 57 | 58 | return $response; 59 | } 60 | 61 | public function delete(?int $id = null): Response 62 | { 63 | $this->setIdOrFail($id); 64 | 65 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 66 | 67 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 68 | } 69 | 70 | public function run(?int $id = null, array $serverIds = []): Response 71 | { 72 | $this->setIdOrFail($id); 73 | 74 | if (!count($serverIds)) { 75 | throw new RequiresId('Server IDs are required'); 76 | } 77 | 78 | $options = [ 79 | 'body' => json_encode([ 80 | 'servers' => $serverIds 81 | ]) 82 | ]; 83 | 84 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId() . '/run'); 85 | 86 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Server.php: -------------------------------------------------------------------------------- 1 | setEndpoint($this->endpoint); 21 | } 22 | 23 | public function buildEndpoint(?string $path = null): string 24 | { 25 | $base = $this->endpoint; 26 | 27 | if ($this->getId()) { 28 | $base = "{$base}/{$this->getId()}"; 29 | } 30 | 31 | if (!$path) { 32 | return $base; 33 | } 34 | 35 | if (strpos($path, '/') === 0) { 36 | return $base . $path; 37 | } 38 | 39 | return "{$base}/{$path}"; 40 | } 41 | 42 | public function callApi(?string $path = null, string $method = 'get', array $options = []): Response 43 | { 44 | return $this->getPloi() 45 | ->makeAPICall($this->buildEndpoint($path), $method, $options); 46 | } 47 | 48 | public function get(?int $id = null): Response 49 | { 50 | if ($id) { 51 | $this->setId($id); 52 | } 53 | 54 | // This method do not need the special callApi() method on pagination 55 | // Since its a the simple get of the servers using the $this->endpoint url 56 | 57 | return (is_null($this->getId())) 58 | ? $this->page() 59 | : $this->callApi(); 60 | } 61 | 62 | public function delete(?int $id = null): Response 63 | { 64 | $this->setIdOrFail($id); 65 | 66 | return $this->callApi(null, 'delete'); 67 | } 68 | 69 | public function logs(?int $id = null): Response 70 | { 71 | $this->setIdOrFail($id); 72 | 73 | return $this->callApi('logs'); 74 | } 75 | 76 | public function create( 77 | string $name, 78 | int $provider, 79 | $region, 80 | $plan, 81 | array $options = [] 82 | ): Response { 83 | 84 | // Remove the id 85 | $this->setId(null); 86 | 87 | $defaults = [ 88 | 'name' => $name, 89 | 'plan' => $plan, 90 | 'region' => $region, 91 | 'credential' => $provider, 92 | 'type' => 'server', 93 | 'database_type' => 'mysql', 94 | 'webserver_type' => 'nginx', 95 | 'php_version' => '7.4' 96 | ]; 97 | 98 | // Set the options 99 | $options = [ 100 | 'body' => json_encode(array_merge($defaults, $options)), 101 | ]; 102 | 103 | // Make the request 104 | $response = $this->callApi(null, 'post', $options); 105 | 106 | // Set the id of the site 107 | $this->setId($response->getJson()->data->id); 108 | 109 | // Return the response 110 | return $response; 111 | } 112 | 113 | public function createCustom(string $ip, array $options): Response 114 | { 115 | $this->setId(null); 116 | $defaults = [ 117 | 'ip' => $ip, 118 | 'type' => 'server', 119 | 'database_type' => 'mysql', 120 | 'php_version' => '7.4', 121 | ]; 122 | 123 | $options = [ 124 | 'body' => json_encode(array_merge($defaults, $options)), 125 | ]; 126 | 127 | $response = $this->callApi('custom', 'post', $options); 128 | 129 | $this->setId($response->getJson()->id); 130 | 131 | return $response; 132 | } 133 | 134 | public function startInstallation(?string $url = null): Response 135 | { 136 | $id = $this->getId(); 137 | 138 | if (!$url && !$id) { 139 | throw new RequiresId("This endpoint requires an ID. Supply an ID or a valid installation url."); 140 | } 141 | 142 | $endpoint = $url ?: "servers/custom/{$id}/start"; 143 | 144 | return $this->getPloi() 145 | ->makeAPICall($endpoint, 'post'); 146 | } 147 | 148 | /** 149 | * @deprecated Will be removed in future versions, use server()->opcache()->refresh() instead. 150 | */ 151 | public function refreshOpcache(?int $id = null): Response 152 | { 153 | $this->setIdOrFail($id); 154 | 155 | return $this->callApi('refresh-opcache', 'post'); 156 | } 157 | 158 | /** 159 | * @deprecated Will be removed in future versions, use server()->opcache()->enable() instead. 160 | */ 161 | public function enableOpcache(?int $id = null): Response 162 | { 163 | $this->setIdOrFail($id); 164 | 165 | return $this->callApi('enable-opcache', 'post'); 166 | } 167 | 168 | /** 169 | * @deprecated Will be removed in future versions, use server()->opcache()->disable() instead. 170 | */ 171 | public function disableOpcache(?int $id = null): Response 172 | { 173 | $this->setIdOrFail($id); 174 | 175 | return $this->callApi('disable-opcache', 'delete'); 176 | } 177 | 178 | public function phpVersions(?int $id = null): Response 179 | { 180 | $this->setIdOrFail($id); 181 | 182 | return $this->callApi('php/versions'); 183 | } 184 | 185 | public function restart(?int $id = null): Response 186 | { 187 | $this->setIdOrFail($id); 188 | 189 | return $this->callApi('restart', 'post'); 190 | } 191 | 192 | public function monitoring(?int $id = null): Response 193 | { 194 | $this->setIdOrFail($id); 195 | 196 | return $this->callApi('monitor'); 197 | } 198 | 199 | public function sites($id = null): Site 200 | { 201 | return new Site($this, $id); 202 | } 203 | 204 | public function services(?string $serviceName = null): Service 205 | { 206 | return new Service($this, $serviceName); 207 | } 208 | 209 | public function databases(?int $id = null): Database 210 | { 211 | return new Database($this, $id); 212 | } 213 | public function cronjobs(?int $id = null): Cronjob 214 | { 215 | return new Cronjob($this, $id); 216 | } 217 | 218 | public function networkRules(?int $id = null): NetworkRule 219 | { 220 | return new NetworkRule($this, $id); 221 | } 222 | 223 | public function systemUsers(?int $id = null): SystemUser 224 | { 225 | return new SystemUser($this, $id); 226 | } 227 | 228 | public function daemons(?int $id = null): Daemon 229 | { 230 | return new Daemon($this, $id); 231 | } 232 | 233 | public function sshKeys(?int $id = null): SshKey 234 | { 235 | return new SshKey($this, $id); 236 | } 237 | 238 | public function opcache(?int $id = null): Opcache 239 | { 240 | return new Opcache($this, $id); 241 | } 242 | 243 | public function insights(?int $id = null): Insight 244 | { 245 | return new Insight($this, $id); 246 | } 247 | 248 | public function loadBalancer(): LoadBalancer 249 | { 250 | return new LoadBalancer($this); 251 | } 252 | } 253 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Service.php: -------------------------------------------------------------------------------- 1 | getPloi()); 16 | 17 | $this->setServer($server); 18 | 19 | if ($serviceName) { 20 | $this->setServiceName($serviceName); 21 | } 22 | 23 | $this->buildEndpoint(); 24 | } 25 | 26 | public function buildEndpoint(): self 27 | { 28 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/services'); 29 | 30 | if ($this->getServiceName()) { 31 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getServiceName()); 32 | } 33 | 34 | return $this; 35 | } 36 | 37 | public function getServiceName(): ?string 38 | { 39 | return $this->serviceName; 40 | } 41 | 42 | public function setServiceName(string $serviceName): self 43 | { 44 | $this->serviceName = $serviceName; 45 | 46 | $this->addHistory('Resource service name set to ' . $serviceName); 47 | 48 | return $this; 49 | } 50 | 51 | public function restart(?string $serviceName = null): Response 52 | { 53 | 54 | if ($serviceName) { 55 | $this->setServiceName($serviceName); 56 | } 57 | 58 | if (!$this->getServiceName()) { 59 | throw new RequiresServiceName; 60 | } 61 | 62 | $this->buildEndpoint(); 63 | 64 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/restart', 'post'); 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /src/Ploi/Resources/Site.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 23 | 24 | $this->setServer($server); 25 | 26 | // Build the endpoint 27 | $this->buildEndpoint(); 28 | } 29 | 30 | public function get(?int $id = null) 31 | { 32 | if ($id) { 33 | $this->setId($id); 34 | } 35 | 36 | // Make sure the endpoint is built 37 | $this->buildEndpoint(); 38 | 39 | return (is_null($this->getId())) 40 | ? $this->page() 41 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 42 | } 43 | 44 | public function getServer(): Server 45 | { 46 | return $this->server; 47 | } 48 | 49 | public function setServer(Server $server) 50 | { 51 | $this->server = $server; 52 | 53 | return $this; 54 | } 55 | 56 | public function buildEndpoint(): self 57 | { 58 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/sites'); 59 | 60 | if ($this->getId()) { 61 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 62 | } 63 | 64 | return $this; 65 | } 66 | 67 | public function create( 68 | string $domain, 69 | string $webDirectory = '/public', 70 | string $projectRoot = '/', 71 | string $systemUser = 'ploi', 72 | ?string $systemUserPassword = null, 73 | ?string $webserverTemplate = null, 74 | ?string $projectType = null 75 | ): Response { 76 | 77 | // Remove the id 78 | $this->setId(null); 79 | 80 | // Set the options 81 | $options = [ 82 | 'body' => json_encode([ 83 | 'root_domain' => $domain, 84 | 'web_directory' => $webDirectory, 85 | 'project_root' => $projectRoot, 86 | 'system_user' => $systemUser, 87 | 'system_user_password' => $systemUserPassword, 88 | 'webserver_template' => $webserverTemplate, 89 | 'project_type' => $projectType 90 | ]), 91 | ]; 92 | 93 | // Build the endpoint 94 | $this->buildEndpoint(); 95 | 96 | // Make the request 97 | $response = $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 98 | 99 | // Set the id of the site 100 | $this->setId($response->getJson()->data->id); 101 | 102 | // Return the response 103 | return $response; 104 | } 105 | 106 | public function update(string $rootDomain): Response 107 | { 108 | $this->setIdOrFail(); 109 | 110 | $options = [ 111 | 'body' => json_encode([ 112 | 'root_domain' => $rootDomain, 113 | ]) 114 | ]; 115 | 116 | $this->buildEndpoint(); 117 | 118 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'patch', $options); 119 | } 120 | 121 | public function delete(?int $id = null): Response 122 | { 123 | if ($id) { 124 | $this->setId($id); 125 | } 126 | 127 | $this->buildEndpoint(); 128 | 129 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 130 | } 131 | 132 | public function logs(?int $id = null): Response 133 | { 134 | if ($id) { 135 | $this->setId($id); 136 | } 137 | 138 | if (!$this->getId()) { 139 | throw new RequiresId('No Site ID set'); 140 | } 141 | 142 | $this->setEndpoint($this->buildEndpoint()->getEndpoint() . '/log'); 143 | 144 | return $this->getPloi()->makeAPICall($this->getEndpoint()); 145 | } 146 | 147 | public function phpVersion($version = '7.4'): Response 148 | { 149 | // Set the options 150 | $options = [ 151 | 'body' => json_encode([ 152 | 'php_version' => $version, 153 | ]), 154 | ]; 155 | 156 | // Build the endpoint 157 | $this->buildEndpoint(); 158 | 159 | // Make the request 160 | $response = $this->getPloi()->makeAPICall($this->getEndpoint() . '/php-version', 'post', $options); 161 | 162 | // Set the id of the site 163 | $this->setId($response->getJson()->data->id); 164 | 165 | // Return the data 166 | return $response; 167 | } 168 | 169 | public function testDomain(?int $id = null): Response 170 | { 171 | if ($id) { 172 | $this->setId($id); 173 | } 174 | 175 | if (!$this->getId()) { 176 | throw new RequiresId('No Site ID set'); 177 | } 178 | 179 | $this->buildEndpoint(); 180 | 181 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/test-domain', 'get'); 182 | } 183 | 184 | public function enableTestDomain(?int $id = null): Response 185 | { 186 | if ($id) { 187 | $this->setId($id); 188 | } 189 | 190 | if (!$this->getId()) { 191 | throw new RequiresId('No Site ID set'); 192 | } 193 | 194 | $this->buildEndpoint(); 195 | 196 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/test-domain', 'post'); 197 | } 198 | 199 | public function disableTestDomain(?int $id = null): Response 200 | { 201 | if ($id) { 202 | $this->setId($id); 203 | } 204 | 205 | if (!$this->getId()) { 206 | throw new RequiresId('No Site ID set'); 207 | } 208 | 209 | $this->buildEndpoint(); 210 | 211 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/test-domain', 'delete'); 212 | } 213 | 214 | public function suspend(?int $id = null, ?string $reason = null): Response 215 | { 216 | $this->setIdOrFail($id); 217 | 218 | $options = []; 219 | if ($reason) { 220 | $options = [ 221 | 'body' => json_encode([ 222 | 'reason' => $reason, 223 | ]), 224 | ]; 225 | } 226 | 227 | $this->buildEndpoint(); 228 | 229 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/suspend', 'post', $options); 230 | } 231 | 232 | public function resume(?int $id = null): Response 233 | { 234 | $this->setIdOrFail($id); 235 | 236 | $this->buildEndpoint(); 237 | 238 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/resume', 'post'); 239 | } 240 | 241 | public function horizonStatistics(string $type = 'stats'): Response 242 | { 243 | $this->buildEndpoint(); 244 | 245 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/laravel/horizon/' . $type); 246 | } 247 | 248 | public function redirects($id = null): Redirect 249 | { 250 | return new Redirect($this->getServer(), $this, $id); 251 | } 252 | 253 | public function certificates($id = null): Certificate 254 | { 255 | return new Certificate($this->getServer(), $this, $id); 256 | } 257 | 258 | public function repository(): Repository 259 | { 260 | return new Repository($this->getServer(), $this); 261 | } 262 | 263 | public function queues($id = null): Queue 264 | { 265 | return new Queue($this->getServer(), $this, $id); 266 | } 267 | 268 | public function deployment(): Deployment 269 | { 270 | return new Deployment($this->getServer(), $this); 271 | } 272 | 273 | public function app($id = null): App 274 | { 275 | return new App($this->getServer(), $this, $id); 276 | } 277 | 278 | public function environment(): Environment 279 | { 280 | return new Environment($this->getServer(), $this); 281 | } 282 | 283 | public function alias(): Alias 284 | { 285 | return new Alias($this->getServer(), $this); 286 | } 287 | 288 | public function fastCgi(): FastCgi 289 | { 290 | return new FastCgi($this->getServer(), $this); 291 | } 292 | 293 | public function authUser(?int $id = null): AuthUser 294 | { 295 | return new AuthUser($this->getServer(), $this, $id); 296 | } 297 | 298 | public function robots(): Robot 299 | { 300 | return new Robot($this->getServer(), $this); 301 | } 302 | 303 | public function tenants(): Tenant 304 | { 305 | return new Tenant($this); 306 | } 307 | 308 | public function monitors(?int $id = null): Monitors 309 | { 310 | return new Monitors($this, $id); 311 | } 312 | 313 | public function nginxConfiguration(): NginxConfiguration 314 | { 315 | return new NginxConfiguration($this); 316 | } 317 | } 318 | -------------------------------------------------------------------------------- /src/Ploi/Resources/SshKey.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 17 | 18 | $this->setServer($server); 19 | 20 | $this->buildEndpoint(); 21 | } 22 | 23 | public function buildEndpoint(): self 24 | { 25 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/ssh-keys'); 26 | 27 | if ($this->getId()) { 28 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 29 | } 30 | 31 | return $this; 32 | } 33 | 34 | public function get(?int $id = null): Response 35 | { 36 | if ($id) { 37 | $this->setId($id); 38 | } 39 | 40 | $this->buildEndpoint(); 41 | 42 | return (is_null($this->getId())) 43 | ? $this->page() 44 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 45 | } 46 | 47 | public function create(string $name, string $key, ?string $systemUser = null): Response 48 | { 49 | $this->setId(null); 50 | 51 | $options = [ 52 | 'body' => json_encode( 53 | [ 54 | 'name' => $name, 55 | 'key' => $key, 56 | 'system_user' => $systemUser, 57 | ] 58 | ), 59 | ]; 60 | 61 | $this->buildEndpoint(); 62 | 63 | $response = $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 64 | 65 | $this->setId($response->getJson()->data->id); 66 | 67 | return $response; 68 | } 69 | 70 | public function delete(?int $id = null): Response 71 | { 72 | $this->setIdOrFail($id); 73 | 74 | $this->buildEndpoint(); 75 | 76 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/Ploi/Resources/StatusPage.php: -------------------------------------------------------------------------------- 1 | buildEndpoint(); 18 | } 19 | 20 | public function buildEndpoint(): self 21 | { 22 | $endpoint = 'status-pages'; 23 | 24 | if ($this->getId()) { 25 | $endpoint .= '/' . $this->getId(); 26 | } 27 | 28 | $this->setEndpoint($endpoint); 29 | 30 | return $this; 31 | } 32 | 33 | public function get(?int $id = null): Response 34 | { 35 | if ($id) { 36 | $this->setId($id); 37 | } 38 | 39 | $this->buildEndpoint(); 40 | 41 | return (is_null($this->getId())) 42 | ? $this->page() 43 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 44 | } 45 | 46 | public function incident(?int $id = null): Incident 47 | { 48 | return new Incident($this, $id); 49 | } 50 | } -------------------------------------------------------------------------------- /src/Ploi/Resources/Synchronize.php: -------------------------------------------------------------------------------- 1 | setEndpoint($this->endpoint); 16 | } 17 | 18 | public function servers() 19 | { 20 | return $this->getPloi()->makeAPICall($this->getEndpoint() . '/servers'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Ploi/Resources/SystemUser.php: -------------------------------------------------------------------------------- 1 | getPloi(), $id); 15 | 16 | $this->setServer($server); 17 | 18 | $this->buildEndpoint(); 19 | } 20 | 21 | public function buildEndpoint(): self 22 | { 23 | $this->setEndpoint($this->getServer()->getEndpoint() . '/' . $this->getServer()->getId() . '/system-users'); 24 | 25 | if ($this->getId()) { 26 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 27 | } 28 | 29 | return $this; 30 | } 31 | 32 | public function get(?int $id = null): Response 33 | { 34 | if ($id) { 35 | $this->setId($id); 36 | } 37 | 38 | // Make sure the endpoint is built 39 | $this->buildEndpoint(); 40 | 41 | return (is_null($this->getId())) 42 | ? $this->page() 43 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 44 | } 45 | 46 | public function create(string $name, bool $sudo = false): Response 47 | { 48 | // Remove the id 49 | $this->setId(null); 50 | 51 | // Set the options 52 | $options = [ 53 | 'body' => json_encode([ 54 | 'name' => $name, 55 | 'sudo' => $sudo 56 | ]), 57 | ]; 58 | 59 | // Build the endpoint 60 | $this->buildEndpoint(); 61 | 62 | // Make the request 63 | $response = $this->getPloi()->makeAPICall($this->getEndpoint(), 'post', $options); 64 | 65 | $this->setId($response->getJson()->data->id); 66 | 67 | // Return the response 68 | return $response; 69 | } 70 | 71 | public function delete(?int $id = null): Response 72 | { 73 | $this->setIdOrFail($id); 74 | 75 | // Build the endpoint 76 | $this->buildEndpoint(); 77 | 78 | // Make the request 79 | return $this->getPloi()->makeAPICall($this->getEndpoint(), 'delete'); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Ploi/Resources/Tenant.php: -------------------------------------------------------------------------------- 1 | getPloi()); 12 | 13 | $this->setSite($site); 14 | 15 | $this->buildEndpoint(); 16 | } 17 | 18 | public function buildEndpoint(): self 19 | { 20 | $this->setEndpoint($this->getSite()->getEndpoint() . '/tenants'); 21 | 22 | return $this; 23 | } 24 | 25 | public function get(): Response 26 | { 27 | return $this->getPloi()->makeAPICall($this->getEndpoint()); 28 | } 29 | 30 | public function create(array $tenants): Response 31 | { 32 | $options = [ 33 | 'body' => json_encode([ 34 | 'tenants' => $tenants, 35 | ]) 36 | ]; 37 | 38 | return $this->getPloi()->makeApiCall($this->getEndpoint(), 'post', $options); 39 | } 40 | 41 | public function delete(?string $tenant = null): Response 42 | { 43 | $url = "{$this->getEndpoint()}/{$tenant}"; 44 | return $this->getPloi()->makeAPICall($url, 'delete'); 45 | } 46 | 47 | public function requestCertificate(string $tenant, ?string $webhook = null, string $domains = ''): Response 48 | { 49 | $options = [ 50 | 'body' => json_encode([ 51 | 'webhook' => $webhook, 52 | 'domains' => $domains 53 | ]) 54 | ]; 55 | 56 | $url = "{$this->getEndpoint()}/{$tenant}/request-certificate"; 57 | 58 | return $this->getPloi()->makeApiCall($url, 'post', $options); 59 | } 60 | 61 | public function revokeCertificate(string $tenant, string $webhook): Response 62 | { 63 | $options = [ 64 | 'body' => json_encode([ 65 | 'webhook' => $webhook, 66 | ]) 67 | ]; 68 | 69 | $url = "{$this->getEndpoint()}/{$tenant}/revoke-certificate"; 70 | 71 | return $this->getPloi()->makeApiCall($url, 'post', $options); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Ploi/Resources/User.php: -------------------------------------------------------------------------------- 1 | setEndpoint($this->endpoint); 17 | } 18 | 19 | public function get(): Response 20 | { 21 | return $this->getPloi()->makeAPICall($this->getEndpoint()); 22 | } 23 | 24 | public function statistics(): Response 25 | { 26 | $url = $this->getEndpoint() . '/statistics'; 27 | 28 | return $this->getPloi()->makeAPICall($url); 29 | } 30 | 31 | public function serverProviders(?int $providerId = null): Response 32 | { 33 | $url = $this->getEndpoint() . '/server-providers'; 34 | 35 | if ($providerId) { 36 | $url .= '/' . $providerId; 37 | } 38 | 39 | return $this->getPloi()->makeAPICall($url); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Ploi/Resources/WebserverTemplate.php: -------------------------------------------------------------------------------- 1 | setEndpoint($this->endpoint); 20 | } 21 | 22 | public function get(?int $id = null): Response 23 | { 24 | if ($id) { 25 | $this->setId($id); 26 | } 27 | 28 | if ($this->getId()) { 29 | $this->setEndpoint($this->getEndpoint() . '/' . $this->getId()); 30 | } 31 | 32 | return (is_null($this->getId())) 33 | ? $this->page() 34 | : $this->getPloi()->makeAPICall($this->getEndpoint()); 35 | } 36 | } -------------------------------------------------------------------------------- /src/Ploi/Traits/HasHistory.php: -------------------------------------------------------------------------------- 1 | 14 | */ 15 | private $history; 16 | 17 | /** 18 | * Returns the history of a resource 19 | * 20 | * @return array 21 | */ 22 | public function getHistory(): array 23 | { 24 | return $this->history; 25 | } 26 | 27 | /** 28 | * Allows the history to be overridden by setting a 29 | * new history. 30 | * 31 | * @param array $history 32 | * @return self 33 | */ 34 | public function setHistory(array $history): self 35 | { 36 | $this->history = $history; 37 | 38 | return $this; 39 | } 40 | 41 | /** 42 | * Adds an item to the history 43 | * 44 | * @param string $history 45 | * @return self 46 | */ 47 | public function addHistory(string $history): self 48 | { 49 | $this->history[] = $history; 50 | 51 | return $this; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Ploi/Traits/HasPagination.php: -------------------------------------------------------------------------------- 1 | amountPerPage = $amountPerPage; 28 | 29 | return $this; 30 | } 31 | 32 | public function page(int $pageNumber = 1, ?int $amountPerPage = null): Response 33 | { 34 | return $this->getPloi()->makeAPICall( 35 | $this->getEndpoint() . $this->getPaginationQuery($pageNumber, $amountPerPage) 36 | ); 37 | } 38 | 39 | protected function getPaginationQuery(int $pageNumber, ?int $amountPerPage = null): string 40 | { 41 | $path = "?page={$pageNumber}"; 42 | 43 | if ($amountPerPage) { 44 | $this->perPage($amountPerPage); 45 | } 46 | 47 | if ($this->amountPerPage) { 48 | $path .= "&per_page={$this->amountPerPage}"; 49 | } 50 | 51 | return $path; 52 | } 53 | } -------------------------------------------------------------------------------- /src/Ploi/Traits/HasSearch.php: -------------------------------------------------------------------------------- 1 | searchQuery = $searchQuery; 45 | 46 | return $this; 47 | } 48 | 49 | /** 50 | * Perform a search with the given query. 51 | * 52 | * @param string $searchQuery 53 | * @return Response 54 | * @throws \Exception 55 | */ 56 | public function search(string $searchQuery): Response 57 | { 58 | $ploi = $this->getPloi(); 59 | $endpoint = $this->getEndpoint(); 60 | 61 | if (is_null($ploi) || is_null($endpoint)) { 62 | throw new \Exception('Ploi instance or endpoint is not set.'); 63 | } 64 | 65 | return $ploi->makeAPICall( 66 | $endpoint . $this->buildSearchQuery($searchQuery) 67 | ); 68 | } 69 | 70 | /** 71 | * Build the search query string. 72 | * 73 | * @param string $searchQuery 74 | * @return string 75 | */ 76 | protected function buildSearchQuery(string $searchQuery): string 77 | { 78 | return "?search={$searchQuery}"; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /tests/.env.sample: -------------------------------------------------------------------------------- 1 | #API_TOKEN=null -------------------------------------------------------------------------------- /tests/BaseTest.php: -------------------------------------------------------------------------------- 1 | ploi; 28 | } 29 | 30 | protected function setup(): void 31 | { 32 | $this->ploi = new Ploi($_ENV['API_TOKEN']); 33 | 34 | parent::setup(); 35 | } 36 | 37 | /** 38 | * Load the environment file 39 | */ 40 | public static function setUpBeforeClass(): void 41 | { 42 | // Load the test environment 43 | $dotenv = \Dotenv\Dotenv::createImmutable(__DIR__); 44 | $dotenv->load(); 45 | $dotenv->required('API_TOKEN')->notEmpty(); 46 | 47 | parent::setUpBeforeClass(); 48 | } 49 | 50 | /** 51 | * Base test to make sure it's running 52 | */ 53 | public function testTrue() 54 | { 55 | $this->assertTrue(true); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/Ploi/PloiTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($_ENV['API_TOKEN'], $this->getPloi()->getApiToken()); 20 | } 21 | 22 | public function testCanSetApiToken() 23 | { 24 | $newToken = "NEW_TOKEN"; 25 | 26 | $this->getPloi()->setApiToken($newToken); 27 | 28 | $this->assertEquals($newToken, $this->getPloi()->getApiToken()); 29 | } 30 | 31 | public function testValidApiMethod() 32 | { 33 | $methods = ['get', 'post', 'delete']; 34 | 35 | foreach ($methods as $method) { 36 | try { 37 | $path = $method === 'delete' ? 'servers/1' : 'servers'; 38 | $this->getPloi()->makeAPICall($path, $method); 39 | } catch (Exception $exception) { 40 | $this->assertNotInstanceOf(NotAllowed::class, $exception); 41 | } 42 | } 43 | } 44 | 45 | public function testInvalidApiMethod() 46 | { 47 | $method = 'PPOST'; 48 | try { 49 | $this->getPloi()->makeAPICall('url', $method); 50 | } catch (Exception $e) { 51 | $this->assertInstanceOf(Exception::class, $e); 52 | $this->assertEquals('Invalid method type', $e->getMessage()); 53 | } 54 | } 55 | 56 | public function testThrows404() 57 | { 58 | try { 59 | $this->getPloi()->makeAPICall('servers/servers'); 60 | } catch (NotFound $e) { 61 | $this->assertInstanceOf(NotFound::class, $e); 62 | } 63 | } 64 | 65 | public function testThrowsUnauthenticated() 66 | { 67 | $this->getPloi()->setApiToken('Invalid'); 68 | 69 | try { 70 | $this->getPloi()->server()->get(); 71 | } catch (Unauthenticated $e) { 72 | $this->assertInstanceOf(Unauthenticated::class, $e); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /tests/Ploi/Resources/AliasTest.php: -------------------------------------------------------------------------------- 1 | getPloi()->server()->get(); 23 | if (!empty($allServers->getJson()->data)) { 24 | $resource = $this->getPloi()->server($allServers->getJson()->data[0]->id); 25 | $serverSites = $resource->sites()->get(); 26 | $this->site = $resource->sites($serverSites->getJson()->data[0]->id); 27 | } 28 | } 29 | 30 | public function testCreateAlias(): void 31 | { 32 | $response = $this->site->alias()->create(['example.com']); 33 | 34 | $this->assertContains('example.com', $response->getData()->aliases); 35 | } 36 | 37 | public function testListAliases(): void 38 | { 39 | $response = $this->site->alias()->get(); 40 | 41 | $this->assertIsArray($response->getData()->aliases); 42 | } 43 | 44 | /** 45 | * @depends testCreateAlias 46 | */ 47 | public function testDeleteAlias(): void 48 | { 49 | $response = $this->site->alias()->delete('example.com'); 50 | 51 | $this->assertNotContains('example.com', $response->getData()->aliases); 52 | } 53 | } -------------------------------------------------------------------------------- /tests/Ploi/Resources/ServerTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf(Server::class, $this->getPloi()->server()); 20 | } 21 | 22 | public function testBuildsUrlCorrectly() 23 | { 24 | $server = $this->getPloi()->server(); 25 | 26 | $this->assertEquals('servers', $server->buildEndpoint()); 27 | $this->assertEquals('servers/custom', $server->buildEndpoint('custom')); 28 | 29 | $server->setId(1); 30 | $this->assertEquals('servers/1', $server->buildEndpoint()); 31 | $this->assertEquals('servers/1/endpoint', $server->buildEndpoint('endpoint')); 32 | $this->assertEquals('servers/1/endpoint', $server->buildEndpoint('/endpoint')); 33 | 34 | $server->setId(); 35 | $this->assertEquals('servers/different-endpoint', $server->buildEndpoint('/different-endpoint')); 36 | } 37 | 38 | /** 39 | * @throws \Ploi\Exceptions\Http\InternalServerError 40 | * @throws \Ploi\Exceptions\Http\NotFound 41 | * @throws \Ploi\Exceptions\Http\NotValid 42 | * @throws \Ploi\Exceptions\Http\PerformingMaintenance 43 | * @throws \Ploi\Exceptions\Http\TooManyAttempts 44 | */ 45 | public function testGetAllServers() 46 | { 47 | $servers = $this->getPloi() 48 | ->server() 49 | ->get(); 50 | 51 | // Test that it's a valid response object 52 | $this->assertInstanceOf(Response::class, $servers); 53 | 54 | // Test the json object response 55 | $this->assertInstanceOf(\stdClass::class, $servers->getJson()); 56 | 57 | // Test the array response 58 | $this->assertIsArray($servers->toArray()); 59 | 60 | // Test to make sure that the data is an array 61 | $this->assertIsArray($servers->getJson()->data); 62 | } 63 | 64 | public function testGetPaginatedServers() 65 | { 66 | $serversPage1 = $this->getPloi() 67 | ->server() 68 | ->perPage(5) 69 | ->page(); 70 | $serversPage2 = $this->getPloi() 71 | ->server() 72 | ->page(2, 5); 73 | 74 | // Test that it's a valid response object 75 | $this->assertInstanceOf(Response::class, $serversPage1); 76 | $this->assertInstanceOf(Response::class, $serversPage2); 77 | 78 | // Test the json object response 79 | $this->assertInstanceOf(\stdClass::class, $serversPage1->getJson()); 80 | $this->assertInstanceOf(\stdClass::class, $serversPage2->getJson()); 81 | 82 | // Test the array response 83 | $this->assertIsArray($serversPage1->toArray()); 84 | $this->assertIsArray($serversPage2->toArray()); 85 | 86 | // Test responses contain paginated result 87 | $this->assertEquals(1, $serversPage1->getJson()->meta->current_page); 88 | $this->assertEquals(2, $serversPage2->getJson()->meta->current_page); 89 | 90 | $this->assertEquals(5, $serversPage1->getJson()->meta->per_page); 91 | $this->assertEquals(5, $serversPage2->getJson()->meta->per_page); 92 | } 93 | 94 | /** 95 | * @throws \Ploi\Exceptions\Http\InternalServerError 96 | * @throws \Ploi\Exceptions\Http\NotFound 97 | * @throws \Ploi\Exceptions\Http\NotValid 98 | * @throws \Ploi\Exceptions\Http\PerformingMaintenance 99 | * @throws \Ploi\Exceptions\Http\TooManyAttempts 100 | */ 101 | public function testGetSingleServer() 102 | { 103 | $serverResource = $this->getPloi() 104 | ->server(); 105 | 106 | // Get all servers and select the first one 107 | $allServers = $serverResource->get(); 108 | $firstServer = $allServers->getJson()->data[0]; 109 | 110 | if (!empty($firstServer)) { 111 | $serverId = $firstServer->id; 112 | 113 | // Get a single server through a pre-existing server resource 114 | $methodOne = $serverResource->get($serverId); 115 | 116 | // Get a single server through a new server resource 117 | $methodTwo = $this->getPloi()->server($serverId)->get(); 118 | 119 | $this->assertEquals($serverId, $methodOne->getJson()->data->id); 120 | $this->assertEquals($serverId, $methodTwo->getJson()->data->id); 121 | } 122 | 123 | // Check that it throws a RequiresId error 124 | try { 125 | $this->getPloi()->server()->get(); 126 | } catch (\Exception $exception) { 127 | $this->assertInstanceOf(RequiresId::class, $exception); 128 | } 129 | } 130 | 131 | /** 132 | * @throws \Ploi\Exceptions\Http\InternalServerError 133 | * @throws \Ploi\Exceptions\Http\NotFound 134 | * @throws \Ploi\Exceptions\Http\NotValid 135 | * @throws \Ploi\Exceptions\Http\PerformingMaintenance 136 | * @throws \Ploi\Exceptions\Http\TooManyAttempts 137 | * @throws \Ploi\Exceptions\Resource\RequiresId 138 | */ 139 | public function testGetServerLogs() 140 | { 141 | $serverResource = $this->getPloi() 142 | ->server(); 143 | 144 | // Get all servers and select the first one 145 | $allServers = $serverResource->get(); 146 | $firstServer = $allServers->getJson()->data[0]; 147 | 148 | if (!empty($firstServer)) { 149 | $serverId = $firstServer->id; 150 | 151 | // Get a single server through a pre-existing server resource 152 | $methodOne = $serverResource->logs($serverId); 153 | 154 | // Get a single server through a new server resource 155 | $methodTwo = $this->getPloi()->server($serverId)->logs(); 156 | 157 | $this->assertIsArray($methodOne->getJson()->data); 158 | $this->assertEquals($serverId, $methodOne->getJson()->data[0]->server_id); 159 | $this->assertEquals($serverId, $methodTwo->getJson()->data[0]->server_id); 160 | } 161 | 162 | // Check that it throws a RequiresId error 163 | try { 164 | $this->getPloi()->server()->logs(); 165 | } catch (\Exception $exception) { 166 | $this->assertInstanceOf(RequiresId::class, $exception); 167 | } 168 | } 169 | 170 | public function testServerRestart() 171 | { 172 | $serverResource = $this->getPloi() 173 | ->server(); 174 | 175 | // Get all servers and select the first one 176 | $allServers = $serverResource->get(); 177 | $firstServer = $allServers->getJson()->data[0]; 178 | 179 | if (!empty($firstServer)) { 180 | $serverId = $firstServer->id; 181 | 182 | // Get a single server through a pre-existing server resource 183 | $methodOne = $serverResource->restart($serverId); 184 | 185 | // Get a single server through a new server resource 186 | $methodTwo = $this->getPloi()->server($serverId)->restart(); 187 | 188 | $this->assertTrue($methodOne->getResponse()->getStatusCode() === 200); 189 | $this->assertTrue($methodTwo->getResponse()->getStatusCode() === 200); 190 | } 191 | 192 | // Check that it throws a RequiresId error 193 | try { 194 | $this->getPloi()->server()->restart(); 195 | } catch (\Exception $exception) { 196 | $this->assertInstanceOf(RequiresId::class, $exception); 197 | } 198 | } 199 | 200 | public function testGetServerMonitoring() 201 | { 202 | $serverResource = $this->getPloi() 203 | ->server(); 204 | 205 | // Get all servers and select the first one 206 | $allServers = $serverResource->get(); 207 | $firstServer = $allServers->getJson()->data[0]; 208 | 209 | if (!empty($firstServer)) { 210 | $serverId = $firstServer->id; 211 | 212 | // Get a single server through a pre-existing server resource 213 | $methodOne = $serverResource->monitoring($serverId); 214 | 215 | // Get a single server through a new server resource 216 | $methodTwo = $this->getPloi()->server($serverId)->monitoring(); 217 | 218 | $this->assertIsArray($methodOne->getJson()->data); 219 | $this->assertIsArray($methodTwo->getJson()->data); 220 | } 221 | 222 | // Check that it throws a RequiresId error 223 | try { 224 | $this->getPloi()->server()->monitoring(); 225 | } catch (\Exception $exception) { 226 | $this->assertInstanceOf(RequiresId::class, $exception); 227 | } 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /tests/Ploi/Resources/SiteTest.php: -------------------------------------------------------------------------------- 1 | getPloi()->server(); 30 | $allServers = $resource->get(); 31 | if (!empty($allServers->getJson()->data)) { 32 | $this->server = $resource->setId($allServers->getJson()->data[0]->id); 33 | } 34 | } 35 | 36 | public function testGetAllSites() 37 | { 38 | $resource = $this->server->sites(); 39 | 40 | $sites = $resource->get(); 41 | 42 | $this->assertInstanceOf(Response::class, $sites); 43 | $this->assertIsArray($sites->getJson()->data); 44 | } 45 | 46 | public function testGetPaginatedSites() 47 | { 48 | $resource = $this->server->sites(); 49 | 50 | $sitesPage1 = $resource->perPage(5)->page(); 51 | $sitesPage2 = $resource->page(2, 5); 52 | 53 | $this->assertInstanceOf(Response::class, $sitesPage1); 54 | $this->assertInstanceOf(Response::class, $sitesPage2); 55 | 56 | $this->assertIsArray($sitesPage1->getJson()->data); 57 | $this->assertIsArray($sitesPage2->getJson()->data); 58 | 59 | $this->assertEquals(1, $sitesPage1->getJson()->meta->current_page); 60 | $this->assertEquals(2, $sitesPage2->getJson()->meta->current_page); 61 | 62 | $this->assertEquals(5, $sitesPage1->getJson()->meta->per_page); 63 | $this->assertEquals(5, $sitesPage2->getJson()->meta->per_page); 64 | } 65 | 66 | /** 67 | * @throws \Ploi\Exceptions\Http\InternalServerError 68 | * @throws \Ploi\Exceptions\Http\NotFound 69 | * @throws \Ploi\Exceptions\Http\NotValid 70 | * @throws \Ploi\Exceptions\Http\PerformingMaintenance 71 | * @throws \Ploi\Exceptions\Http\TooManyAttempts 72 | */ 73 | public function testGetSingleSite() 74 | { 75 | $resource = $this->server->sites(); 76 | $sites = $resource->get(); 77 | 78 | if (!empty($sites->getJson()->data[0])) { 79 | $siteId = $sites->getJson()->data[0]->id; 80 | 81 | $resource->setId($siteId); 82 | $methodOne = $resource->get(); 83 | $methodTwo = $this->server->sites($siteId)->get(); 84 | $methodThree = $this->server->sites()->get($siteId); 85 | 86 | $this->assertInstanceOf(stdClass::class, $methodOne->getJson()->data); 87 | $this->assertEquals($siteId, $methodOne->getJson()->data->id); 88 | $this->assertEquals($siteId, $methodTwo->getJson()->data->id); 89 | $this->assertEquals($siteId, $methodThree->getJson()->data->id); 90 | } 91 | } 92 | 93 | public function testCreateExampleDotCom(): stdClass 94 | { 95 | try { 96 | $response = $this->server->sites()->create('example.com'); 97 | 98 | $this->assertInstanceOf(Response::class, $response); 99 | $this->assertNotEmpty($response->getData()->id); 100 | return $response->getData(); 101 | } catch (\Exception $e) { 102 | $this->assertInstanceOf(NotValid::class, $e); 103 | 104 | $allSites = $this->server->sites()->get(); 105 | $foundSite = false; 106 | foreach ($allSites->getJson()->data as $site) { 107 | if ($foundSite) { 108 | break; 109 | } 110 | 111 | if ($site->domain === 'example.com') { 112 | $this->server->sites($site->id)->delete(); 113 | 114 | $this->testCreateExampleDotCom(); 115 | } 116 | } 117 | } 118 | } 119 | 120 | /** 121 | * @depends testCreateExampleDotCom 122 | */ 123 | public function testDeleteSite($site) 124 | { 125 | if (!empty($site)) { 126 | $deleted = $this->server->sites($site->id)->delete(); 127 | $this->assertTrue($deleted->getResponse()->getStatusCode() === 200); 128 | } 129 | } 130 | 131 | public function testDeleteInvalidSite() 132 | { 133 | try { 134 | $this->server->sites(1)->delete(); 135 | } catch (\Exception $e) { 136 | $this->assertInstanceOf(NotFound::class, $e); 137 | } 138 | 139 | try { 140 | $this->server->sites()->delete(1); 141 | } catch (\Exception $e) { 142 | $this->assertInstanceOf(NotFound::class, $e); 143 | } 144 | } 145 | 146 | public function testLogs() 147 | { 148 | $resource = $this->server->sites(); 149 | $sites = $resource->get(); 150 | 151 | if (!empty($sites->getJson()->data[0])) { 152 | $siteId = $sites->getJson()->data[0]->id; 153 | 154 | $response = $resource->logs($siteId); 155 | $this->assertInstanceOf(Response::class, $response); 156 | 157 | $logs = $response->getData(); 158 | $this->assertIsArray($logs); 159 | 160 | 161 | if (!empty($logs[0])) { 162 | $this->assertInstanceOf(stdClass::class, $logs[0]); 163 | } 164 | } 165 | } 166 | 167 | public function testSuspendSite() 168 | { 169 | $sites = $this->server->sites()->get(); 170 | 171 | if (!empty($sites->getJson()->data[0])) { 172 | $siteId = $sites->getJson()->data[0]->id; 173 | $response = $this->server->sites($siteId)->suspend(null, 'Testing SDK'); 174 | 175 | $this->assertTrue($response->getResponse()->getStatusCode() === 200); 176 | } 177 | 178 | try { 179 | $this->server->sites()->resume(); 180 | } catch (\Exception $e) { 181 | $this->assertInstanceOf(RequiresId::class, $e); 182 | } 183 | } 184 | 185 | public function testResumeSite() 186 | { 187 | $sites = $this->server->sites()->get(); 188 | 189 | if (!empty($sites->getJson()->data[0])) { 190 | $siteId = $sites->getJson()->data[0]->id; 191 | $response = $this->server->sites($siteId)->resume(); 192 | 193 | $this->assertTrue($response->getResponse()->getStatusCode() === 200); 194 | } 195 | 196 | try { 197 | $this->server->sites()->resume(); 198 | } catch (\Exception $e) { 199 | $this->assertInstanceOf(RequiresId::class, $e); 200 | } 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /tests/Ploi/Resources/SshKeyTest.php: -------------------------------------------------------------------------------- 1 | getPloi()->server(); 28 | $allServers = $resource->get(); 29 | if (!empty($allServers->getJson()->data)) { 30 | $this->server = $resource->setId($allServers->getJson()->data[0]->id); 31 | } 32 | } 33 | 34 | public function testGetAllSshKeys() 35 | { 36 | $resource = $this->server->sshKeys(); 37 | 38 | $sshKeys = $resource->get(); 39 | 40 | $this->assertInstanceOf(Response::class, $sshKeys); 41 | $this->assertIsArray($sshKeys->getJson()->data); 42 | } 43 | 44 | public function testGetPaginatedSshKeys() 45 | { 46 | $resource = $this->server->sshKeys(); 47 | 48 | $sshKeysPage1 = $resource->perPage(5)->page(); 49 | $sshKeysPage2 = $resource->page(2, 5); 50 | 51 | $this->assertInstanceOf(Response::class, $sshKeysPage1); 52 | $this->assertInstanceOf(Response::class, $sshKeysPage2); 53 | 54 | $this->assertIsArray($sshKeysPage1->getJson()->data); 55 | $this->assertIsArray($sshKeysPage2->getJson()->data); 56 | 57 | $this->assertEquals(1, $sshKeysPage1->getJson()->meta->current_page); 58 | $this->assertEquals(2, $sshKeysPage2->getJson()->meta->current_page); 59 | 60 | $this->assertEquals(5, $sshKeysPage1->getJson()->meta->per_page); 61 | $this->assertEquals(5, $sshKeysPage2->getJson()->meta->per_page); 62 | } 63 | 64 | public function testGetSingleSshKey() 65 | { 66 | $resource = $this->server->sshKeys(); 67 | $sshKeys = $resource->get(); 68 | 69 | if (!empty($sshKeys->getJson()->data[0])) { 70 | $sshKeyId = $sshKeys->getJson()->data[0]->id; 71 | 72 | $resource->setId($sshKeyId); 73 | $methodOne = $resource->get(); 74 | $methodTwo = $this->server->sshKeys($sshKeyId)->get(); 75 | $methodThree = $this->server->sshKeys()->get($sshKeyId); 76 | 77 | $this->assertInstanceOf(stdClass::class, $methodOne->getJson()->data); 78 | $this->assertEquals($sshKeyId, $methodOne->getJson()->data->id); 79 | $this->assertEquals($sshKeyId, $methodTwo->getJson()->data->id); 80 | $this->assertEquals($sshKeyId, $methodThree->getJson()->data->id); 81 | } 82 | } 83 | 84 | public function testCreateSshKey(): stdClass 85 | { 86 | $response = $this->server->sshKeys()->create( 87 | 'SDK Test SSH Key', 88 | 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDNnp3LYOjNdQzkFH27ggocdjQKxF+XF5NB0rl0jnmIYaA/Y28ONgivQED8NXpZutlpWvORcL+wPwwbdje8d+9uuOMaVO5c26HPczMS6EX0QpYyyEfw1BJbkKAMUBQC3ncqijzslrzNtl3y0R5nvOS6TO4ehsq/9/ntINztuGIdcw==' 89 | ); 90 | 91 | $this->assertInstanceOf(Response::class, $response); 92 | $this->assertNotEmpty($response->getData()->id); 93 | return $response->getData(); 94 | } 95 | 96 | /** 97 | * @depends testCreateSshKey 98 | */ 99 | public function testDeleteSshKey(stdClass $sshKey) 100 | { 101 | if (!empty($sshKey)) { 102 | $deleted = $this->server->sshKeys($sshKey->id)->delete(); 103 | $this->assertTrue($deleted->getResponse()->getStatusCode() === 200); 104 | } 105 | } 106 | 107 | public function testDeleteInvalidSshKey() 108 | { 109 | try { 110 | $this->server->sshKeys(1)->delete(); 111 | } catch (\Exception $e) { 112 | $this->assertInstanceOf(NotFound::class, $e); 113 | } 114 | 115 | try { 116 | $this->server->sshKeys()->delete(1); 117 | } catch (\Exception $e) { 118 | $this->assertInstanceOf(NotFound::class, $e); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /tests/Ploi/Traits/HistoryTest.php: -------------------------------------------------------------------------------- 1 | resource = $this->getPloi()->server(); 25 | } 26 | 27 | public function testGetHistory() 28 | { 29 | $this->assertIsArray($this->resource->getHistory()); 30 | } 31 | 32 | public function testAddHistory() 33 | { 34 | $newHistory ='Adding to the history'; 35 | $this->resource->addHistory($newHistory); 36 | 37 | $this->assertContains($newHistory, $this->resource->getHistory()); 38 | } 39 | 40 | public function testSetHistory() 41 | { 42 | $newHistory = [ 43 | 'New History' 44 | ]; 45 | 46 | // Set the history 47 | $this->resource->setHistory($newHistory); 48 | 49 | $this->assertEquals(1, count($this->resource->getHistory())); 50 | $this->assertEquals($newHistory, $this->resource->getHistory()); 51 | } 52 | } 53 | --------------------------------------------------------------------------------