PHP Classes
elePHPant
Icontem

CYMAPGT Console: Manage services to handle console commands

Recommend this page to a friend!
  Info   View files Example   Videos Videos   View files View files (21)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-08-03 (2 months ago) RSS 2.0 feedNot enough user ratingsTotal: 88 All time: 8,841 This week: 609Up
Version License PHP version Categories
cymapgt-console 1.0.4BSD License5.4PHP 5, Console
Description Author

This package can manage services to handle console commands.

It can add, remove, replace and route to service classes that will handle commands entered in a console by the user.

The package can also display help text that will tell the user how each of the commands should be entered to pass options of those commands.

Innovation Award
PHP Programming Innovation award nominee
July 2017
Number 6
One way to structure better the components of an application is to build service components that can be called to provide separate services.

This package provides a means to use service components to implement different functionality for a console application.

Different components can be called based on the options that the user passed in the command line.

Manuel Lemos
  Performance   Level  
Name: Cyril Ogana <contact>
Classes: 4 packages by
Country: Kenya Kenya
Age: ???
All time rank: 19013 in Kenya Kenya
Week rank: 149 Up1 in Kenya Kenya Up
Innovation award
Innovation award
Nominee: 2x

Details

console

package for exposing PHP services via a console interface, providing build in authentication if needed

Description

The console package allows other packages to implement an interface that allows them to provide command line functionality to their classes in with minimal duplication of code. A NetConsoleInterface aware class can be registered to the console API; which offers among other things automatic help generation as well as an authentication interface prior to accessing registered namespaces.

Installing

Install application via Composer

require "cymapgt/console" : "^1.0.0"

Usage

Overview

  • Authenticate the console user (named console) to the Service
  • Provide interface to add services to the API
  • Provide interface to remove services from the API
  • Provide interface to amend a service using the API
  • Provide interface to display usage for the API
  • Provide interface to delegate actual API calls to the registered services

Using the Console package

Writing a NetConsole aware class

The package comes with two demo Classes that implement the NetConsoleInterface. See the files src/DemoApi.php and src/DemoRpi.php for template which you can use to implement your NetConsole class. Copy the files and customize as required.

Authentication to NetConsole

The default NetConsole authentication comes with some assumptions:

1.You auth data store is a database, with a table named user; and fields for username and password

2.You have an active user named console in the datastore


If you adhere to the above, your console authentication will work out of the box (assuming as well that the NetworkBootstrap is properly configured).

If you would like to implement your own Authentication, replace the file src/helper/ConsoleCredentials.php and in it

1.Create a class named ConsoleCredentials

2.Creat a public static method named authenticate() that will implement your custom authentication logic

Core NetConsole Commands

The core of NetConsole implements the NetConsoleInterface. There are a number of reserved keywords:

1.ADD COMMAND:

add serviceName serviceNamespace

COMMANDS AND SWITCHES:

COMMANDS

serviceName - The name of the service as registered in the console, or one of the sticky services.

serviceNamespace - The fully qualified namespace for the service being registered to the netconsole API

SWITCHES

None

EXAMPLE:

add bootstrap cymapgt\core\utility\bootstrap\console\BootstrapConsole;

2.HELP COMMAND:

help serviceName [-v="..."] [-m="..."]

COMMANDS AND SWITCHES:

COMMANDS

serviceName - The name of the service as registered in the console, or one of the sticky services.

SWITCHES

-v - The verbosity level of the help documentation

-m - Specifying a method name here will filter the help to provide only docs for that specific method

EXAMPLES

help bootstrap -m=config-all -v=3

help add

3.REMOVE COMMAND:

remove serviceName

COMMANDS AND SWITCHES:

COMMANDS

serviceName - The name of the service as registered in the console, or one of the sticky services.

SWITCHES

None

EXAMPLE:

remove bootstrap

4.QUIT COMMAND:

quit

COMMANDS AND SWITCHES:

COMMANDS

None

SWITCHES

None

EXAMPLE:

quit

5.CUSTOM COMMANDS:

Your PHP services functionality is exposed by implementing the NetConsoleInterface

After this implementation, you need to register your package with NetConsole by using the add command.

Successfully adding the package will expose all of the commands and switches you defined in the console configuration. The package can thus be used for managing tasks such as application installations within a controlled environment if you are distributing your proprietary logic.

It can also be used to quickly convert PHP services to console applications.

Testing

PHPUnit Tests are provided with the package

Contribute

  • Email @rhossis or contact via Skype
  • You will be added as author for contributions

License

BSD 3-clause

Videos  
  • cymapgt console authentication
  • cymapgt console demo
  Files folder image Files  
File Role Description
Files folder imagebin (2 files)
Files folder imagesrc (4 files, 4 directories)
Files folder imagetests (2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  bin  
File Role Description
  Accessible without login Plain text file netconsole Data Auxiliary data
  Accessible without login Plain text file netconsole.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imageabstractclass (1 file)
Files folder imageconfig (2 files)
Files folder imageException (1 file)
Files folder imagehelper (3 files)
  Plain text file ConsoleManager.php Class Class source
  Plain text file DemoApi.php Class Class source
  Plain text file DemoRpi.php Class Class source
  Plain text file NetConsole.php Class Class source

  Files folder image Files  /  src  /  abstractclass  
File Role Description
  Plain text file NetConsoleInterface.php Class Class source

  Files folder image Files  /  src  /  config  
File Role Description
  Plain text file ConsoleConfig.php Class Class source
  Accessible without login Plain text file NamedConstant.php Aux. Auxiliary script

  Files folder image Files  /  src  /  Exception  
File Role Description
  Plain text file NetConsoleException.php Class Class source

  Files folder image Files  /  src  /  helper  
File Role Description
  Plain text file ConsoleCredentials.php Class Class source
  Plain text file ConsoleEcho.php Class Class source
  Plain text file ConsoleRegister.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagefiles (2 files)
Files folder imagesrc (2 files)

  Files folder image Files  /  tests  /  files  
File Role Description
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Accessible without login Plain text file phpunit.xml Data Auxiliary data

  Files folder image Files  /  tests  /  src  
File Role Description
  Plain text file ConsoleManagerTest.php Class Class source
  Plain text file NetConsoleTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:88
This week:0
All time:8,841
This week:609Up