CliApplication
Extends \Joomla\CMS\Application\BaseApplicationBase class for a Joomla! command line application.
since |
2.5.0 |
---|---|
note |
As of 4.0 this class will be abstract |
Methods
__construct
Class constructor.
__construct(\Joomla\Input\Input $input = null, \Joomla\Registry\Registry $config = null)
since |
1.0 |
---|
Arguments
- $input
\Joomla\Input\Input
An optional argument to provide dependency injection for the application's input object. If the argument is an Input object that object will become the application's input object, otherwise a default input object is created.- $config
\Joomla\Registry\Registry
An optional argument to provide dependency injection for the application's config object. If the argument is a Registry object that object will become the application's config object, otherwise a default config object is created.
close
Method to close the application.
close(integer $code) : void
since |
1.0 |
---|
Arguments
- $code
integer
The exit code (optional; default is 0).
doExecute
Method to run the application routines. Most likely you will want to instantiate a controller and execute it, or perform some sort of task directly.
doExecute() : void
since |
1.0 |
---|
execute
Execute the application.
execute() : void
since |
1.0 |
---|
fetchConfigurationData
Method to load a PHP configuration class file based on convention and return the instantiated data object. You will extend this method in child classes to provide configuration data from whatever data source is relevant for your specific application.
fetchConfigurationData(string $file = '', string $class = '\JConfig') : mixed
since |
1.7.0 |
---|
Arguments
- $file
string
The path and filename of the configuration file. If not provided, configuration.php in JPATH_CONFIGURATION will be used.- $class
string
The class name to instantiate.
Response
mixed
Either an array or object to be loaded into the configuration object.
get
Returns a property of the object or the default value if the property is not set.
get(string $key, mixed $default = null) : mixed
since |
1.0 |
---|
Arguments
- $key
string
The name of the property.- $default
mixed
The default value (optional) if none is set.
Response
mixed
The value of the configuration.
getIdentity
Get the application identity.
getIdentity() : mixed
since |
3.0.0 |
---|
Response
mixed
A \JUser object or null.
getInstance
Returns a reference to the global CliApplication object, only creating it if it doesn't already exist.
getInstance(string $name = null) : \Joomla\CMS\Application\CliApplication
This method must be invoked as: $cli = CliApplication::getInstance();
since |
1.7.0 |
---|
Arguments
- $name
string
The name (optional) of the JApplicationCli class to instantiate.
Response
getLogger
Get the logger.
getLogger() : \Psr\Log\LoggerInterface
since |
1.0 |
---|
Response
\Psr\Log\LoggerInterface
getOutput
Get an output object.
getOutput() : \Joomla\Application\Cli\CliOutput
in
Get a value from standard input.
in() : string
since |
1.7.0 |
---|
Response
string
The input string from standard input.
initialise
Custom initialisation method.
initialise() : void
Called at the end of the AbstractApplication::__construct method. This is for developers to inject initialisation code for their application classes.
since |
1.0 |
---|
loadConfiguration
Load an object or array into the application configuration object.
loadConfiguration(mixed $data) : \Joomla\CMS\Application\CliApplication
since |
1.7.0 |
---|
Arguments
- $data
mixed
Either an array or object to be loaded into the configuration object.
Response
\Joomla\CMS\Application\CliApplication
Instance of $this to allow chaining.
loadDispatcher
Allows the application to load a custom or default dispatcher.
loadDispatcher(\JEventDispatcher $dispatcher = null) : \Joomla\CMS\Application\BaseApplication
The logic and options for creating this object are adequately generic for default cases but for many applications it will make sense to override this method and create event dispatchers, if required, based on more specific needs.
since |
3.0.0 |
---|
Arguments
- $dispatcher
\JEventDispatcher
An optional dispatcher object. If omitted, the factory dispatcher is created.
Response
\Joomla\CMS\Application\BaseApplication
This method is chainable.
loadIdentity
Allows the application to load a custom or default identity.
loadIdentity(\JUser $identity = null) : \Joomla\CMS\Application\BaseApplication
The logic and options for creating this object are adequately generic for default cases but for many applications it will make sense to override this method and create an identity, if required, based on more specific needs.
since |
3.0.0 |
---|
Arguments
- $identity
\JUser
An optional identity object. If omitted, the factory user is created.
Response
\Joomla\CMS\Application\BaseApplication
This method is chainable.
out
Write a string to standard output.
out(string $text = '', boolean $nl = true) : \Joomla\CMS\Application\CliApplication
since |
1.7.0 |
---|
Arguments
- $text
string
The text to display.- $nl
boolean
True (default) to append a new line at the end of the output string.
Response
\Joomla\CMS\Application\CliApplication
Instance of $this to allow chaining.
registerEvent
Registers a handler to a particular event group.
registerEvent(string $event, callable $handler) : \Joomla\CMS\Application\BaseApplication
since |
3.0.0 |
---|
Arguments
- $event
string
The event name.- $handler
callable
The handler, a function or an instance of an event object.
Response
\Joomla\CMS\Application\BaseApplication
The application to allow chaining.
set
Modifies a property of the object, creating it if it does not already exist.
set(string $key, mixed $value = null) : mixed
since |
1.0 |
---|
Arguments
- $key
string
The name of the property.- $value
mixed
The value of the property to set (optional).
Response
mixed
Previous value of the property
setConfiguration
Sets the configuration for the application.
setConfiguration(\Joomla\Registry\Registry $config) : \Joomla\Application\AbstractApplication
since |
1.0 |
---|
Arguments
- $config
\Joomla\Registry\Registry
A registry object holding the configuration.
Response
\Joomla\Application\AbstractApplication
Returns itself to support chaining.
setLogger
Set the logger.
setLogger(\Psr\Log\LoggerInterface $logger) : \Joomla\Application\AbstractApplication
since |
1.0 |
---|
Arguments
- $logger
\Psr\Log\LoggerInterface
The logger.
Response
\Joomla\Application\AbstractApplication
Returns itself to support chaining.
setOutput
Set an output object.
setOutput(\Joomla\Application\Cli\CliOutput $output) : \Joomla\CMS\Application\CliApplication
since |
3.3 |
---|
Arguments
- $output
\Joomla\Application\Cli\CliOutput
CliOutput object
Response
\Joomla\CMS\Application\CliApplication
Instance of $this to allow chaining.
triggerEvent
Calls all handlers associated with an event group.
triggerEvent(string $event, array $args = null) : array
since |
3.0.0 |
---|
Arguments
- $event
string
The event name.- $args
array
An array of arguments (optional).
Response
array
An array of results from each function call, or null if no dispatcher is defined.
Properties
instance
The application instance.
identity
The application identity object.
since |
3.0.0 |
---|
Type(s)
\JUser
logger
A logger.
since |
1.0 |
---|
Type(s)
\Psr\Log\LoggerInterface
input
The application input object.
The application input object
Type(s)
\JInput