PHPackages                             ricardoper/micra - 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. [Framework](/categories/framework)
4. /
5. ricardoper/micra

AbandonedArchivedLibrary[Framework](/categories/framework)

ricardoper/micra
================

CLI framework for your apps with a minimum overhead based on Symfony Components

v2.0.0(5y ago)14MITPHPPHP ^7.2.5

Since May 8Pushed 5y agoCompare

[ Source](https://github.com/ricardoper/micra)[ Packagist](https://packagist.org/packages/ricardoper/micra)[ Docs](https://github.com/ricardoper)[ RSS](/packages/ricardoper-micra/feed)WikiDiscussions master Synced 1w ago

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

PHP Micra Framework for CLI Apps
================================

[](#php-micra-framework-for-cli-apps)

**Micra** is a CLI framework for your apps with a minimum overhead based on [Symfony Components](https://symfony.com/components).

- PHP &gt;= 7.2
- Customizable with an easy configuration:
    - Models
    - Commands
    - Handlers
    - Configurations
    - Service Providers
    - Error Handler
    - Shutdown Handler
- [PSR-3 Logger](https://www.php-fig.org/psr/psr-3/)
- Global Helpers
- Better &amp; More Verbose Error Handler
- Environment variables with [PHP dotenv](https://github.com/vlucas/phpdotenv)
- [Pimple](https://pimple.symfony.com/) Dependency Injection Container
- [Medoo](https://medoo.in/) Database Framework (MySQL, PostgreSQL, SQLite, MS SQL Server, ...)

Table of Contents
-----------------

[](#table-of-contents)

- [How to Install](#how-to-install)
- [Most Relevant Folders](#most-relevant-folders)
- [Global Helpers](#global-helpers)
    - [Development Only](#global-helpers-for-development-only)
- [Configurations](#configurations)
    - [Dot Notation](#configurations-dot-notation)
- [Commands](#commands)
    - [Helpers](#commands-helpers)
    - [Inbuilt](#inbuilt-commands)
- [Run Commands](#run-commands)
- [Models](#models)
    - [Models Helpers](#models-helpers)
- [Services Providers](#services-providers)
- [Handlers](#handlers)
- [Database Support](#database-support)
- [Exceptions](#exceptions)
- [Logging](#logging)
- [Benchmarks](#benchmarks)

---

How to Install
--------------

[](#how-to-install)

Run this command from the directory in which you want to install your new **Micra Framework**.

```
composer create-project ricardoper/micra [my-app-name]
```

**NOTE**:

- Replace `[my-app-name]`with the desired directory name for your new application.
- Ensure `storage/` is web writeable.

Most Relevant Folders
---------------------

[](#most-relevant-folders)

- /app : *Application* code (**App** Namespace - [PSR-4](https://www.php-fig.org/psr/psr-4/))
    - ./Commands : The start point of your tasks. Add your *Controllers* here.
    - ./Handlers : Handles specified behaviors of the application. Add your *Handlers* here.
    - ./Models : Manages the data, logic and rules of the application. Add your *Models* here.
    - ./Services : Define bindings and inject dependencies. Add your *Service Providers* here.
- /configs : Add/modify your *Configurations* here

Global Helpers
--------------

[](#global-helpers)

- `env(string $variable, string $default)` - Returns *environment* variables (using DotEnv)
- `app()` - Returns *App* instance
- `container(string $name)` - Returns *Container* registered data
- `configs(string $variable, string $default)` - Returns *Configuration* data
- `base_path(string $path)` - Returns *base path* location
- `app_path(string $path)` - Returns *app path* location
- `configs_path(string $path)` - Returns *configs path* location
- `storage_path(string $path)` - Returns *storage path* location

### Global Helpers for Development Only

[](#global-helpers-for-development-only)

- `dump($var1, $var2, ...)` - Dump vars
- `dd($var1, $var2, ...)` - Dump &amp; die vars

Configurations
--------------

[](#configurations)

You can add as many configurations files as you want (`/configs`). These files *will be automatically preload and merged* in the container based on selected environment.

If you have an environment called "sandbox" and you want to overwrite some configuration only for this environment, you need to create a subfolder "sandbox" in `/configs`. Something like that `/configs/sandbox`. Then create the file that includes the configuration that you need to replace and the respective keys and values inside it.

`/configs/logger.php`

```
return [

    'name' => 'app',

    'maxFiles' => 7,

];
```

`/configs/local/logger.php`

```
return [

    'name' => 'app-local',

];
```

Results of `name` for the environment:

- prod : 'app'
- sandbox : 'app'
- **local : 'app-local'**
- testing : 'app'

**NOTE**: You can see the example in this framework for the *local* environment.

### Configurations Dot Notation

[](#configurations-dot-notation)

You can use **dot notation** to get values from configurations.

`/configs/example.php`

```
return [

    'types' => [
        'mysql' => [
            'host' => 'localhost',
            'port' => '3306',
        ],
        'postgre' => [
            'host' => 'localhost',
            'port' => '3306',
        ],
    ],

];
```

If you want the `host` value for MySQL type:

```
$this->getConfigs('example.types.mysql.host')  => 'localhost'

configs('example.types.mysql.host') => 'localhost'

container('configs')->get('example.types.mysql.host') => 'localhost'
```

Commands
--------

[](#commands)

*The start point of your tasks.*

You can add as many *Commands* as you want in a cleaning way (`/app/Commands`).

After add your *Command*, you can enable or disable it in `config/[env/]commands.php` configuration file.

**NOTE**: To have helpers you must extend the *Commands* with **ControllerAbstract** located in `\App\Kernel\Abstracts`.

```
use App\Kernel\Abstracts\CommandAbstract;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class HelloCommand extends CommandAbstract
{

    /**
     * Command name
     *
     * @var string
     */
    protected $cmdName = 'Hello';

    /**
     * Configure/explain command
     */
    protected function configure()
    {
        $this
            ->setName($this->cmdName)
            ->setDescription('Hello World!');

    }

    /**
     * Execute command process
     *
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $output->writeln('Hello World!');

        return 0;
    }
}
```

Enable it in `config/[env/]commands.php`:

```
use App\Commands\Demo\HelloCommand;

return [

    'hello' => HelloCommand::class,

];
```

### Commands Helpers

[](#commands-helpers)

- `getApp()` - Returns *App* object
- `getContainer(string $name)` - Returns the App *Container*
- `getConfigs(string $name)` - Returns App *Configs*
- `getService(string $service)` - Returns *Service Provider* from container by name

### Inbuilt commands

[](#inbuilt-commands)

- *Deps* : Is an in-built command to see if your system respect all the dependencies to run this framework.
- *Hello* : Is a command only for *local* environment (that can be deleted) only for demo purposes.
- *Example* : Is a command only for *local* environment (that can be deleted) only for demo purposes.
- *Addresses* : Is a command only for *local* environment (that can be deleted) only for demo purposes.

Run Commands
------------

[](#run-commands)

To run Commands use `micra` PHP executable.
`./micra [command-name]`

If you need help:
`./micra -h`

If you need Command help:
`./micra [command-name] -h`

Models
------

[](#models)

*Manages the data, logic and rules of the application.*

You can add as many *Models* as you want in a cleaning way (`/app/Models`).

After add your *Models*, you use it for, for example, in a *Controller*.

**NOTE**: To have helpers you must extend the *Model* with **ModelAbstract** located in `\App\Kernel\Abstracts`.

```
use App\Kernel\Abstracts\ModelAbstract;
use PDO;

class AddressesModel extends ModelAbstract
{

    /**
     * Get Last Addresses with Pdo
     *
     * @param int $limit
     * @return array
     */
    public function getLastWithPdo(int $limit = 25): array
    {
        /** @var $db PDO */
        $db = $this->getDb()->pdo;

        $sql = 'SELECT `address`.`address_id`,`address`.`address`,`address`.`address2`,`address`.`district`,`city`.`city`,`address`.`postal_code`,`address`.`phone` FROM `address` ';
        $sql .= 'LEFT JOIN `city` ON `address`.`city_id` = `city`.`city_id` ';
        $sql .= 'ORDER BY `address_id` DESC LIMIT 10';

        return $db->query($sql)->fetchAll(PDO::FETCH_ASSOC);
    }
```

### Models Helpers

[](#models-helpers)

- `getApp()` - Returns *App* object
- `getContainer(string $name)` - Returns the App *Container*
- `getConfigs(string $name)` - Returns App *Configs*
- `getService(string $service)` - Returns *Service Provider* from container by name
- `getDb()` - Returns *Database* object

Services Providers
------------------

[](#services-providers)

*Define bindings and inject dependencies.*

You can add as many *Services Providers* as you want in a cleaning way (`/app/Services`).

After add your *Services Provider*, you can enable or disable it in `configs/services.php` configuration file.

**NOTE**: *Service Providers* must respect the **ServiceProviderInterface** located in `\App\Kernel\Interfaces`.

```
use App\Kernel\Interfaces\ServiceProviderInterface;
use Pimple\Container;

class ExampleServiceProvider implements ServiceProviderInterface
{

    /**
     * Service register name
     */
    public function name(): string
    {
        return 'example';
    }

    /**
     * Register new service on dependency container
     *
     * @param Container $container
     * @return mixed
     */
    public function register(Container $container)
    {
        return function (Container $c) {
            unset($c);

            return new Example();
        };
    }
}
```

Enable it in `configs/services.php`:

```
use App\Services\Example\ExampleServiceProvider;

return [

    'example' => ExampleServiceProvider::class,

];
```

Handlers
--------

[](#handlers)

*Handles specified behaviors of the application.*

You can override the following Handlers in a cleaning way (`/app/Handlers`):

- *ErrorHandler* (default located in `/app/Handlers/ErrorHandler`)
- *ShutdownHandler* (default located in `/app/Handlers/ShutdownHandler`)

After add your *Handler*, you can enable or disable it in `configs/app.php` configuration file.

```
use App\Handlers\ErrorHandler;
use App\Handlers\ShutdownHandler;

return [

    // Handlers //
    'errorHandler' => ErrorHandler::class,

    'shutdownHandler' => ShutdownHandler::class,
```

Database Support
----------------

[](#database-support)

*Medoo* is implemented out of box as a *Service Provider*. The use **is optional** and is not enabled by default.

To enable database support with *Medoo* you need to add this library/vendor with Composer:

```
composer require catfan/medoo
```

Once installed you need to enable the *Service Provider* in `configs/services.php`:

```
use App\Services\Database\DatabaseServiceProvider;

return [

    'database' => DatabaseServiceProvider::class,

];
```

Now you are ready to use it...

If you need more details, documentation, api reference, please visit Medoo webpage:

**NOTES**:

- Don't forget to load PDO extensions for your database. For example, if you need MySQL, you need to install `pdo_mysql` PHP extensions.
- You can use another library as a *Service Provider* (Native drivers for MySQLi, PostgreSQL, MongoDB, Redis, ...).

Exceptions
----------

[](#exceptions)

You have some *Exceptions* out the box, located in `\App\Kernel\Exceptions`, than you can use it:

```
CommandException  - For Commands Exceptions
ConfigsException  - For Configurations Exceptions
ModelException    - For Models Exceptions
ServiceException  - For Service Providers Exceptions

```

Logging
-------

[](#logging)

Logging is always enabled and you can see all the output in `/storage/logs/app-[date].log`.

**NOTE**: Logs will with more than 7 days will be deleted automatically by the Logger.

Benchmarks
----------

[](#benchmarks)

Some numbers for Hello Command...

**Machine:**
Intel® Core™ i5-8400 CPU @ 2.80GHz × 6
16Gb RAM
SSD

**Versions:**
Ubuntu 20.04 LTS
Docker v19.03.8
PHP v7.4.3
PHP v7.2.24
Zend OPcache enabled

PHP v7.2PHP v7.4Linux Time - real0m0.057s0m0.054sLinux Time - user0m0.026s0m0.024sLinux Time - syssys 0m0.031ssys 0m0.030sPHP - Time0.016968s0.015434sPHP - Max Memory2414 KB2294 KBPHP - Allocated Memory4096 KB4096 KB
---

### Enjoy the simplicity :oP

[](#enjoy-the-simplicity-op)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

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 ~16 days

Total

2

Last Release

2183d ago

Major Versions

v1.0.0 → v2.0.02020-05-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/765a863c426744d47fb2a72ba44a64078e9e946e3e8b8c21daf5da007e4a3200?d=identicon)[ricardoper](/maintainers/ricardoper)

---

Top Contributors

[![ricardoper](https://avatars.githubusercontent.com/u/5161172?v=4)](https://github.com/ricardoper "ricardoper (8 commits)")

---

Tags

phpcliframeworkapplight

### Embed Badge

![Health badge](/badges/ricardoper-micra/health.svg)

```
[![Health](https://phpackages.com/badges/ricardoper-micra/health.svg)](https://phpackages.com/packages/ricardoper-micra)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[doppar/framework

The Doppar Framework

366.7k8](/packages/doppar-framework)[hunzhiwange/framework

The QueryPHP Framework.

6415.7k1](/packages/hunzhiwange-framework)[quantum/framework

The Quantum PHP Framework

402.8k1](/packages/quantum-framework)

PHPackages © 2026

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