anso/console

Console framework for training project.

dev-master 2020-04-13 10:28 UTC

This package is auto-updated.

Last update: 2025-06-13 22:54:13 UTC


README

Requirements

PHP >= 7.4

Installation

anso/console can be installed via Composer.

composer require anso/console:dev-master

Usage

A few configuration files must be created and placed in a single folder before instantiating Application object and calling start() method:

  • exception_handler.php - must return instance of ExceptionHandler
  • providers.php - must return array of Providers that are used to register DI container's bindings.
  • commands.php - must return instance of CommandCollection. It contains array of commands defined by key as name and string value as Handler

Afterwards application can be started like this (/console.php):

<?php

define('BASE_PATH', __DIR__);

require __DIR__ . '/vendor/autoload.php';

use Anso\Framework\Base\Container;
use Anso\Framework\Base\Configuration;
use Anso\Framework\Console\ConsoleApp;
use Anso\Framework\Base\Contract\Application;

$configuration = new Configuration('/config/console');
$container = new Container($configuration);
$app = new ConsoleApp($container, $configuration);

$container->addResolved(Application::class, $app);

$app->start();
  • BASE_PATH constant is needed to include config files and extract values from them later.
  • To enable autoloading composer's autoload.php must be required.
  • Then Configuration, Container and ConsoleApp objects must be created. Be sure that you have Application, Container and Configuration registered as singletons either in a provider or right after creating $app object.
  • $app object should be marked as resolved, so that if it is required later, a duplicate app object with wrong config wouldn't be created.
  • Finally the app can start working.