\Dewdrop\CliRun

This class is responsible for handling execution of CLI commands.

If you need to add CLI commands that are not provided by Dewdrop out of the box, provide an array of command classnames in a Pimple resource called "cli-commands". We use this special Pimple resource for custom command injection because it's not possible to define a custom Run instance in Pimple altogether, like we do for custom view helpers for example. Run is a "root" class in the sense that it is responsible for finding and kicking off the bootstrap directly.

Summary

Methods
Properties
Constants
__construct()
getPimple()
setArgs()
run()
halt()
executeCommand()
getCommands()
getCommandByName()
connectDb()
No public properties found
No constants found
instantiateCommands()
No protected properties found
N/A
No private methods found
$commandClasses
$commands
$args
$command
$renderer
$dbAdapter
$paths
$pimple
N/A

Properties

$commandClasses

$commandClasses : array

The class names of the commands that can be handled.

Type

array

$commands

$commands : \Dewdrop\Cli\array()

The instantiated command objects available for execution.

Type

\Dewdrop\Cli\array()

$args

$args : array

The arguments that should be supplied to the executed command. By default these will be taken from the command line directly, using every element in the $_SERVER['argv'] array starting at index 2.

Type

array

$command

$command : string

The name of the command that should be run. If not specified, the command specified in $_SERVER['argv'][1] will be used.

Type

string

$renderer

$renderer : \Dewdrop\Cli\Renderer\RendererInterface

The renderer that will be used by this class and any executed commands in order to send output to the terminal.

Type

\Dewdrop\Cli\Renderer\RendererInterface

$dbAdapter

$dbAdapter : \Dewdrop\Db\Adapter

The DB adapter. You can retrieve this by calling connectDb().

Type

\Dewdrop\Db\Adapter

$paths

$paths : \Dewdrop\Paths

A \Dewdrop\Paths instance to help in navigating the filesystem.

Type

\Dewdrop\Paths

$pimple

$pimple : \Pimple

The Pimple DI container associated with this application. Found via the application's bootstrap class.

Type

\Pimple

Methods

__construct()

__construct(array  $args = null, string  $command = null, \Dewdrop\Cli\Renderer\RendererInterface  $renderer = null) 

Create the CLI runner, giving users the ability to inject non-default args, command name, and renderer (primarily for testing purposes).

Parameters

array $args
string $command
\Dewdrop\Cli\Renderer\RendererInterface $renderer

getPimple()

getPimple() : \Pimple

Grab the Pimple DI container associated with this application.

Returns

\Pimple

setArgs()

setArgs(array  $args) : \Dewdrop\Cli\Run

Override the args applied to this runner

Parameters

array $args

Returns

\Dewdrop\Cli\Run

run()

run() : void

Find the selected command, if any, and execute it. If no command is selected, display the default help content instead. Either way, execution is halted after this method is done.

halt()

halt(integer  $exitStatus) : void

Stop execution. In a separate method to make it easy to mock during testing.

Parameters

integer $exitStatus

executeCommand()

executeCommand(string  $name) : \Dewdrop\Cli\Run

Run the named command, if its arguments can be successfully parsed.

Parameters

string $name

Returns

\Dewdrop\Cli\Run

getCommands()

getCommands() : array

Get the array of instantiated commands. Will be an empty array until run() is called. This is used by the Help command to display a list of available commands.

Returns

array

getCommandByName()

getCommandByName(  $name) 

Parameters

$name

connectDb()

connectDb() : \Dewdrop\Db\Adapter

Pull in the wp-config.php file to allow us to connect to the database on the CLI.

Returns

\Dewdrop\Db\Adapter

instantiateCommands()

instantiateCommands() : void

Instantiate all command objects. We need them all instantiated so that we can see if any has been selected for execution (i.e. the command property of this object matches the command name or one of its aliases).