├── host.sample.php ├── yaml ├── state.yml └── program.yml ├── src ├── Options.php ├── Resource │ ├── Async │ │ ├── EmptyState.php │ │ ├── EmptyProgram.php │ │ ├── State.php │ │ └── Program.php │ ├── Sync │ │ ├── EmptyState.php │ │ ├── EmptyProgram.php │ │ ├── State.php │ │ └── Program.php │ ├── StateInterface.php │ ├── EmptyState.php │ ├── State.php │ ├── ProgramInterface.php │ ├── EmptyProgram.php │ └── Program.php ├── CommandBus │ ├── Command │ │ ├── PidCommand.php │ │ ├── StateCommand.php │ │ ├── RestartCommand.php │ │ ├── VersionCommand.php │ │ ├── ClearLogCommand.php │ │ ├── ProgramsCommand.php │ │ ├── ShutdownCommand.php │ │ ├── APIVersionCommand.php │ │ ├── IdentificationCommand.php │ │ ├── ProgramCommand.php │ │ ├── Program │ │ │ ├── StartCommand.php │ │ │ └── StopCommand.php │ │ └── ReadLogCommand.php │ └── Handler │ │ ├── PidHandler.php │ │ ├── RestartHandler.php │ │ ├── ClearLogHandler.php │ │ ├── ShutdownHandler.php │ │ ├── VersionHandler.php │ │ ├── APIVersionHandler.php │ │ ├── IdentificationHandler.php │ │ ├── ReadLogHandler.php │ │ ├── Program │ │ ├── StopHandler.php │ │ └── StartHandler.php │ │ ├── StateHandler.php │ │ ├── ProgramHandler.php │ │ └── ProgramsHandler.php ├── ClientInterface.php ├── AsyncClientInterface.php ├── ApiSettings.php ├── Client.php └── AsyncClient.php ├── .editorconfig ├── resources.yml ├── .php_cs ├── Makefile ├── LICENSE ├── CONTRIBUTING.md ├── README.md └── composer.json /host.sample.php: -------------------------------------------------------------------------------- 1 | setFinder( 16 | PhpCsFixer\Finder::create() 17 | ->in($paths) 18 | ->append($paths) 19 | ) 20 | ->setUsingCache(false) 21 | ; 22 | })(); 23 | -------------------------------------------------------------------------------- /src/Resource/Sync/State.php: -------------------------------------------------------------------------------- 1 | wait($this->handleCommand(new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this))->then(function (StateInterface $state) { 14 | return $state->refresh(); 15 | })); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | composer run-script qa-all --timeout=0 3 | 4 | all-coverage: 5 | composer run-script qa-all-coverage --timeout=0 6 | 7 | ci: 8 | composer run-script qa-ci --timeout=0 9 | 10 | ci-extended: 11 | composer run-script qa-ci-extended --timeout=0 12 | 13 | contrib: 14 | composer run-script qa-contrib --timeout=0 15 | 16 | init: 17 | composer ensure-installed 18 | 19 | cs: 20 | composer cs 21 | 22 | cs-fix: 23 | composer cs-fix 24 | 25 | unit: 26 | composer run-script unit --timeout=0 27 | 28 | unit-coverage: 29 | composer run-script unit-coverage --timeout=0 30 | 31 | ci-coverage: init 32 | composer ci-coverage 33 | 34 | generate-resources: init 35 | ./vendor/bin/api-client-resource-generator ./resources.yml 36 | -------------------------------------------------------------------------------- /src/ClientInterface.php: -------------------------------------------------------------------------------- 1 | name = $name; 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getName(): string 31 | { 32 | return $this->name; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandBus/Command/Program/StartCommand.php: -------------------------------------------------------------------------------- 1 | name = $name; 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getName(): string 31 | { 32 | return $this->name; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandBus/Command/Program/StopCommand.php: -------------------------------------------------------------------------------- 1 | name = $name; 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getName(): string 31 | { 32 | return $this->name; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Resource/State.php: -------------------------------------------------------------------------------- 1 | statecode; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function statename(): string 35 | { 36 | return $this->statename; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/CommandBus/Handler/PidHandler.php: -------------------------------------------------------------------------------- 1 | service = $service; 24 | } 25 | 26 | /** 27 | * @param PidCommand $command 28 | * @return PromiseInterface 29 | */ 30 | public function handle(PidCommand $command): PromiseInterface 31 | { 32 | return $this->service->call('supervisor.getPID'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandBus/Handler/RestartHandler.php: -------------------------------------------------------------------------------- 1 | service = $service; 24 | } 25 | 26 | /** 27 | * @param RestartCommand $command 28 | * @return PromiseInterface 29 | */ 30 | public function handle(RestartCommand $command): PromiseInterface 31 | { 32 | return $this->service->call('supervisor.restart'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandBus/Handler/ClearLogHandler.php: -------------------------------------------------------------------------------- 1 | service = $service; 24 | } 25 | 26 | /** 27 | * @param ClearLogCommand $command 28 | * @return PromiseInterface 29 | */ 30 | public function handle(ClearLogCommand $command): PromiseInterface 31 | { 32 | return $this->service->call('supervisor.clearLog'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandBus/Handler/ShutdownHandler.php: -------------------------------------------------------------------------------- 1 | service = $service; 24 | } 25 | 26 | /** 27 | * @param ShutdownCommand $command 28 | * @return PromiseInterface 29 | */ 30 | public function handle(ShutdownCommand $command): PromiseInterface 31 | { 32 | return $this->service->call('supervisor.shutdown'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandBus/Handler/VersionHandler.php: -------------------------------------------------------------------------------- 1 | service = $service; 24 | } 25 | 26 | /** 27 | * @param VersionCommand $command 28 | * @return PromiseInterface 29 | */ 30 | public function handle(VersionCommand $command): PromiseInterface 31 | { 32 | return $this->service->call('supervisor.getSupervisorVersion'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandBus/Handler/APIVersionHandler.php: -------------------------------------------------------------------------------- 1 | service = $service; 24 | } 25 | 26 | /** 27 | * @param APIVersionCommand $command 28 | * @return PromiseInterface 29 | */ 30 | public function handle(APIVersionCommand $command): PromiseInterface 31 | { 32 | return $this->service->call('supervisor.getAPIVersion'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/AsyncClientInterface.php: -------------------------------------------------------------------------------- 1 | service = $service; 24 | } 25 | 26 | /** 27 | * @param IdentificationCommand $command 28 | * @return PromiseInterface 29 | */ 30 | public function handle(IdentificationCommand $command): PromiseInterface 31 | { 32 | return $this->service->call('supervisor.getIdentification'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/CommandBus/Command/ReadLogCommand.php: -------------------------------------------------------------------------------- 1 | offset = $offset; 31 | $this->length = $length; 32 | } 33 | 34 | /** 35 | * @return int 36 | */ 37 | public function getOffset(): int 38 | { 39 | return $this->offset; 40 | } 41 | 42 | /** 43 | * @return int 44 | */ 45 | public function getLength(): int 46 | { 47 | return $this->length; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/CommandBus/Handler/ReadLogHandler.php: -------------------------------------------------------------------------------- 1 | service = $service; 24 | } 25 | 26 | /** 27 | * @param ReadLogCommand $command 28 | * @return PromiseInterface 29 | */ 30 | public function handle(ReadLogCommand $command): PromiseInterface 31 | { 32 | return $this->service->call( 33 | 'supervisor.readLog', 34 | [ 35 | $command->getOffset(), 36 | $command->getLength(), 37 | ] 38 | ); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Cees-Jan Kiewiet 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Pull requests are highly appreciated. Here's a quick guide. 4 | 5 | Fork, then clone the repo: 6 | 7 | git clone git@github.com:your-username/supervisord.git 8 | 9 | Set up your machine: 10 | 11 | composer install 12 | 13 | Make sure the tests pass: 14 | 15 | make unit 16 | 17 | Make sure the tests pass on all supported PHP versions (requires docker): 18 | 19 | make dunit 20 | 21 | Make your change. Add tests for your change. Make the tests pass: 22 | 23 | make dunit && make unit 24 | 25 | Before committing and submitting your pull request make sure it passes PSR2 coding style, unit tests pass and pass on all supported PHP versions: 26 | 27 | make contrib 28 | 29 | Push to your fork and [submit a pull request][pr]. 30 | 31 | [pr]: https://help.github.com/articles/creating-a-pull-request/ 32 | 33 | At this point you're waiting on me. I like to at least comment on pull requests 34 | within a day or two. I may suggest some changes or improvements or alternatives. 35 | 36 | Some things that will increase the chance that your pull request is accepted: 37 | 38 | * Write tests. 39 | * Follow PSR2 (travis will also check for this). 40 | * Write a [good commit message][commit]. 41 | 42 | [commit]: http://chris.beams.io/posts/git-commit/ 43 | -------------------------------------------------------------------------------- /src/CommandBus/Handler/Program/StopHandler.php: -------------------------------------------------------------------------------- 1 | service = $service; 32 | $this->hydrator = $hydrator; 33 | } 34 | 35 | /** 36 | * @param ProgramsCommand $command 37 | * @return PromiseInterface 38 | */ 39 | public function handle(StopCommand $command): PromiseInterface 40 | { 41 | return $this->service->call( 42 | 'supervisor.stopProcess', 43 | [ 44 | $command->getName(), 45 | ] 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/CommandBus/Handler/Program/StartHandler.php: -------------------------------------------------------------------------------- 1 | service = $service; 32 | $this->hydrator = $hydrator; 33 | } 34 | 35 | /** 36 | * @param ProgramsCommand $command 37 | * @return PromiseInterface 38 | */ 39 | public function handle(StartCommand $command): PromiseInterface 40 | { 41 | return $this->service->call( 42 | 'supervisor.startProcess', 43 | [ 44 | $command->getName(), 45 | ] 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Resource/Async/Program.php: -------------------------------------------------------------------------------- 1 | handleCommand(new ProgramCommand($this->name)); 16 | } 17 | 18 | /** 19 | * Reason behind the enable/disable names is that start is in 20 | * use by an property. 21 | * 22 | * @return PromiseInterface 23 | */ 24 | public function enable(): PromiseInterface 25 | { 26 | return $this->handleCommand(new StartCommand($this->name)); 27 | } 28 | 29 | public function disable(): PromiseInterface 30 | { 31 | return $this->handleCommand(new StopCommand($this->name)); 32 | } 33 | 34 | public function restart(): PromiseInterface 35 | { 36 | return $this->disable()->then(function () { 37 | return $this->enable(); 38 | })->then(function () { 39 | return $this->refresh(); 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/CommandBus/Handler/StateHandler.php: -------------------------------------------------------------------------------- 1 | service = $service; 33 | $this->hydrator = $hydrator; 34 | } 35 | 36 | /** 37 | * @param StateCommand $command 38 | * @return PromiseInterface 39 | */ 40 | public function handle(StateCommand $command): PromiseInterface 41 | { 42 | return $this->service->call('supervisor.getState')->then(function (array $state) { 43 | return resolve( 44 | $this->hydrator->hydrate( 45 | StateInterface::HYDRATE_CLASS, 46 | $state 47 | ) 48 | ); 49 | }); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Resource/Sync/Program.php: -------------------------------------------------------------------------------- 1 | wait($this->handleCommand(new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this))->then(function (ProgramInterface $program) { 14 | return $program->refresh(); 15 | })); 16 | } 17 | 18 | public function enable(): bool 19 | { 20 | return $this->wait($this->handleCommand(new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this))->then(function (ProgramInterface $program) { 21 | return $program->enable(); 22 | })); 23 | } 24 | 25 | public function disable(): bool 26 | { 27 | return $this->wait($this->handleCommand(new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this))->then(function (ProgramInterface $program) { 28 | return $program->disable(); 29 | })); 30 | } 31 | 32 | public function restart(): Program 33 | { 34 | return $this->wait($this->handleCommand(new BuildAsyncFromSyncCommand(self::HYDRATE_CLASS, $this))->then(function (ProgramInterface $program) { 35 | return $program->restart(); 36 | })); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Resource/ProgramInterface.php: -------------------------------------------------------------------------------- 1 | service = $service; 34 | $this->hydrator = $hydrator; 35 | } 36 | 37 | /** 38 | * @param ProgramsCommand $command 39 | * @return PromiseInterface 40 | */ 41 | public function handle(ProgramCommand $command): PromiseInterface 42 | { 43 | return $this->service->call( 44 | 'supervisor.getProcessInfo', 45 | [ 46 | $command->getName(), 47 | ] 48 | )->then(function (array $program) { 49 | return resolve( 50 | $this->hydrator->hydrate( 51 | ProgramInterface::HYDRATE_CLASS, 52 | $program 53 | ) 54 | ); 55 | }); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/CommandBus/Handler/ProgramsHandler.php: -------------------------------------------------------------------------------- 1 | service = $service; 34 | $this->hydrator = $hydrator; 35 | } 36 | 37 | /** 38 | * @param ProgramsCommand $command 39 | * @return PromiseInterface 40 | */ 41 | public function handle(ProgramsCommand $command): PromiseInterface 42 | { 43 | return $this->service->call('supervisor.getAllProcessInfo')->then(function (array $xml) { 44 | return resolve( 45 | observableFromArray( 46 | $xml 47 | )->map(function ($program) { 48 | return $this->hydrator->hydrate( 49 | ProgramInterface::HYDRATE_CLASS, 50 | $program 51 | ); 52 | }) 53 | ); 54 | }); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Resource/EmptyProgram.php: -------------------------------------------------------------------------------- 1 | state()->done(function (StateInterface $state) { 32 | resource_pretty_print($state); 33 | }); 34 | 35 | $loop->run(); 36 | 37 | ``` 38 | 39 | For more examples check the [examples](examples) directory. 40 | 41 | # License 42 | 43 | The MIT License (MIT) 44 | 45 | Copyright (c) 2017 Cees-Jan Kiewiet 46 | 47 | Permission is hereby granted, free of charge, to any person obtaining a copy 48 | of this software and associated documentation files (the "Software"), to deal 49 | in the Software without restriction, including without limitation the rights 50 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 51 | copies of the Software, and to permit persons to whom the Software is 52 | furnished to do so, subject to the following conditions: 53 | 54 | The above copyright notice and this permission notice shall be included in all 55 | copies or substantial portions of the Software. 56 | 57 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 58 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 59 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 60 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 61 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 62 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 63 | SOFTWARE. 64 | -------------------------------------------------------------------------------- /src/ApiSettings.php: -------------------------------------------------------------------------------- 1 | [ 25 | HydratorOptions::NAMESPACE => self::NAMESPACE, 26 | HydratorOptions::NAMESPACE_DIR => __DIR__ . DIRECTORY_SEPARATOR . 'Resource' . DIRECTORY_SEPARATOR, 27 | ], 28 | FoundationOptions::TRANSPORT_OPTIONS => [ 29 | TransportOptions::SCHEMA => 'http', 30 | TransportOptions::PATH => '/RPC2', 31 | TransportOptions::MIDDLEWARE => [ 32 | HttpExceptionsMiddleware::class, 33 | UserAgentMiddleware::class, 34 | XmlEncodeMiddleware::class, 35 | XmlDecodeMiddleware::class, 36 | ], 37 | TransportOptions::DEFAULT_REQUEST_OPTIONS => [ 38 | UserAgentMiddleware::class => [ 39 | UserAgentMiddlewareOptions::STRATEGY => UserAgentStrategies::PACKAGE_VERSION, 40 | UserAgentMiddlewareOptions::PACKAGE => 'api-clients/supervisord', 41 | ], 42 | ], 43 | ], 44 | ]; 45 | 46 | public static function getOptions(string $host, array $suppliedOptions, string $suffix): array 47 | { 48 | $options = options_merge(self::TRANSPORT_OPTIONS, $suppliedOptions); 49 | $options[FoundationOptions::HYDRATOR_OPTIONS][HydratorOptions::NAMESPACE_SUFFIX] = $suffix; 50 | 51 | $transportOptions = $options[FoundationOptions::TRANSPORT_OPTIONS]; 52 | 53 | list($ip, $port) = explode(':', $host); 54 | $transportOptions[TransportOptions::HOST] = $ip; 55 | $transportOptions[TransportOptions::PORT] = $port; 56 | 57 | if (isset($suppliedOptions[Options::USERNAME])) { 58 | $transportOptions[TransportOptions::MIDDLEWARE][] = BasicAuthorizationHeaderMiddleware::class; 59 | $transportOptions[TransportOptions::DEFAULT_REQUEST_OPTIONS][BasicAuthorizationHeaderMiddleware::class] = [ 60 | BasicAuthorizationHeaderMiddlewareOptions::USERNAME => $suppliedOptions[Options::USERNAME], 61 | BasicAuthorizationHeaderMiddlewareOptions::PASSWORD => $suppliedOptions[Options::PASSWORD] ?? '', 62 | ]; 63 | } 64 | 65 | $options[FoundationOptions::TRANSPORT_OPTIONS] = $transportOptions; 66 | 67 | return $options; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "api-clients/supervisord", 3 | "description": "Async first Supervisord XML-RPC client", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "Cees-Jan Kiewiet", 8 | "email": "ceesjank@gmail.com" 9 | } 10 | ], 11 | "require": { 12 | "php": "^7.0", 13 | "api-clients/client-services": "^1.3", 14 | "api-clients/foundation": "^1.0", 15 | "api-clients/middleware-basic-authorization": "^3.0", 16 | "api-clients/middleware-http-exceptions": "^2.0", 17 | "api-clients/middleware-user-agent": "^2.0", 18 | "api-clients/middleware-xml": "^1.0", 19 | "api-clients/rx": "^2.2", 20 | "api-clients/transport": "^3.1", 21 | "api-clients/xml-rpc-service": "^1.0" 22 | }, 23 | "require-dev": { 24 | "api-clients/resource-generator": "^1.0", 25 | "api-clients/resource-test-utilities": "^1.0", 26 | "api-clients/test-utilities": "^4.3" 27 | }, 28 | "autoload": { 29 | "psr-4": { 30 | "ApiClients\\Client\\Supervisord\\": "src/" 31 | } 32 | }, 33 | "autoload-dev": { 34 | "psr-4": { 35 | "MyVendor\\Tests\\Client\\Supervisord\\": "tests/" 36 | } 37 | }, 38 | "config": { 39 | "sort-packages": true, 40 | "platform": { 41 | "php": "7.0" 42 | } 43 | }, 44 | "extra": { 45 | "api-clients": { 46 | "command-bus": { 47 | "path": "src/CommandBus", 48 | "namespace": "ApiClients\\Client\\Supervisord\\CommandBus" 49 | } 50 | } 51 | }, 52 | "scripts": { 53 | "ensure-installed": "composer install --ansi -n -q", 54 | "generate-resources": [ 55 | "@ensure-installed", 56 | "api-client-resource-generator ./resources.yml" 57 | ], 58 | "cs": [ 59 | "@ensure-installed", 60 | "php-cs-fixer fix --config=.php_cs --ansi --dry-run --diff --verbose --allow-risky=yes --show-progress=estimating" 61 | ], 62 | "cs-fix": [ 63 | "@ensure-installed", 64 | "php-cs-fixer fix --config=.php_cs --ansi --verbose --allow-risky=yes --show-progress=estimating" 65 | ], 66 | "unit": [ 67 | "@ensure-installed", 68 | "phpunit --colors=always -c phpunit.xml.dist" 69 | ], 70 | "unit-coverage": [ 71 | "@ensure-installed", 72 | "phpunit --colors=always -c phpunit.xml.dist --coverage-text --coverage-html covHtml --coverage-clover ./build/logs/clover.xml" 73 | ], 74 | "lint-php": [ 75 | "@ensure-installed", 76 | "parallel-lint --exclude vendor ." 77 | ], 78 | "qa-all": [ 79 | "@lint-php", 80 | "@cs", 81 | "@unit" 82 | ], 83 | "qa-all-coverage": [ 84 | "@lint-php", 85 | "@cs", 86 | "@unit-coverage" 87 | ], 88 | "qa-windows": [ 89 | "@lint-php", 90 | "@cs", 91 | "@unit" 92 | ], 93 | "qa-ci": [ 94 | "@unit" 95 | ], 96 | "qa-ci-extended": [ 97 | "@qa-all-coverage" 98 | ], 99 | "qa-ci-windows": [ 100 | "@qa-windows" 101 | ], 102 | "qa-contrib": [ 103 | "@qa-all" 104 | ], 105 | "ci-coverage": [ 106 | "if [ -f ./build/logs/clover.xml ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover ./build/logs/clover.xml; fi" 107 | ] 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/Resource/Program.php: -------------------------------------------------------------------------------- 1 | group; 89 | } 90 | 91 | /** 92 | * @return string 93 | */ 94 | public function name(): string 95 | { 96 | return $this->name; 97 | } 98 | 99 | /** 100 | * @return int 101 | */ 102 | public function pid(): int 103 | { 104 | return $this->pid; 105 | } 106 | 107 | /** 108 | * @return string 109 | */ 110 | public function description(): string 111 | { 112 | return $this->description; 113 | } 114 | 115 | /** 116 | * @return int 117 | */ 118 | public function state(): int 119 | { 120 | return $this->state; 121 | } 122 | 123 | /** 124 | * @return string 125 | */ 126 | public function statename(): string 127 | { 128 | return $this->statename; 129 | } 130 | 131 | /** 132 | * @return int 133 | */ 134 | public function now(): int 135 | { 136 | return (int)$this->now; 137 | } 138 | 139 | /** 140 | * @return int 141 | */ 142 | public function start(): int 143 | { 144 | return (int)$this->start; 145 | } 146 | 147 | /** 148 | * @return int 149 | */ 150 | public function stop(): int 151 | { 152 | return (int)$this->stop; 153 | } 154 | 155 | /** 156 | * @return string 157 | */ 158 | public function spawnerr(): string 159 | { 160 | return $this->spawnerr; 161 | } 162 | 163 | /** 164 | * @return int 165 | */ 166 | public function exitstatus(): int 167 | { 168 | return $this->exitstatus; 169 | } 170 | 171 | /** 172 | * @return string 173 | */ 174 | public function logfile(): string 175 | { 176 | return $this->logfile; 177 | } 178 | 179 | /** 180 | * @return string 181 | */ 182 | public function stdoutLogfile(): string 183 | { 184 | return $this->stdout_logfile; 185 | } 186 | 187 | /** 188 | * @return string 189 | */ 190 | public function stderrLogfile(): string 191 | { 192 | return $this->stderr_logfile; 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /src/Client.php: -------------------------------------------------------------------------------- 1 | loop = $loop; 33 | $this->client = $client; 34 | } 35 | 36 | /** 37 | * @param array $options 38 | * @return Client 39 | */ 40 | public static function create(string $host, array $options = []): self 41 | { 42 | $loop = Factory::create(); 43 | $options = ApiSettings::getOptions($host, $options, 'Sync'); 44 | $client = FoundationClientFactory::create($loop, $options); 45 | setAsyncScheduler($loop); 46 | $asyncClient = AsyncClient::createFromClient($client); 47 | 48 | return new self($loop, $asyncClient); 49 | } 50 | 51 | /** 52 | * @return string 53 | */ 54 | public function APIVersion(): string 55 | { 56 | return await( 57 | $this->client->APIVersion(), 58 | $this->loop 59 | ); 60 | } 61 | 62 | /** 63 | * @return string 64 | */ 65 | public function version(): string 66 | { 67 | return await( 68 | $this->client->version(), 69 | $this->loop 70 | ); 71 | } 72 | 73 | /** 74 | * @return string 75 | */ 76 | public function identification(): string 77 | { 78 | return await( 79 | $this->client->identification(), 80 | $this->loop 81 | ); 82 | } 83 | 84 | /** 85 | * @return StateInterface 86 | */ 87 | public function state(): StateInterface 88 | { 89 | return await( 90 | $this->client->state(), 91 | $this->loop 92 | ); 93 | } 94 | 95 | /** 96 | * @return string 97 | */ 98 | public function readLog(int $offset = 0, int $length = 0): string 99 | { 100 | return await( 101 | $this->client->readLog($offset, $length), 102 | $this->loop 103 | ); 104 | } 105 | 106 | /** 107 | * @return bool 108 | */ 109 | public function clearLog(): bool 110 | { 111 | return await( 112 | $this->client->clearLog(), 113 | $this->loop 114 | ); 115 | } 116 | 117 | /** 118 | * @return int 119 | */ 120 | public function pid(): int 121 | { 122 | return await( 123 | $this->client->pid(), 124 | $this->loop 125 | ); 126 | } 127 | 128 | /** 129 | * @return bool 130 | */ 131 | public function restart(): bool 132 | { 133 | return await( 134 | $this->client->restart(), 135 | $this->loop 136 | ); 137 | } 138 | 139 | /** 140 | * @return bool 141 | */ 142 | public function shutdown(): bool 143 | { 144 | return await( 145 | $this->client->shutdown(), 146 | $this->loop 147 | ); 148 | } 149 | 150 | /** 151 | * @return array 152 | */ 153 | public function programs(): array 154 | { 155 | return await( 156 | Promise::fromObservable( 157 | $this->client->programs()->toArray() 158 | ), 159 | $this->loop 160 | ); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /src/AsyncClient.php: -------------------------------------------------------------------------------- 1 | client = $client; 38 | } 39 | 40 | /** 41 | * @param LoopInterface $loop 42 | * @param array $options 43 | * @return AsyncClient 44 | */ 45 | public static function create(string $host, LoopInterface $loop, array $options = []): self 46 | { 47 | $options = ApiSettings::getOptions($host, $options, 'Async'); 48 | $client = Factory::create($loop, $options); 49 | 50 | return new self($client); 51 | } 52 | 53 | /** 54 | * @internal 55 | * @param ClientInterface $client 56 | * @return AsyncClient 57 | */ 58 | public static function createFromClient(ClientInterface $client): self 59 | { 60 | return new self($client); 61 | } 62 | 63 | public function hydrate(string $resource): CancellablePromiseInterface 64 | { 65 | return $this->client->hydrate($resource); 66 | } 67 | 68 | public function extract(ResourceInterface $resource): CancellablePromiseInterface 69 | { 70 | return $this->client->extract($resource); 71 | } 72 | 73 | public function APIVersion(): CancellablePromiseInterface 74 | { 75 | return $this->client->handle(new APIVersionCommand()); 76 | } 77 | 78 | public function version(): CancellablePromiseInterface 79 | { 80 | return $this->client->handle(new VersionCommand()); 81 | } 82 | 83 | public function identification(): CancellablePromiseInterface 84 | { 85 | return $this->client->handle(new IdentificationCommand()); 86 | } 87 | 88 | public function state(): CancellablePromiseInterface 89 | { 90 | return $this->client->handle(new StateCommand()); 91 | } 92 | 93 | public function readLog(int $offset = 0, int $length = 0): CancellablePromiseInterface 94 | { 95 | return $this->client->handle(new ReadLogCommand($offset, $length)); 96 | } 97 | 98 | public function clearLog(): CancellablePromiseInterface 99 | { 100 | return $this->client->handle(new ClearLogCommand()); 101 | } 102 | 103 | public function pid(): CancellablePromiseInterface 104 | { 105 | return $this->client->handle(new PidCommand()); 106 | } 107 | 108 | public function restart(): CancellablePromiseInterface 109 | { 110 | return $this->client->handle(new RestartCommand()); 111 | } 112 | 113 | public function shutdown(): CancellablePromiseInterface 114 | { 115 | return $this->client->handle(new ShutdownCommand()); 116 | } 117 | 118 | public function programs(): Observable 119 | { 120 | return unwrapObservableFromPromise($this->client->handle(new ProgramsCommand())); 121 | } 122 | } 123 | --------------------------------------------------------------------------------