2017 © Pedro Peláez
 

library console

Console is a lightweight console framework for PHP

image

shaggy8871/console

Console is a lightweight console framework for PHP

  • Thursday, February 15, 2018
  • by shaggy8871
  • Repository
  • 1 Watchers
  • 0 Stars
  • 775 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 6 Versions
  • 42 % Grown

The README.md

Console

Console is a lightweight console routing framework for PHP. It's easy to get started, requires almost zero configuration, and can run within existing projects without a major rewrite., (*1)

Installation:, (*2)

In composer.json:, (*3)

"require": {
    "shaggy8871/console": "dev-master"
}

Then run:, (*4)

composer install

Example console.php file:, (*5)

<?php
include_once "vendor/autoload.php";

$console = new Console\Runner();

// Add one or more commands here
$console->registerAll([
    'app:command' => [
        'class' => 'Commands\CustomCommand',
        'description' => 'Add your custom command description'
    ]
]);

// Start your engines...
try {
    $console->run();
} catch(Console\Exception\CommandNotFoundException $e) {
    echo $e->getMessage() . "\n--------\n\n" . $console->getHelp();
    die();
}

Example command class:, (*6)

<?php

namespace Commands;

use Console\CommandInterface;
use Console\Args;

class CustomCommand implements CommandInterface
{

    public function execute(Args $args)
    {

        // Convert short-form to long-form arguments
        $args->setAliases([
            'l' => 'longform'
        ]);

        // Write custom code
        // ... Do something with $args->longform or $args->getAll()

    }

}

Color decorating

To decorate output with colors or styles, use the following method:, (*7)

<?php

use Console\Decorate;

echo Decorate::color('Hello, world!', 'red bold bg_white');

Color reference

Colors Modifiers Backgrounds
black bold bg_black
red underline bg_red
green bg_green
yellow bg_yellow
blue bg_blue
purple bg_purple
cyan bg_cyan
light_gray bg_white
dark_gray
light_red
light_green
light_yellow
light_blue
light_purple
light_cyan
white

To introduce a 256-color VGA palette, use the handy vgaColor and vgaBackground helpers., (*8)

<?php

use Console\Decorate;

echo Decorate::color('Hello, world!', [
    Decorate::vgaBackground(9), 
    Decorate::vgaColor(52)
]);

StdOut

Some console applications need the ability to enable or disable ansi output depending on whether output is rendering to the console or to a log file. The StdOut class allows for switching between the two., (*9)

To render one or more decorated strings:, (*10)

<?php

use Console\StdOut;

StdOut::write([
    ["Hello, world!\n", 'red'],
    ["This is a second line, but in green\n", 'green']
]);

To disable ansi but still output, call disableAnsi() first. All ansi characters will be removed in future output. You can call enableAnsi() to re-enable ansi mode., (*11)

<?php

use Console\StdOut;

StdOut::disableAnsi();
StdOut::write([
    ["Hello, world!\n", 'red'],
    ["This is a second line, but in green\n", 'green']
]);

The Versions

15/02 2018

dev-master

9999999-dev

Console is a lightweight console framework for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by J. Ginsberg

15/02 2018

1.0.4

1.0.4.0

Console is a lightweight console framework for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by J. Ginsberg

25/09 2017

1.0.3

1.0.3.0

Console is a lightweight console framework for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by J. Ginsberg

04/04 2017

1.0.2

1.0.2.0

Console is a lightweight console framework for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by J. Ginsberg

04/04 2017

1.0.1

1.0.1.0

Console is a lightweight console framework for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by J. Ginsberg

27/02 2017

1.0

1.0.0.0

Console is a lightweight console framework for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

by J. Ginsberg