{"id":22188959,"url":"https://github.com/mikoweb/php-cli-executor","last_synced_at":"2025-07-30T07:39:55.421Z","repository":{"id":62528731,"uuid":"458611239","full_name":"mikoweb/php-cli-executor","owner":"mikoweb","description":"PHP CLI Executor library","archived":false,"fork":false,"pushed_at":"2022-02-13T02:06:25.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-30T00:32:10.460Z","etag":null,"topics":["cli","client-library","command-line","exec","execute","executor","php"],"latest_commit_sha":null,"homepage":"https://rmweb.pl","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikoweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-12T18:52:01.000Z","updated_at":"2022-02-12T21:38:39.000Z","dependencies_parsed_at":"2022-11-02T11:01:15.389Z","dependency_job_id":null,"html_url":"https://github.com/mikoweb/php-cli-executor","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikoweb%2Fphp-cli-executor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikoweb%2Fphp-cli-executor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikoweb%2Fphp-cli-executor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikoweb%2Fphp-cli-executor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikoweb","download_url":"https://codeload.github.com/mikoweb/php-cli-executor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245344006,"owners_count":20599867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","client-library","command-line","exec","execute","executor","php"],"created_at":"2024-12-02T11:13:52.247Z","updated_at":"2025-03-24T20:16:57.204Z","avatar_url":"https://github.com/mikoweb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP CLI Executor library\n\nLibrary for CLI application execution with output parsing and validation.\n\n## Installation\n\n    composer require mikoweb/php-cli-executor\n\n## Example of use\n\nIn your app file:\n\n```php\nrequire_once __DIR__ . '/vendor/autoload.php';\n\nuse Mikoweb\\CLIExecutor\\Executor;\nuse Mikoweb\\CLIExecutor\\Config;\nuse Mikoweb\\CLIExecutor\\Validator\\Validator;\nuse Mikoweb\\CLIExecutor\\Validator\\Exceptions\\InvalidOutputException;\n\n$config = new Config(__DIR__ . '/sample-cli.php'); // set path to your CLI script\n// $config = new Config('cli_path', 'php_bin_or_other'); // you can set php bin path\n\n$executor = new Executor($config);\n$validator = new Validator();\n\n$output = $executor-\u003eexecute(['app:test']); // set command options, arguments etc.\n\ntry {\n    $validator-\u003evalidate($output);\n    // $validator-\u003evalidate($output, false); // if set false in second argument method not throw exception and return ValidationResultInterface\n\n    echo $output-\u003eisSuccessful());\n    echo $output-\u003egetStatus()); // output status code like http\n    echo $output-\u003egetData()-\u003eget('message')); // you can get result property\n    // echo $output-\u003egetData()-\u003egetData(); // or you can get full data\n} catch (InvalidOutputException $exception) {\n    echo $output-\u003egetErrorMessage());\n    echo $output-\u003egetStatus());\n    \n    // you can access to $exception-\u003egetValidationResult(), $exception-\u003egetMessage(), $exception-\u003egetCode() etc. \n}\n```\n\nSuccessful with WriterBuilder `sample-cli.php`:\n\n```php\nrequire_once __DIR__ . '/vendor/autoload.php';\n\nuse Mikoweb\\CLIExecutor\\Writer\\WriterBuilder;\n\n$writer = new WriterBuilder();\n$writer\n    -\u003esetMessage('ok')\n    -\u003eprintMessageAsSuccess(true)\n    -\u003ewrite()\n;\n\nexit(0);\n```\n\nFailed example with WriterBuilder `sample-cli.php`:\n\n```php\n$writer = new WriterBuilder();\n$writer\n    -\u003esetErrorMessage(\"something's wrong\")\n    -\u003eprintErrorMessageAsError(true)\n    -\u003esetStatus(OutputStatus::STATUS_INTERNAL_ERROR)\n    -\u003ewrite()\n;\n```\n\nSuccessful Raw Example `sample-cli.php`:\n\n```php\necho '\nLorem ipsum // unnecessary, example\n\n\u003coutput\u003e\n{\n    \"message\": \"ok\",\n    \"status\": 200\n}\n\u003c/output\u003e\n\nLorem ipsum // unnecessary, example\n';\n\nexit(0);\n```\n\nFailed Raw Example `sample-cli.php`:\n\n```php\necho '\n\u003coutput\u003e\n{\n    \"error_message\": \"something\\'s wrong\",\n    \"status\": 500\n}\n\u003c/output\u003e\n';\n\nexit(0);\n```\n\nFailed too `sample-cli.php`:\n\n```php\nexit(1);\n```\n\n## Custom Output Parser\n\nBy default, it is used JsonOutputParser. You can create your own parser e.g. XmlOutputParser:\n\n```php\nclass XmlOutputParser extends AbstractOutputParser\n{\n    public function decode(string $data): array\n    {\n        return simplexml_to_assoc(simplexml_load_string($data));\n    }\n}\n```\n\nSet the parser as an Executor argument:\n\n```php\n$executor = new Executor($config, new XmlOutputParser());\n```\n\n## Custom Writer Serializer\n\nBy default, it is used JsonSerializer. You can create your own serializer e.g. XmlSerializer:\n\n```php\nclass XmlSerializer implements SerializerInterface\n{\n    public function serialize(array $data): string\n    {\n        return JMS::serialize($data, 'xml');\n    }\n}\n```\n\nSet the serializer as an WriterBuilder argument:\n\n```php\n$writer = new WriterBuilder(new XmlSerializer());\n```\n\n## Tests\n\n    php7.1 composer.phar install --dev\n    php7.1 ./vendor/bin/phpunit tests\n\n## Copyrights\n\nCopyright (c) Rafał Mikołajun 2022.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikoweb%2Fphp-cli-executor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikoweb%2Fphp-cli-executor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikoweb%2Fphp-cli-executor/lists"}