PHPackages                             herrera-io/cli-app - 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. herrera-io/cli-app

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

herrera-io/cli-app
==================

A service container-based Symfony Console application template.

2.0.0(12y ago)1178041MITPHPPHP &gt;=5.3.3

Since Feb 5Pushed 12y agoCompare

[ Source](https://github.com/kherge-archive/php-cli-app)[ Packagist](https://packagist.org/packages/herrera-io/cli-app)[ Docs](http://herrera-io.github.com/php-cli-app)[ RSS](/packages/herrera-io-cli-app/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (6)Used By (1)

CLI App
=======

[](#cli-app)

[![Build Status](https://camo.githubusercontent.com/f9d5979abf714fc6189a1c7317b21f32f739494e022c5eacb9fffc187981434b/68747470733a2f2f7472617669732d63692e6f72672f686572726572612d696f2f7068702d636c692d6170702e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/herrera-io/php-cli-app)

CLI App is a template for creating console applications based on Symfony [Console](http://symfony.com/doc/current/components/console/index.html) and the Herrera.io [Service Container](https://github.com/herrera-io/php-service-container). Think Silex, but for console applications, and easier.

Example
-------

[](#example)

```
use Herrera\Cli\Application;

$app = new Application(
    array(
        'app.name' => 'MyApp',
        'app.version' => '1.2.3',
    )
);

$myCommand = $app->add(
    'myCommand',
    function ($in, $out) {
        $out->writeln('Hello, ' . $in->getArgument('name') . '!');

        return 123;
    }
);

$myCommand->addArgument('name');

$app->run();
```

Running the example:

```
$ php myApp.php myCommand world
Hello, world!

```

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

[](#installation)

Add it to your list of Composer dependencies:

```
$ composer require "herrera-io/cli-app=~2.0"
```

Usage
-----

[](#usage)

Creating a new application is as simple as instantiating the `Application`class. The class itself is an extension of the `Container` class from the Herrera.io service container library.

```
use Herrera\Cli\Application;

$app = new Application(
    array(
        'app.name' => 'Example',
        'app.version' => '1.0',
    )
);
```

> The purpose of `app.name` and `app.version` will be later discussed in the section titled **Configuration**. It is one of many customizable options for the application.

### Default Services

[](#default-services)

When the application is instantiated two services are registered:

- `Herrera\Cli\Provider\ErrorHandlingServiceProvider` — Replaces the current error handler with one provided by the service. The custom error handler will simply convert all errors into instances of `ErrorException`and throw them. The handler will respect the current `error_reporting()`setting.
- `Herrera\Cli\Provider\ConsoleServiceProvider` — The console service provider that is used by the application to configure, add commands, add helpers, and run.

The `Application` class is designed so that you can replace the default registered services by overriding a single method. You can also extend the method to register additional default services.

```
class CustomApplication extends Application
{
    /**
     * @override
     */
    protected function registerDefaultServices()
    {
        parent::registerDefaultServices();

        $this->register(new Service());
    }
}
```

### Adding a Command

[](#adding-a-command)

To add a new command to the application, you will need to call the `add()`method. This method will create a new command and return it for further, optional, configuration. The command returned is an instance of the `Symfony\Component\Console\Command\Command` class.

```
$command = $app->add(
    'commandName',
    function ($in, $out) {
        // command code
    }
);

$command->addArgument('argumentName');
```

### Adding a Helper

[](#adding-a-helper)

To add a helper to the application, you will need to call the `set()` method. This method will register the helper with the current helper set. Any instance of `Symfony\Component\Console\Helper\HelperInterface` is accepted.

```
$app->set(new Helper());
```

### App Container as Helper

[](#app-container-as-helper)

The `Application` container is registered as a helper in the console instance. This will make it easier to access the container in order to use other services within a command that extends the `Command` class.

```
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CustomCommand extends Command
{
    protected function configure()
    {
        $this->setName('customCommand');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $app = $this->getHelperSet()->get('app');
    }
}
```

### Running

[](#running)

Running the application is simple:

```
$status = $app->run();
```

If auto exiting is disabled, `$status` will hold the exit status code.

### Configuration

[](#configuration)

The majority of the all available configuration parameters and servics lie within the `ConsoleServiceProvider` that is registered with the `Application`service container. The default parameters and services can be modified until the `console` service is used. Any further changes will not take any effect.

These are the default console parameters:

```
use Symfony\Component\Console\Output\ConsoleOutput;

array(
    // the name of the application
    'app.name' => 'UNKNOWN',

    // the version of the application
    'app.version' => 'UNKNOWN',

    // automatically exit once the app has run?
    'console.auto_exist' => true,

    // the overriding list of $_SERVER['argv'] values
    'console.input.argv' => null,

    // the default array of input definitions
    'console.input.definition' => null,

    // the default verbosity level
    'console.output.verbosity' => ConsoleOutput::VERBOSITY_NORMAL,

    // the default "use decorator" flag
    'console.output.decorator' => null,
)
```

These are the default console services:

```
// the Symfony `Console` instance
$app['console'];

// creates new `Command` instances
$app['console.command_factory'];

// the Symfony `ArgvInput` instance
$app['console.input'];

// the Symfony `ConsoleOutput` instance
$app['console.output'];

// the Symfony `OutputFormatter` instance
$app['console.output.formatter'];

// runs `Application->run()` with input and output services
$app['console.run'];
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 96.4% 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 ~46 days

Total

5

Last Release

4667d ago

Major Versions

1.0.x-dev → 2.0.02013-08-07

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/9122157?v=4)[Kevin Herrera](/maintainers/kherge)[@kherge](https://github.com/kherge)

---

Top Contributors

[![kherge](https://avatars.githubusercontent.com/u/9122157?v=4)](https://github.com/kherge "kherge (27 commits)")[![ciarand](https://avatars.githubusercontent.com/u/2149341?v=4)](https://github.com/ciarand "ciarand (1 commits)")

---

Tags

cliconsole

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/herrera-io-cli-app/health.svg)

```
[![Health](https://phpackages.com/badges/herrera-io-cli-app/health.svg)](https://phpackages.com/packages/herrera-io-cli-app)
```

###  Alternatives

[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k331.8M8.5k](/packages/nunomaduro-collision)[nunomaduro/termwind

It's like Tailwind CSS, but for the console.

2.5k239.8M286](/packages/nunomaduro-termwind)[helhum/typo3-console

A reliable and powerful command line interface for TYPO3 CMS

2939.0M192](/packages/helhum-typo3-console)[buggregator/trap

A simple and powerful tool for debugging PHP applications.

2591.7M40](/packages/buggregator-trap)[laminas/laminas-cli

Command-line interface for Laminas projects

563.7M54](/packages/laminas-laminas-cli)[alecrabbit/php-console-spinner

Extremely flexible spinner for \[async\] php cli applications

24032.0k2](/packages/alecrabbit-php-console-spinner)

PHPackages © 2026

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