├── .github ├── dependabot.yml └── workflows │ └── run-tests.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── plesk.php └── src ├── Api ├── AbstractApi.php ├── ApiInterface.php ├── Authentication.php ├── Cli.php ├── Clients.php ├── Domains.php ├── Extensions.php └── Server.php ├── Client.php ├── ClientInterface.php ├── Facade.php ├── HttpClient ├── HttpClient.php └── HttpClientInterface.php ├── Plesk.php ├── ServiceProvider.php └── helpers.php /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: composer 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | -------------------------------------------------------------------------------- /.github/workflows/run-tests.yml: -------------------------------------------------------------------------------- 1 | name: tests 2 | 3 | on: 4 | push: 5 | pull_request: 6 | schedule: 7 | - cron: '0 0 * * *' 8 | 9 | jobs: 10 | php-tests: 11 | runs-on: ${{ matrix.os }} 12 | 13 | strategy: 14 | matrix: 15 | php: [8.0, 7.4] 16 | laravel: [8.*, 7.*, 6.*] 17 | dependency-version: [prefer-lowest, prefer-stable] 18 | os: [ubuntu-latest] 19 | include: 20 | - laravel: 8.* 21 | testbench: 6.* 22 | - laravel: 7.* 23 | testbench: 5.* 24 | - laravel: 6.* 25 | testbench: 4.* 26 | 27 | name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} 28 | 29 | steps: 30 | - name: Checkout code 31 | uses: actions/checkout@v2 32 | 33 | - name: Setup PHP 34 | uses: shivammathur/setup-php@v2 35 | with: 36 | php-version: ${{ matrix.php }} 37 | extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick 38 | coverage: none 39 | 40 | - name: Install dependencies 41 | run: | 42 | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update 43 | composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest 44 | 45 | - name: Execute tests 46 | run: vendor/bin/phpunit 47 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-plesk` will be documented in this file 4 | 5 | ## 0.8.0 - 2020-12-06 6 | 7 | - Adding support for PHP 8.0, ditched PHP 7.2 and PHP 7.3 8 | 9 | ## 0.7.0 - 2020-09-18 10 | 11 | - Adding support for Laravel 8 12 | 13 | ## 0.6.0 - 2020-02-24 14 | 15 | - Adding support for Laravel 7 16 | - Dropping support for Laravel 5.8 17 | 18 | ## 0.5.0 - 2019-12-02 19 | 20 | - Added support for PHP 7.4 21 | 22 | ## 0.4.0 - 2019-09-04 23 | 24 | - Added support for Laravel 6 25 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) nickurt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Laravel Plesk Onyx 17.8 2 | [![Build Status](https://github.com/nickurt/laravel-plesk/workflows/tests/badge.svg)](https://github.com/nickurt/laravel-plesk/actions) 3 | [![Total Downloads](https://poser.pugx.org/nickurt/laravel-plesk/d/total.svg)](https://packagist.org/packages/nickurt/laravel-plesk) 4 | [![Latest Stable Version](https://poser.pugx.org/nickurt/laravel-plesk/v/stable.svg)](https://packagist.org/packages/nickurt/laravel-plesk) 5 | [![MIT Licensed](https://poser.pugx.org/nickurt/laravel-plesk/license.svg)](LICENSE.md) 6 | 7 | ### Installation 8 | Install this package with composer: 9 | ``` 10 | composer require nickurt/laravel-plesk 11 | ``` 12 | Copy the config files for the Plesk-plugin 13 | ``` 14 | php artisan vendor:publish --provider="nickurt\Plesk\ServiceProvider" --tag="config" 15 | ``` 16 | ### Tests 17 | ```sh 18 | composer test 19 | ``` 20 | - - - 21 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nickurt/laravel-plesk", 3 | "description": "Plesk Onyx 17.8 for Laravel 6.x/7.x/8.x", 4 | "keywords": ["plesk", "plesk onyx", "plesk onyx 17.8", "laravel"], 5 | "license": "MIT", 6 | "require": { 7 | "php": "^8.0|^7.4", 8 | "laravel/framework": "^6.0|^7.0|^8.0", 9 | "guzzlehttp/guzzle": "^6.3.1|^7.0.1" 10 | }, 11 | "require-dev": { 12 | "phpunit/phpunit": "^7.5.15|^8.4|^9.3.3", 13 | "orchestra/testbench": "^4.0|^5.0|^6.0" 14 | }, 15 | "autoload": { 16 | "psr-4": { 17 | "nickurt\\Plesk\\": "src/" 18 | }, 19 | "files": [ 20 | "src/helpers.php" 21 | ] 22 | }, 23 | "autoload-dev": { 24 | "psr-4": { 25 | "nickurt\\Plesk\\tests\\": "tests" 26 | } 27 | }, 28 | "scripts": { 29 | "test": "vendor/bin/phpunit", 30 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage" 31 | }, 32 | "minimum-stability": "dev", 33 | "prefer-stable": true, 34 | "extra": { 35 | "laravel": { 36 | "providers": [ 37 | "nickurt\\Plesk\\ServiceProvider" 38 | ], 39 | "aliases": { 40 | "Plesk": "nickurt\\Plesk\\Facade" 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /config/plesk.php: -------------------------------------------------------------------------------- 1 | env('PLESK_SERVER', 'default'), 6 | 7 | 'servers' => [ 8 | 9 | 'default' => [ 10 | 'host' => env('PLESK_DEFAULT_HOST'), 11 | 'username' => env('PLESK_DEFAULT_USERNAME'), 12 | 'password' => env('PLESK_DEFAULT_PASSWORD'), 13 | ], 14 | 15 | ], 16 | 17 | ]; -------------------------------------------------------------------------------- /src/Api/AbstractApi.php: -------------------------------------------------------------------------------- 1 | client = $client; 19 | } 20 | 21 | /** 22 | * @param string $path 23 | * @param array $parameters 24 | * @param array $headers 25 | * @return mixed 26 | * @throws \GuzzleHttp\Exception\GuzzleException 27 | */ 28 | public function delete($path, array $parameters = [], array $headers = []) 29 | { 30 | return $this->client->getHttpClient()->delete( 31 | $path, 32 | $parameters, 33 | $headers 34 | ); 35 | } 36 | 37 | /** 38 | * @param string $path 39 | * @param array $parameters 40 | * @param array $headers 41 | * @return mixed 42 | */ 43 | public function get($path, array $parameters = [], array $headers = []) 44 | { 45 | return $this->client->getHttpClient()->get( 46 | $path, 47 | $parameters, 48 | $headers 49 | ); 50 | } 51 | 52 | public function path($path, $body, array $headers = []) 53 | { 54 | // 55 | } 56 | 57 | /** 58 | * @param string $path 59 | * @param array $body 60 | * @param array $headers 61 | * @return mixed 62 | * @throws \GuzzleHttp\Exception\GuzzleException 63 | */ 64 | public function post($path, $body, array $headers = []) 65 | { 66 | return $this->client->getHttpClient()->post( 67 | $path, 68 | $body, 69 | $headers 70 | ); 71 | } 72 | 73 | /** 74 | * @param string $path 75 | * @param array $body 76 | * @param array $headers 77 | * @return mixed 78 | * @throws \GuzzleHttp\Exception\GuzzleException 79 | */ 80 | public function put($path, $body, array $headers = []) 81 | { 82 | return $this->client->getHttpClient()->put( 83 | $path, 84 | $body, 85 | $headers 86 | ); 87 | } 88 | } -------------------------------------------------------------------------------- /src/Api/ApiInterface.php: -------------------------------------------------------------------------------- 1 | post('auth/keys', $params); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Api/Cli.php: -------------------------------------------------------------------------------- 1 | post('cli/' . $id . '/call', $params); 16 | } 17 | 18 | /** 19 | * @return mixed 20 | */ 21 | public function commands() 22 | { 23 | return $this->get('cli/commands'); 24 | } 25 | 26 | /** 27 | * @param int $id 28 | * @return mixed 29 | */ 30 | public function ref($id) 31 | { 32 | return $this->get('cli/' . $id . '/ref'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Api/Clients.php: -------------------------------------------------------------------------------- 1 | delete('clients/' . $id); 15 | } 16 | 17 | /** 18 | * @return mixed 19 | */ 20 | public function index() 21 | { 22 | return $this->get('clients'); 23 | } 24 | 25 | /** 26 | * @param int $id 27 | * @return mixed 28 | */ 29 | public function show($id) 30 | { 31 | return $this->get('clients/' . $id); 32 | } 33 | 34 | /** 35 | * @param array $params 36 | * @return mixed 37 | * @throws \GuzzleHttp\Exception\GuzzleException 38 | */ 39 | public function store($params) 40 | { 41 | return $this->post('clients', $params); 42 | } 43 | 44 | /** 45 | * @param int $id 46 | * @param array $params 47 | * @return mixed 48 | * @throws \GuzzleHttp\Exception\GuzzleException 49 | */ 50 | public function update($id, $params) 51 | { 52 | return $this->put('clients/' . $id, $params); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Api/Domains.php: -------------------------------------------------------------------------------- 1 | get('domains/' . $id . '/client'); 14 | } 15 | 16 | /** 17 | * @param int $id 18 | * @return mixed 19 | * @throws \GuzzleHttp\Exception\GuzzleException 20 | */ 21 | public function destroy($id) 22 | { 23 | return $this->delete('domains/' . $id); 24 | } 25 | 26 | /** 27 | * @return mixed 28 | */ 29 | public function index() 30 | { 31 | return $this->get('domains'); 32 | } 33 | 34 | /** 35 | * @param int $id 36 | * @return mixed 37 | */ 38 | public function show($id) 39 | { 40 | return $this->get('domains/' . $id); 41 | } 42 | 43 | /** 44 | * @param int $id 45 | * @return mixed 46 | * @throws \GuzzleHttp\Exception\GuzzleException 47 | */ 48 | public function status($id) 49 | { 50 | return $this->get('domains/' . $id . '/status'); 51 | } 52 | 53 | /** 54 | * @param array $params 55 | * @return mixed 56 | * @throws \GuzzleHttp\Exception\GuzzleException 57 | */ 58 | public function store($params) 59 | { 60 | return $this->post('domains', $params); 61 | } 62 | 63 | /** 64 | * @param int $id 65 | * @param array $params 66 | * @return mixed 67 | * @throws \GuzzleHttp\Exception\GuzzleException 68 | */ 69 | public function update($id, $params) 70 | { 71 | return $this->put('domains/' . $id, $params); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Api/Extensions.php: -------------------------------------------------------------------------------- 1 | delete('extensions/' . $identifier); 15 | } 16 | 17 | /** 18 | * @param string $identifier 19 | * @return mixed 20 | * @throws \GuzzleHttp\Exception\GuzzleException 21 | */ 22 | public function disable($identifier) 23 | { 24 | return $this->put('extensions/' . $identifier . '/disable', ''); 25 | } 26 | 27 | /** 28 | * @param string $identifier 29 | * @return mixed 30 | * @throws \GuzzleHttp\Exception\GuzzleException 31 | */ 32 | public function enable($identifier) 33 | { 34 | return $this->put('extensions/' . $identifier . '/enable', ''); 35 | } 36 | 37 | /** 38 | * @return mixed 39 | */ 40 | public function index() 41 | { 42 | return $this->get('extensions'); 43 | } 44 | 45 | /** 46 | * @param $id 47 | * @return mixed 48 | */ 49 | public function show($id) 50 | { 51 | return $this->get('extensions/' . $id); 52 | } 53 | 54 | /** 55 | * @param $params 56 | * @return mixed 57 | * @throws \GuzzleHttp\Exception\GuzzleException 58 | */ 59 | public function store($params) 60 | { 61 | return $this->post('extensions', $params); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Api/Server.php: -------------------------------------------------------------------------------- 1 | get('server'); 13 | } 14 | 15 | /** 16 | * @param arary $params 17 | * @return mixed 18 | * @throws \GuzzleHttp\Exception\GuzzleException 19 | */ 20 | public function init($params) 21 | { 22 | return $this->post('server/init', $params); 23 | } 24 | 25 | /** 26 | * @return mixed 27 | */ 28 | public function ips() 29 | { 30 | return $this->get('server/ips'); 31 | } 32 | 33 | /** 34 | * @param array $params 35 | * @return mixed 36 | * @throws \GuzzleHttp\Exception\GuzzleException 37 | */ 38 | public function license($params) 39 | { 40 | return $this->post('server/license', $params); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Client.php: -------------------------------------------------------------------------------- 1 | api($method); 24 | } catch (InvalidArgumentException $e) { 25 | throw new \BadMethodCallException(sprintf('Undefined method called:"%s"', $method)); 26 | } 27 | } 28 | 29 | /** 30 | * @param string $name 31 | * @return Api\Authentication|Api\Cli|Api\Clients|Api\Domains|Api\Extensions|Api\Server 32 | */ 33 | public function api($name) 34 | { 35 | switch ($name) { 36 | case 'authentication': 37 | $api = new \nickurt\Plesk\Api\Authentication($this); 38 | break; 39 | case 'cli': 40 | $api = new \nickurt\Plesk\Api\Cli($this); 41 | break; 42 | case 'clients': 43 | $api = new \nickurt\Plesk\Api\Clients($this); 44 | break; 45 | case 'domains': 46 | $api = new \nickurt\Plesk\Api\Domains($this); 47 | break; 48 | case 'extensions': 49 | $api = new \nickurt\Plesk\Api\Extensions($this); 50 | break; 51 | case 'server': 52 | $api = new \nickurt\Plesk\Api\Server($this); 53 | break; 54 | default: 55 | throw new \InvalidArgumentException(sprintf('Undefined method called:"%s"', $name)); 56 | break; 57 | } 58 | return $api; 59 | } 60 | 61 | /** 62 | * @param string $username 63 | * @param string $password 64 | */ 65 | public function setCredentials($username, $password) 66 | { 67 | $this->getHttpClient()->setOptions([ 68 | 'username' => $username, 69 | 'password' => $password 70 | ]); 71 | } 72 | 73 | /** 74 | * @return HttpClient 75 | */ 76 | public function getHttpClient() 77 | { 78 | if (!isset($this->httpClient)) { 79 | $this->httpClient = new HttpClient(); 80 | $this->httpClient->setOptions($this->options); 81 | } 82 | 83 | return $this->httpClient; 84 | } 85 | 86 | /** 87 | * @param string $host 88 | */ 89 | public function setHost($host) 90 | { 91 | $this->getHttpClient()->setOptions([ 92 | 'host' => $host 93 | ]); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/ClientInterface.php: -------------------------------------------------------------------------------- 1 | 'application/json', 13 | 'Accept' => 'application/json' 14 | ]; 15 | 16 | /** @var array */ 17 | protected $options = []; 18 | 19 | /** 20 | * @param $path 21 | * @param $body 22 | * @param array $headers 23 | * @return mixed 24 | * @throws \GuzzleHttp\Exception\GuzzleException 25 | */ 26 | public function delete($path, $body, array $headers = []) 27 | { 28 | return $this->request($path, $body, 'DELETE', $headers); 29 | } 30 | 31 | /** 32 | * @param string $path 33 | * @param array $body 34 | * @param string $httpMethod 35 | * @param array $headers 36 | * @param array $options 37 | * @throws \GuzzleHttp\Exception\GuzzleException 38 | */ 39 | public function request($path, $body, $httpMethod = 'GET', array $headers = [], array $options = []) 40 | { 41 | $fullPath = sprintf('%s:%d/%s/%s', $this->getOptions()['host'], '8443', 'api/v2', $path); 42 | 43 | $response = $this->getClient()->request($httpMethod, $fullPath, [ 44 | 'auth' => [$this->getOptions()['username'], $this->getOptions()['password']], 45 | 'headers' => $this->getHeaders(), 46 | 'body' => $body ? $body : null 47 | ]); 48 | 49 | return json_decode($response->getBody(), true); 50 | } 51 | 52 | /** 53 | * @return array 54 | */ 55 | public function getOptions() 56 | { 57 | return $this->options; 58 | } 59 | 60 | /** 61 | * @param array $options 62 | */ 63 | public function setOptions(array $options) 64 | { 65 | $this->options = array_merge($this->options, $options); 66 | } 67 | 68 | /** 69 | * @return \GuzzleHttp\Client 70 | */ 71 | public function getClient() 72 | { 73 | if (!isset($this->client)) { 74 | $this->client = new \GuzzleHttp\Client(); 75 | 76 | return $this->client; 77 | } 78 | 79 | return $this->client; 80 | } 81 | 82 | /** 83 | * @param $client 84 | */ 85 | public function setClient($client) 86 | { 87 | $this->client = $client; 88 | } 89 | 90 | /** 91 | * @return array 92 | */ 93 | public function getHeaders() 94 | { 95 | return $this->headers; 96 | } 97 | 98 | /** 99 | * @param array $headers 100 | */ 101 | public function setHeaders(array $headers) 102 | { 103 | $this->headers = array_merge($this->headers, $headers); 104 | } 105 | 106 | /** 107 | * @param string $path 108 | * @param array $parameters 109 | * @param array $headers 110 | * @throws \GuzzleHttp\Exception\GuzzleException 111 | */ 112 | public function get($path, array $parameters = [], array $headers = []) 113 | { 114 | return $this->request($path, $parameters, 'GET', $headers); 115 | } 116 | 117 | public function path($path, $body, array $headers = []) 118 | { 119 | // 120 | } 121 | 122 | /** 123 | * @param string $path 124 | * @param array $body 125 | * @param array $headers 126 | * @return mixed 127 | * @throws \GuzzleHttp\Exception\GuzzleException 128 | */ 129 | public function post($path, $body, array $headers = []) 130 | { 131 | return $this->request($path, $body, 'POST', $headers); 132 | } 133 | 134 | /** 135 | * @param $path 136 | * @param $body 137 | * @param array $headers 138 | * @return mixed 139 | * @throws \GuzzleHttp\Exception\GuzzleException 140 | */ 141 | public function put($path, $body, array $headers = []) 142 | { 143 | return $this->request($path, $body, 'PUT', $headers); 144 | } 145 | } -------------------------------------------------------------------------------- /src/HttpClient/HttpClientInterface.php: -------------------------------------------------------------------------------- 1 | app = $app; 23 | } 24 | 25 | /** 26 | * @param $method 27 | * @param $args 28 | * @return mixed 29 | */ 30 | public function __call($method, $args) 31 | { 32 | return call_user_func_array([$this->client, $method], $args); 33 | } 34 | 35 | /** 36 | * @param null|string $name 37 | * @return \nickurt\Plesk\Client 38 | */ 39 | public function server($name = null) 40 | { 41 | $name = $name ?: $this->getDefaultServer(); 42 | 43 | return $this->servers[$name] = $this->get($name); 44 | } 45 | 46 | /** 47 | * @return array 48 | */ 49 | public function getDefaultServer() 50 | { 51 | return $this->app['config']['plesk.default']; 52 | } 53 | 54 | /** 55 | * @param string $name 56 | * @return \nickurt\Plesk\Client 57 | */ 58 | protected function get($name) 59 | { 60 | return $this->servers[$name] ?? $this->resolve($name); 61 | } 62 | 63 | /** 64 | * @param string $name 65 | * @return \nickurt\Plesk\Client 66 | */ 67 | protected function resolve($name) 68 | { 69 | $config = $this->getConfig($name); 70 | 71 | $this->client = new \nickurt\Plesk\Client(); 72 | $this->client->setHost($config['host']); 73 | $this->client->setCredentials( 74 | $config['username'], 75 | $config['password'] 76 | ); 77 | 78 | return $this->client; 79 | } 80 | 81 | /** 82 | * @param string $name 83 | * @return array 84 | */ 85 | protected function getConfig($name) 86 | { 87 | return $this->app['config']["plesk.servers.{$name}"]; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 15 | __DIR__ . '/../config/plesk.php' => config_path('plesk.php') 16 | ], 'config'); 17 | } 18 | 19 | /** 20 | * Get the services provided by the provider. 21 | * 22 | * @return array 23 | */ 24 | public function provides() 25 | { 26 | return ['nickurt\Plesk\Plesk', 'Plesk']; 27 | } 28 | 29 | /** 30 | * Register the service provider. 31 | * 32 | * @return void 33 | */ 34 | public function register() 35 | { 36 | $this->app->singleton('nickurt\Plesk\Plesk', function ($app) { 37 | $plesk = new Plesk($app); 38 | $plesk->server($plesk->getDefaultServer()); 39 | 40 | return $plesk; 41 | }); 42 | 43 | $this->app->alias('nickurt\Plesk\Plesk', 'Plesk'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 |