codedungeon / php-messenger
PHP library for creating console messages
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.27
- orchestra/testbench: ~3.0
- phpunit/phpunit: ^8.0
- spatie/phpunit-watcher: ^1.8
This package is auto-updated.
Last update: 2024-10-30 01:39:20 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.
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 thealiases
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