Methods |
public
|
__construct(
?string $basePath = null,
?string $appName = null,
int $envFlags = Env::APPLY_ALL,
?string $configDir = 'config',
)
Creates a new Application object
Creates a new Application object
If $basePath is null , the value of environment variable
app_base_path is used if present, otherwise the path of the root
package is used.
If $appName is null , the basename of the file used to run the script
is used after removing common PHP file extensions and recognised version
numbers.
If $configDir exists and is a directory, it is passed to
{@see Config::loadDirectory()} after .env files are loaded and values
are applied from the environment to the running script.
Parameters
$envFlags |
Values to apply from the
environment to the running script.
|
$configDir |
A path relative to the application's base
path, or null if configuration files should not be loaded.
|
Overrides
Implements
|
#
|
public
|
getProgramName(): string
Get the name of the file used to run the application
Get the name of the file used to run the application
Implements
|
#
|
public
|
getRunningCommand(): ?CliCommandInterface
Get the command invoked by run()
Get the command invoked by run()
This method should only return a command that is currently running.
Implements
|
#
|
public
|
getLastCommand(): ?CliCommandInterface
Get the command most recently invoked by run()
Get the command most recently invoked by run()
This method should only return a command that ran to completion or failed
with an exception.
Implements
|
#
|
public
|
getLastExitStatus(): int
Get the return value most recently recorded by run()
Get the return value most recently recorded by run()
This method should return 0 if a return value has not been recorded.
Implements
|
#
|
protected
|
getNodeCommand(
string $name,
array<string, class-string<CliCommandInterface>|mixed[]>|class-string<CliCommandInterface>|false|null $node,
): ?CliCommandInterface
Get a command instance from the given node in the command tree
Get a command instance from the given node in the command tree
Returns null if no command is registered at the given node.
Parameters
$name |
The name of the node as a space-delimited list of
subcommands.
|
$node |
The node as returned by {@see CliApplication::getNode()}.
|
|
#
|
protected
|
getNode(
string[] $name = [],
): array<string, class-string<CliCommandInterface>|mixed[]>|class-string<CliCommandInterface>|false|null
Resolve an array of subcommand names to a node in the command tree
Resolve an array of subcommand names to a node in the command tree
Returns one of the following:
-
null if nothing has been added to the tree at $name
- the name of the {@see CliCommandInterface} class registered at
$name
- an array that maps subcommands of
$name to their respective nodes
-
false if a {@see CliCommandInterface} has been registered above
$name , e.g. if $name is ["sync", "canvas", "from-sis"] and a
command has been registered at ["sync", "canvas"]
Nodes in the command tree are either subcommand arrays (branches) or
{@see CliCommandInterface} class names (leaves).
|
#
|
public
|
oneCommand(string $id)
Register one, and only one, command for the lifetime of the container
Register one, and only one, command for the lifetime of the container
Calling this method should have the same effect as calling
{@see CliApplicationInterface::command()} with an empty command name.
Implements
|
#
|
public
|
command(array $name, string $id)
Register a command with the container
Register a command with the container
Parameters
$name |
The name of the command as an array of subcommands.
Valid subcommands start with a letter, followed by any number of letters,
numbers, hyphens and underscores.
|
Implements
|
#
|
public
|
run()
Process command line arguments passed to the script and record a return
value
Process command line arguments passed to the script and record a return
value
This method should take the first applicable action:
-
If --help is the only remaining argument after processing subcommand
arguments, print a help message to STDOUT . Return value: 0
-
If --version is the only remaining argument, print the application's
name, version and commit reference to STDOUT , followed by the PHP
version. Return value: 0
-
If subcommand arguments resolve to a registered command, create an
instance of the command and run it. Return value: command exit status
-
If, after processing subcommand arguments, there are no further
arguments but there are further subcommands, print a one-line synopsis
of each registered subcommand. Return value: 0
-
Report an error and print a one-line synopsis of each registered
subcommand. Return value: 1
Implements
|
#
|
public
|
exit()
Exit with the return value most recently recorded by run()
Exit with the return value most recently recorded by run()
This method should use exit status 0 if a return value has not been
recorded.
Implements
|
#
|
public
|
runAndExit()
Process command line arguments passed to the script and exit with the
recorded return value
Process command line arguments passed to the script and exit with the
recorded return value
See {@see CliApplicationInterface::run()} for details.
Implements
|
#
|
public
|
reportVersion(int $level = MessageLevel::INFO, bool $stdout = false)
Print the application's name, version and commit reference, followed by
the PHP version
Print the application's name, version and commit reference, followed by
the PHP version
Implements
|
#
|
public
|
getVersionString(): string
Get the application's name, version and commit reference, followed by the
PHP version
Get the application's name, version and commit reference, followed by the
PHP version
This method should return the string that
{@see CliApplicationInterface::reportVersion()} would print.
Implements
|
#
|