codedungeon/php-messenger

PHP library for creating console messages

1.1.1 2021-07-28 16:53 UTC

README

Description

PHP Messenger provides a suite of routine which can be used in CLI based applications, providing a simple consistent interface, taking care of all the colorizing for you.

Screenshot

Using with Laravel Commands and Laravel-Zero

In addition, PHP Messenger can also be used with CLI applications created with Laravel Commands or Laravel-Zero, using the Laravel facades interface.

Installation

composer require codedungeon/php-messenger

Laravel Configuration

Laravel before 5.5 registration

  • Registering Service Provider

    Modify config/app.php and add the Service Provide

        'providers' => [
             ...
     		Codedungeon\PHPMessenger\MessengerServiceProvider::class,
     		...
  • Registering Facades

    Modify config/app/php and add the Facades to the aliases section

         'aliases' => [
     	...
             'Messenger' => Codedungeon\PHPMessenger\MessengerServiceProvider::class,
     	...

Laravel 5.5 and greater

When installing into a Laravel based project, it will use the auto discover system available with Laravel 5.5 or greater.

Laravel Zero Configuration

  • Register Service Provider

    Modify config/app.php providers section

     	'providers' => [
     		...
     		Codedungeon\PHPMessenger\ServiceProvider::class,
     		...
     	],
  • Create desired command, and use as follows

     	// add use statement
     	use Codedungeon\PHPMessenger\Facades\Messenger;
    
     	// handle method
     	public function handle()
     	{
     		echo PHP_EOL;
     		$msg = "PHP Messenger v" . Messenger::version();
     		Messenger::important($msg);
     		Messenger::info("-- Using Laravel Package (Facades)");
     	   ...
     	}

Using in non-Laravel applications

<?php

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

use Codedungeon\PHPMessenger\Messenger;

$messenger = new Messenger();

$messenger->success("Success Message w/ Label"," SUCCESS ");
$messenger->info("Information Message");
...

Usage

Messenger Signature

All messenger methods use the same method signature as follows

Messenger Methods

Messenger::log(msg:string, [label:string - optional])

Messenger::info(msg:string, [label:string - optional])

Messenger::debug(msg:string, [label:string - optional])

Messenger::critical(msg:string, [label:string - optional])

Messenger::error(msg:string, [label:string - optional])

Messenger::success(msg:string, [label:string - optional])

Messenger::warning(msg:string, [label:string - optional])

Messenger::warn(msg:string, [label:string - optional])

Messenger::important(msg:string, [label:string - optional])

Messenger::status(msg:string, [label:string - optional])

Messenger::notice(msg:string, [label:string - optional])

Messenger::note(msg:string, [label:string - optional])

Messenger::version() -> returns current package version

License

Copyright © 2019-2020 Mike Erickson Released under the MIT license

Credits

PHP Messenger written by Mike Erickson

E-Mail: codedungeon@gmail.com

Twitter: @codedungeon

Website: codedungeon.io