liberty_code/command

v1.0.1 2022-01-10 22:12 UTC

This package is auto-updated.

Last update: 2024-04-11 02:49:34 UTC


README

Description

Library contains command line components, to use features and other libraries components, on command line context.

Requirement

  • Script language: PHP: version 7 || 8

Installation

Several ways are possible:

Composer

  1. Requirement

    It requires composer installation. For more information: https://getcomposer.org

  2. Command: Move in project root path

     cd "<project_root_path>"
    
  3. Command: Installation

     php composer.phar require liberty_code/command ["<version>"]
    
  4. Note

    • Include vendor

      If project uses composer, vendor must be included:

        require_once('<project_root_path>/vendor/autoload.php');
      
    • Configuration

      Installation command allows to add, on composer file "/composer.json", following configuration:

        {
            "require": {
                "liberty_code/command": "<version>"
            }
        }
      

Include

  1. Download

    • Download following repository.
    • Put it on repository root path.
  2. Include source

     require_once('<repository_root_path>/include/Include.php');
    

Configuration

Main configuration

  • Use following class to configure specific elements

      use liberty_code\command\config\model\DefaultConfig;
      DefaultConfig::instanceGetDefault()->get|set...();
    
  • Elements configurables

    • Request options

Usage

Route

Route allows to interpret specified source, from command line request, on command line context, to get executable.

Elements

  • CommandPatternRoute, CommandParamRoute, CommandFixRoute, CommandSeparatorRoute

    Extends route features. Adapt all standard routes, to interpret specified source, from command line request, and get information (summary and help).

  • CommandRouteFactory

    Extends DI route factory features. Provides command route instance.

Request

Request allows to provide route source, on request flow process and command line context.

Elements

  • CommandRequest

    Extends request features. Allows to design command line request.

Example

use liberty_code\command\request_flow\request\model\CommandRequest;
$request = CommandRequest::instanceGetDefault();
echo($request->getStrRouteSrc()); 
// Show "{route:<route>,argument:[<command line arguments...>],option:[<command line options...>]}"
...

Response

Response allows to provide final send-able content, from request flow process, on command line context.

Elements

  • Response utilities

    Information command line response allows to get specific information about context, on command line context.

      Example: response with command lines summary content, 
      response with specific command line help content.
    

Front controller

Front controller allows to design the request flow process, on command line context.

Elements

  • CommandFrontController

    Extends front controller features. Uses command line request, to get response.

  • InfoFrontController

    Extends command line front controller features. Allows to manage information command line responses.

Example

use liberty_code\command\request_flow\front\model\CommandFrontController;
$frontController = new CommandFrontController();
$frontController->setRouter(...);
$frontController->setActiveRequest(...);
...
// Show response object
var_dump($frontController->execute());
...

Authentication

Authentication allows to design an authentication class, using command request arguments.

Elements

  • CommandAuthentication

    Extends authentication features. Uses command request arguments, to get all identification and authentication information.

Example

// Get command authentication
use liberty_code\command\request_flow\request\model\CommandRequest;
$commandAuth = new CommandRequest($request);
$commandAuth->setAuthConfig(...);
...
// Get array of identification data
var_dump($commandAuth->getTabIdData());
...
// Get array of authentication data
var_dump($commandAuth->getTabAuthData());
...