PHPackages                             flo/nimic - 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. flo/nimic

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

flo/nimic
=========

A console app backbone with a cacheable dependency injection container

0.1(11y ago)333MITPHPPHP &gt;=5.4.0

Since Oct 9Pushed 11y ago1 watchersCompare

[ Source](https://github.com/florinutz/nimic)[ Packagist](https://packagist.org/packages/flo/nimic)[ RSS](/packages/flo-nimic/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

Nimic
=====

[](#nimic)

Nimic provides a good starting point for a php console application. Its purpose is to provide a base for your code with access to a (cacheable) dependency injection container, a console application ready to carry (symfony) commands, an event dispatcher and a monolog instance and phpunit. It's basically a facade built upon symfony components.

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

[](#installation)

You can clone the \[github repo\]\[1\], but the recommended method is through composer. Require \[flo / nimic\]\[2\] in your composer.json.

Basic usage
-----------

[](#basic-usage)

Inside your app put this in somefile.php

```
/**
 * composer  autoloader:
 */
require 'vendor/autoload.php';

$kernel = new \Flo\Nimic\Kernel\NimiKernel; //extend this kernel!

/**
 * This is a Symfony2 container
 */
$container = $kernel->getContainer();

/**
 * with some predefined services, like this (Console Component) application
 */
$app = $container->get('app');

/**
 * on which you should add your own commands:
 */
$app->add(new MyCommand);

/**
 * before running it
 */
$app->run();
```

Create your commands \[like this\]\[3\].

Adding a new service
--------------------

[](#adding-a-new-service)

You have to

1. \[create your extension\]\[5\] class
2. using the extension, \[add the command service definition\]\[4\] to the container.
3. (optional) If the service is a command, an event listener or subscriber then you should tag it with **command**, **listener** or **subscriber**. See \[this\]\[7\] for events.

In order to register your extension with the container, you'll have to \[override\]\[8\] NimiKernel::getExtensions(). This method should return an array of your ExtensionInterface instances, and it's quite possible that you'll need only one extension.

```
class YourCustomKernel extends \Flo\Nimic\Kernel\NimiKernel
{
    ...
    /**
     * @return array Array of your own extensions
     */
    protected function getExtensions()
    {
        return [
            new YourExtension()
        ];
    }
    ...
}
```

And then continue with the basic usage example, but instead of

```
$kernel = new \Flo\Nimic\Kernel\NimiKernel;
```

do

```
$kernel = new YourCustomKernel;
```

Again, using the extension, you can add (or override) any container service, not just Command classes.

example.php
-----------

[](#examplephp)

```
#!/usr/bin/env php
