PHPackages                             mikoweb/php-cli-executor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. mikoweb/php-cli-executor

ActiveLibrary[CLI &amp; Console](/categories/cli)

mikoweb/php-cli-executor
========================

PHP CLI Executor

v1.1.0(4y ago)048LGPL-3.0-or-laterPHPPHP &gt;=7.1

Since Feb 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/mikoweb/php-cli-executor)[ Packagist](https://packagist.org/packages/mikoweb/php-cli-executor)[ Docs](https://rmweb.pl)[ RSS](/packages/mikoweb-php-cli-executor/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

PHP CLI Executor library
========================

[](#php-cli-executor-library)

Library for CLI application execution with output parsing and validation.

Installation
------------

[](#installation)

```
composer require mikoweb/php-cli-executor

```

Example of use
--------------

[](#example-of-use)

In your app file:

```
require_once __DIR__ . '/vendor/autoload.php';

use Mikoweb\CLIExecutor\Executor;
use Mikoweb\CLIExecutor\Config;
use Mikoweb\CLIExecutor\Validator\Validator;
use Mikoweb\CLIExecutor\Validator\Exceptions\InvalidOutputException;

$config = new Config(__DIR__ . '/sample-cli.php'); // set path to your CLI script
// $config = new Config('cli_path', 'php_bin_or_other'); // you can set php bin path

$executor = new Executor($config);
$validator = new Validator();

$output = $executor->execute(['app:test']); // set command options, arguments etc.

try {
    $validator->validate($output);
    // $validator->validate($output, false); // if set false in second argument method not throw exception and return ValidationResultInterface

    echo $output->isSuccessful());
    echo $output->getStatus()); // output status code like http
    echo $output->getData()->get('message')); // you can get result property
    // echo $output->getData()->getData(); // or you can get full data
} catch (InvalidOutputException $exception) {
    echo $output->getErrorMessage());
    echo $output->getStatus());

    // you can access to $exception->getValidationResult(), $exception->getMessage(), $exception->getCode() etc.
}
```

Successful with WriterBuilder `sample-cli.php`:

```
require_once __DIR__ . '/vendor/autoload.php';

use Mikoweb\CLIExecutor\Writer\WriterBuilder;

$writer = new WriterBuilder();
$writer
    ->setMessage('ok')
    ->printMessageAsSuccess(true)
    ->write()
;

exit(0);
```

Failed example with WriterBuilder `sample-cli.php`:

```
$writer = new WriterBuilder();
$writer
    ->setErrorMessage("something's wrong")
    ->printErrorMessageAsError(true)
    ->setStatus(OutputStatus::STATUS_INTERNAL_ERROR)
    ->write()
;
```

Successful Raw Example `sample-cli.php`:

```
echo '
Lorem ipsum // unnecessary, example

{
    "message": "ok",
    "status": 200
}

Lorem ipsum // unnecessary, example
';

exit(0);
```

Failed Raw Example `sample-cli.php`:

```
echo '

{
    "error_message": "something\'s wrong",
    "status": 500
}

';

exit(0);
```

Failed too `sample-cli.php`:

```
exit(1);
```

Custom Output Parser
--------------------

[](#custom-output-parser)

By default, it is used JsonOutputParser. You can create your own parser e.g. XmlOutputParser:

```
class XmlOutputParser extends AbstractOutputParser
{
    public function decode(string $data): array
    {
        return simplexml_to_assoc(simplexml_load_string($data));
    }
}
```

Set the parser as an Executor argument:

```
$executor = new Executor($config, new XmlOutputParser());
```

Custom Writer Serializer
------------------------

[](#custom-writer-serializer)

By default, it is used JsonSerializer. You can create your own serializer e.g. XmlSerializer:

```
class XmlSerializer implements SerializerInterface
{
    public function serialize(array $data): string
    {
        return JMS::serialize($data, 'xml');
    }
}
```

Set the serializer as an WriterBuilder argument:

```
$writer = new WriterBuilder(new XmlSerializer());
```

Tests
-----

[](#tests)

```
php7.1 composer.phar install --dev
php7.1 ./vendor/bin/phpunit tests

```

Copyrights
----------

[](#copyrights)

Copyright (c) Rafał Mikołajun 2022.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1556d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/68263721584210e6cd329a0025d50c48be25fc6cfedb9d9f514af2f9f87b0cc6?d=identicon)[mikoweb](/maintainers/mikoweb)

---

Top Contributors

[![mikoweb](https://avatars.githubusercontent.com/u/4729995?v=4)](https://github.com/mikoweb "mikoweb (32 commits)")

---

Tags

cliclient-librarycommand-lineexecexecuteexecutorphpphpclicommandexecutorexecuteexeccli client

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mikoweb-php-cli-executor/health.svg)

```
[![Health](https://phpackages.com/badges/mikoweb-php-cli-executor/health.svg)](https://phpackages.com/packages/mikoweb-php-cli-executor)
```

###  Alternatives

[helhum/typo3-console

A reliable and powerful command line interface for TYPO3 CMS

2939.0M192](/packages/helhum-typo3-console)[seregazhuk/php-watcher

Automatically restart PHP application once the source code changes

394137.8k4](/packages/seregazhuk-php-watcher)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
