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 today

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 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

1602d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4729995?v=4)[Rafał Mikołajun](/maintainers/mikoweb)[@mikoweb](https://github.com/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

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[illuminate/console

The Illuminate Console package.

13046.0M6.5k](/packages/illuminate-console)[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

54743.1k4](/packages/jolicode-castor)[automattic/jetpack-changelogger

Jetpack Changelogger tool. Allows for managing changelogs by dropping change files into a changelog directory with each PR.

107.2M176](/packages/automattic-jetpack-changelogger)[whatsdiff/whatsdiff

See what's changed in your project's dependencies

771.2k](/packages/whatsdiff-whatsdiff)[dagger/dagger

Dagger PHP SDK

261.1k](/packages/dagger-dagger)

PHPackages © 2026

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