PHP Class ZF\Console\Application

Afficher le fichier Open project: zfcampus/zf-console Class Usage Examples

Protected Properties

Свойство Type Description
$banner null | string | callable
$bannerDisabledForUserCommands boolean
$console Zend\Console\Adapter\AdapterInterface
$debug boolean Flag to specify if the application is in debug mode
$dispatcher ZF\Console\DispatcherInterface
$exceptionHandler callable
$footer null | string | callable
$name string
$routeCollection ZF\Console\RouteCollection
$version string

Méthodes publiques

Méthode Description
__construct ( string $name, string $version, array | Traversabl\Traversable $routes, Zend\Console\Adapter\AdapterInterface $console = null, ZF\Console\DispatcherInterface $dispatcher = null ) Initialize the application
getDispatcher ( ) : ZF\Console\DispatcherInterface
getExceptionHandler ( ) : callable Gets the registered exception handler
isBannerDisabledForUserCommands ( ) : boolean Whether or not to disable the banner in user commands. False by default.
removeRoute ( String $name ) : self Remove a route by name
run ( array $args = null ) : integer Run the application
setBanner ( null | string | callable $bannerOrCallable ) : self Set the banner to display.
setBannerDisabledForUserCommands ( boolean $flag = true ) : self Disables the banner for user commands. Still shows it before usage messages.
setDebug ( boolean $flag ) Sets the debug flag of the application
setExceptionHandler ( callable $handler ) : self Sets exception handler to use the expection Message
setFooter ( null | string | callable $footerOrCallable ) : self Set the footer to display.
showMessage ( string | callable $messageOrCallable ) Display a message (banner or footer)
showUsageMessage ( null | string $name = null ) Displays a usage message for the router
showVersion ( Zend\Console\Adapter\AdapterInterface $console ) : integer Display the application version

Méthodes protégées

Méthode Description
calcMaxString ( array $data = [] ) : integer Calculate the maximum string length for an array
initializeExceptionHandler ( ) Initialize the exception handler (if not in debug mode)
mapRouteHandler ( array $route ) Map a route handler
processRun ( array $args ) : integer Process run If the argument list is empty, displays a usage message.
setProcessTitle ( ) Set CLI process title (PHP versions >= 5.5)
setRoutes ( array | Traversabl\Traversable $routes ) : self Set routes to use
setupAutocompleteCommand ( ZF\Console\RouteCollection $routeCollection, ZF\Console\DispatcherInterface $dispatcher ) Sets up the default autocomplete command
setupHelpCommand ( ZF\Console\RouteCollection $routeCollection, ZF\Console\DispatcherInterface $dispatcher ) Sets up the default help command
setupVersionCommand ( ZF\Console\RouteCollection $routeCollection, ZF\Console\DispatcherInterface $dispatcher ) Sets up the default version command
showUnmatchedRouteMessage ( array $args ) Show message indicating inability to match a route.
showUnrecognizedRouteMessage ( string $name ) Display an error message indicating a route name was not recognized
showUsageMessageForRoute ( Route $route, $log = false ) Display the usage message for an individual route
validateMessage ( mixed $stringOrCallable )

Method Details

__construct() public méthode

Creates a RouteCollection and populates it with the $routes provided. Sets the banner to call showVersion(). If no help command is defined, defines one. If no version command is defined, defines one.
public __construct ( string $name, string $version, array | Traversabl\Traversable $routes, Zend\Console\Adapter\AdapterInterface $console = null, ZF\Console\DispatcherInterface $dispatcher = null )
$name string Application name
$version string Application version
$routes array | Traversabl\Traversable Routes/route specifications to use for the application
$console Zend\Console\Adapter\AdapterInterface Console adapter to use within the application
$dispatcher ZF\Console\DispatcherInterface Configured dispatcher mapping routes to callables

calcMaxString() protected méthode

Calculate the maximum string length for an array
protected calcMaxString ( array $data = [] ) : integer
$data array
Résultat integer

getDispatcher() public méthode

public getDispatcher ( ) : ZF\Console\DispatcherInterface
Résultat ZF\Console\DispatcherInterface

getExceptionHandler() public méthode

Lazy-instantiates an ExceptionHandler instance with the current console instance if no handler has been specified.
public getExceptionHandler ( ) : callable
Résultat callable

initializeExceptionHandler() protected méthode

Initialize the exception handler (if not in debug mode)

isBannerDisabledForUserCommands() public méthode

Whether or not to disable the banner in user commands. False by default.

mapRouteHandler() protected méthode

If a given route specification has a "handler" entry, and the dispatcher does not currently have a handler for that command, map it.
protected mapRouteHandler ( array $route )
$route array

processRun() protected méthode

If arguments are provided, but no routes match, displays a usage message and returns a status of 1. Otherwise, attempts to dispatch the matched command, returning the execution status.
protected processRun ( array $args ) : integer
$args array
Résultat integer

removeRoute() public méthode

Remove a route by name
public removeRoute ( String $name ) : self
$name String
Résultat self

run() public méthode

If no arguments are provided, pulls them from $argv, stripping the script argument first. If the argument list is empty, displays a usage message. If arguments are provided, but no routes match, displays a usage message and returns a status of 1. Otherwise, attempts to dispatch the matched command, returning the execution status.
public run ( array $args = null ) : integer
$args array
Résultat integer

setBanner() public méthode

Used whenever the application is called without arguments. If the default help implementation is used, also displayed with help messages.
public setBanner ( null | string | callable $bannerOrCallable ) : self
$bannerOrCallable null | string | callable
Résultat self

setBannerDisabledForUserCommands() public méthode

Disables the banner for user commands. Still shows it before usage messages.
public setBannerDisabledForUserCommands ( boolean $flag = true ) : self
$flag boolean
Résultat self

setDebug() public méthode

Sets the debug flag of the application
public setDebug ( boolean $flag )
$flag boolean

setExceptionHandler() public méthode

Sets exception handler to use the expection Message
public setExceptionHandler ( callable $handler ) : self
$handler callable
Résultat self

setFooter() public méthode

Used whenever the application is called without arguments. If the default help implementation is used, also displayed with help messages.
public setFooter ( null | string | callable $footerOrCallable ) : self
$footerOrCallable null | string | callable
Résultat self

setProcessTitle() protected méthode

Set CLI process title (PHP versions >= 5.5)
protected setProcessTitle ( )

setRoutes() protected méthode

Allows specifying an array of routes, which may be mixed Route instances or array specifications for creating routes.
protected setRoutes ( array | Traversabl\Traversable $routes ) : self
$routes array | Traversabl\Traversable
Résultat self

setupAutocompleteCommand() protected méthode

Creates the route, and maps the command.
protected setupAutocompleteCommand ( ZF\Console\RouteCollection $routeCollection, ZF\Console\DispatcherInterface $dispatcher )
$routeCollection ZF\Console\RouteCollection
$dispatcher ZF\Console\DispatcherInterface

setupHelpCommand() protected méthode

Creates the route, and maps the command.
protected setupHelpCommand ( ZF\Console\RouteCollection $routeCollection, ZF\Console\DispatcherInterface $dispatcher )
$routeCollection ZF\Console\RouteCollection
$dispatcher ZF\Console\DispatcherInterface

setupVersionCommand() protected méthode

Creates the route, and maps the command.
protected setupVersionCommand ( ZF\Console\RouteCollection $routeCollection, ZF\Console\DispatcherInterface $dispatcher )
$routeCollection ZF\Console\RouteCollection
$dispatcher ZF\Console\DispatcherInterface

showMessage() public méthode

If the message is a string and not callable, uses the composed console instance to render it. If the message is a callable, calls it with the composed console instance as an argument.
public showMessage ( string | callable $messageOrCallable )
$messageOrCallable string | callable

showUnmatchedRouteMessage() protected méthode

Show message indicating inability to match a route.
protected showUnmatchedRouteMessage ( array $args )
$args array

showUnrecognizedRouteMessage() protected méthode

Display an error message indicating a route name was not recognized
protected showUnrecognizedRouteMessage ( string $name )
$name string

showUsageMessage() public méthode

If a route name is provided, usage for that route only will be displayed; otherwise, the name/short description for each will be present.
public showUsageMessage ( null | string $name = null )
$name null | string

showUsageMessageForRoute() protected méthode

Display the usage message for an individual route
protected showUsageMessageForRoute ( Route $route, $log = false )
$route Route

showVersion() public méthode

Display the application version
public showVersion ( Zend\Console\Adapter\AdapterInterface $console ) : integer
$console Zend\Console\Adapter\AdapterInterface
Résultat integer

validateMessage() protected méthode

protected validateMessage ( mixed $stringOrCallable )
$stringOrCallable mixed

Property Details

$banner protected_oe property

protected null|string|callable $banner
Résultat null | string | callable

$bannerDisabledForUserCommands protected_oe property

protected bool $bannerDisabledForUserCommands
Résultat boolean

$console protected_oe property

protected AdapterInterface,Zend\Console\Adapter $console
Résultat Zend\Console\Adapter\AdapterInterface

$debug protected_oe property

Flag to specify if the application is in debug mode
protected bool $debug
Résultat boolean

$dispatcher protected_oe property

protected DispatcherInterface,ZF\Console $dispatcher
Résultat ZF\Console\DispatcherInterface

$exceptionHandler protected_oe property

protected callable $exceptionHandler
Résultat callable

$name protected_oe property

protected string $name
Résultat string

$routeCollection protected_oe property

protected RouteCollection,ZF\Console $routeCollection
Résultat ZF\Console\RouteCollection

$version protected_oe property

protected string $version
Résultat string