Overview

Namespaces

  • None
  • splitbrain
    • phpcli
      • tests

Classes

  • CLI
  • Colors
  • Options
  • PSR3CLI
  • TableFormatter

Exceptions

  • Exception
  • Overview
  • Namespace
  • Class

Class CLI

Class CLI

Your commandline script should inherit from this class and implement the abstract methods.

Direct known subclasses

logging, Minimal, splitbrain\phpcli\PSR3CLI
Abstract
Namespace: splitbrain\phpcli
License: MIT
Author: Andreas Gohr andi@splitbrain.org
Located at src/CLI.php
Methods summary
public
# __construct( boolean $autocatch = true )

constructor

constructor

Initialize the arguments, set up helper classes and set up the CLI environment

Parameters

$autocatch
should exceptions be catched and handled automatically?
abstract protected
# setup( splitbrain\phpcli\Options $options )

Register options and arguments on the given $options object

Register options and arguments on the given $options object

Parameters

$options

Throws

splitbrain\phpcli\Exception
abstract protected
# main( splitbrain\phpcli\Options $options )

Your main program

Your main program

Arguments and options have been parsed when this is run

Parameters

$options

Throws

splitbrain\phpcli\Exception
public
# run( )

Execute the CLI program

Execute the CLI program

Executes the setup() routine, adds default options, initiate the options parsing and argument checking and finally executes main() - Each part is split into their own protected function below, so behaviour can easily be overwritten

Throws

splitbrain\phpcli\Exception
protected
# registerDefaultOptions( )

Add the default help, color and log options

Add the default help, color and log options

protected
# handleDefaultOptions( )

Handle the default options

Handle the default options

protected
# setupLogging( )

Handle the logging options

Handle the logging options

protected
# parseOptions( )

Wrapper around the option parsing

Wrapper around the option parsing

protected
# checkArgments( )

Wrapper around the argument checking

Wrapper around the argument checking

protected
# execute( )

Wrapper around main

Wrapper around main

public
# fatal( Exception|string $error, array $context = array() )

Exits the program on a fatal error

Exits the program on a fatal error

Parameters

$error
either an exception or an error message
$context
public
# emergency( string $message, array $context = array() )

System is unusable.

System is unusable.

Parameters

$message
$context
public
# alert( string $message, array $context = array() )

Action must be taken immediately.

Action must be taken immediately.

Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.

Parameters

$message
$context
public
# critical( string $message, array $context = array() )

Critical conditions.

Critical conditions.

Example: Application component unavailable, unexpected exception.

Parameters

$message
$context
public
# error( string $message, array $context = array() )

Runtime errors that do not require immediate action but should typically be logged and monitored.

Runtime errors that do not require immediate action but should typically be logged and monitored.

Parameters

$message
$context
public
# warning( string $message, array $context = array() )

Exceptional occurrences that are not errors.

Exceptional occurrences that are not errors.

Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.

Parameters

$message
$context
public
# success( string $string, array $context = array() )

Normal, positive outcome

Normal, positive outcome

Parameters

$string
$context
public
# notice( string $message, array $context = array() )

Normal but significant events.

Normal but significant events.

Parameters

$message
$context
public
# info( string $message, array $context = array() )

Interesting events.

Interesting events.

Example: User logs in, SQL logs.

Parameters

$message
$context
public
# debug( string $message, array $context = array() )

Detailed debug information.

Detailed debug information.

Parameters

$message
$context
public
# log( string $level, string $message, array $context = array() )

Parameters

$level
$message
$context
public string
# interpolate( $message, array $context = array() )

Interpolates context values into the message placeholders.

Interpolates context values into the message placeholders.

Parameters

$message
$context

Returns

string
Properties summary
protected string $bin

the executed script itself

the executed script itself

#
protected splitbrain\phpcli\Options $options

the option parser

the option parser

#
public splitbrain\phpcli\Colors $colors
#
protected array $loglevel

PSR-3 compatible loglevels and their prefix, color, output channel

PSR-3 compatible loglevels and their prefix, color, output channel

# array( 'debug' => array('', Colors::C_RESET, STDOUT), 'info' => array('ℹ ', Colors::C_CYAN, STDOUT), 'notice' => array('☛ ', Colors::C_CYAN, STDOUT), 'success' => array('✓ ', Colors::C_GREEN, STDOUT), 'warning' => array('⚠ ', Colors::C_BROWN, STDERR), 'error' => array('✗ ', Colors::C_RED, STDERR), 'critical' => array('☠ ', Colors::C_LIGHTRED, STDERR), 'alert' => array('✖ ', Colors::C_LIGHTRED, STDERR), 'emergency' => array('✘ ', Colors::C_LIGHTRED, STDERR), )
protected string $logdefault
# 'info'
API documentation generated by ApiGen