ConsoleApplication

Extends Application Implements DispatcherAwareInterface, CMSApplicationInterface

The Joomla! CMS Console Application

since

4.0.0

package

Joomla CMS

Methods

__construct

Class constructor.

__construct(\Joomla\Registry\Registry config, \Joomla\Event\DispatcherInterface dispatcher, \Joomla\DI\Container container, \Joomla\CMS\Language\Language language, \Symfony\Component\Console\Input\InputInterface|null input = null, \Symfony\Component\Console\Output\OutputInterface|null output = null) : 
since

4.0.0

Arguments

config

RegistryAn 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.

dispatcher

DispatcherInterfaceAn optional argument to provide dependency injection for the application's event dispatcher. If the argument is a DispatcherInterface object that object will become the application's event dispatcher, if it is null then the default event dispatcher will be created based on the application's loadDispatcher() method.

container

ContainerDependency injection container.

language

LanguageThe language object provisioned for the application.

input

InputInterface|nullAn optional argument to provide dependency injection for the application's input object. If the argument is an InputInterface object that object will become the application's input object, otherwise a default input object is created.

output

OutputInterface|nullAn optional argument to provide dependency injection for the application's output object. If the argument is an OutputInterface object that object will become the application's output object, otherwise a default output object is created.

Response

mixed

__get

Magic method to access properties of the application.

__get( name) : 
deprecated
since

4.0.0

deprecated

4.0 will be removed in 6.0 This is a B/C proxy for deprecated read accesses, use getInput() method instead Example: $app->getInput();

Arguments

name

stringThe name of the property.

Response

mixedA value if the property name is valid, null otherwise.

bootComponent

Boots the component with the given name.

bootComponent( component) : \Joomla\CMS\Extension\ComponentInterface
inherited
since

4.0.0

Arguments

component

stringThe component to boot.

Response

ComponentInterface

bootModule

Boots the module with the given name.

bootModule( module,  applicationName) : \Joomla\CMS\Extension\ModuleInterface
inherited
since

4.0.0

Arguments

module

stringThe module to boot

applicationName

stringThe application name

Response

ModuleInterface

bootPlugin

Boots the plugin with the given name and type.

bootPlugin( plugin,  type) : \Joomla\CMS\Extension\PluginInterface
inherited
since

4.0.0

Arguments

plugin

stringThe plugin name

type

stringThe type of the plugin

Response

PluginInterface

createExtensionNamespaceMap

Allows the application to load a custom or default identity.

createExtensionNamespaceMap() : 
inherited
since

4.0.0

Response

void

doExecute

Method to run the application routines.

doExecute() : 
since

4.0.0

throws

Throwable

Response

intThe exit code for the application

enqueueMessage

Enqueue a system message.

enqueueMessage( msg,  type = self::MSG_INFO) : 
since

4.0.0

Arguments

msg

stringThe message to enqueue.

type

stringThe message type.

Response

void

execute

Execute the application.

execute() : 
since

4.0.0

throws

Throwable

Response

void

flushAssets

Flush the media version to refresh versionable assets

flushAssets() : 
since

4.0.0

Response

void

getConfig

Retrieve the application configuration object.

getConfig() : \Joomla\Registry\Registry
since

4.0.0

Response

Registry

getContainer

Get the DI container.

getContainer() : \Joomla\DI\Container
inherited abstract
since

4.0.0

throws

ContainerNotFoundExceptionMay be thrown if the container has not been set.

Response

Container

getDefaultCommands

Get the commands which should be registered by default to the application.

getDefaultCommands() : \Joomla\Console\Command\AbstractCommand||string|int
since

4.0.0

Response

array<string|int, AbstractCommand>

getDefaultInputDefinition

Builds the default input definition.

getDefaultInputDefinition() : \Symfony\Component\Console\Input\InputDefinition
since

4.2.1

Response

InputDefinition

getDispatcher

Get the event dispatcher.

getDispatcher() : \Joomla\Event\DispatcherInterface
inherited abstract
since

4.0.0

throws

UnexpectedValueExceptionMay be thrown if the dispatcher has not been set.

Response

DispatcherInterface

getIdentity

Get the application identity.

getIdentity() : \Joomla\CMS\User\User
inherited
since

4.0.0

Response

User

getInput

Method to get the application input object.

getInput() : \Joomla\Input\Input
since

4.0.0

Response

Input

getLanguage

Method to get the application language object.

getLanguage() : \Joomla\CMS\Language\Language
since

4.0.0

Response

LanguageThe language object

getLogger

Get the logger.

getLogger() : \Psr\Log\LoggerInterface
inherited abstract
since

4.0.0

Response

LoggerInterface

getLongVersion

Get the long version string for the application.

getLongVersion() : 

Overrides the parent method due to conflicting use of the getName method between the console application and the CMS application interface.

since

4.0.0

Response

string

getMessageQueue

Get the system message queue.

getMessageQueue() : mixed||string|int
since

4.0.0

Response

array<string|int, mixed>The system message queue.

getName

Gets the name of the current running application.

getName() : 
since

4.0.0

Response

stringThe name of the application.

getRouter

Returns the application Router object.

getRouter( name = null, mixed||string|int options = []) : \Joomla\CMS\Router\Router
static deprecated
since

4.0.6

throws

InvalidArgumentException

deprecated

4.3 will be removed in 6.0 Inject the router or load it from the dependency injection container Example: Factory::getContainer()->get(ApiRouter::class);

Arguments

name

stringThe name of the application.

options

array<string|int, mixed>An optional associative array of configuration settings.

Response

Router

getSession

Method to get the application session object.

getSession() : \Joomla\Session\SessionInterface
since

4.0.0

Response

SessionInterfaceThe session object

getUserState

Gets a user state.

getUserState( key,  default = null) : 
since

4.4.0

Arguments

key

stringThe path of the state.

default

mixedOptional default value, returned if the internal value is null.

Response

mixedThe user state or null.

getUserStateFromRequest

Gets the value of a user state variable.

getUserStateFromRequest( key,  request,  default = null,  type = 'none') : 
since

4.4.0

Arguments

key

stringThe key of the user state variable.

request

stringThe name of the variable passed in a request.

default

stringThe default value for the variable if not found. Optional.

type

stringFilter for the variable, for valid values see {@link InputFilter::clean()}. Optional.

Response

mixedThe request user state.

isCli

Flag if the application instance is a CLI or web based application.

isCli() : 
deprecated

Helper function, you should use the native PHP functions to detect if it is a CLI application.

since

4.0.0

deprecated

4.0 will be removed in 6.0 Will be removed without replacement. CLI will be handled by the joomla/console package instead

Response

bool

isClient

Check the client interface by name.

isClient( identifier) : 
since

4.0.0

Arguments

identifier

stringString identifier for the application interface

Response

boolTrue if this application is of the given type client interface.

loadExtension

Loads the extension.

loadExtension( type,  extensionName,  extensionPath) : \Joomla\CMS\Extension\ComponentInterface|\Joomla\CMS\Extension\ModuleInterface|\Joomla\CMS\Extension\PluginInterface
inherited
since

4.0.0

Arguments

type

stringThe extension type

extensionName

stringThe extension name

extensionPath

stringThe path of the extension

Response

ComponentInterface|ModuleInterface|PluginInterface

loadIdentity

Allows the application to load a custom or default identity.

loadIdentity(\Joomla\CMS\User\User identity = null) : 
inherited
since

4.0.0

Arguments

identity

UserAn optional identity object. If omitted, a null user object is created.

Response

$this

loadPluginFromFilesystem

Creates a CMS plugin from the filesystem.

loadPluginFromFilesystem( plugin,  type) : \Joomla\CMS\Plugin\CMSPlugin
inherited
since

4.0.0

Arguments

plugin

stringThe plugin

type

stringThe type

Response

CMSPlugin

populateHttpHost

Populates the HTTP_HOST and REQUEST_URI from the URL provided in the --live-site parameter.

populateHttpHost() : 

If the URL provided is empty or invalid we will use the URL https://joomla.invalid/set/by/console/application just so that the CLI application doesn't crash when a WebApplication descendant is instantiated in it.

This is a practical workaround for using any service depending on a WebApplication descendant under CLI.

Practical example: using a component's MVCFactory which instantiates the SiteRouter service for that component which in turn relies on an instance of SiteApplication.

since

4.2.1

see

https://github.com/joomla/joomla-cms/issues/38518

Response

void

registerEvent

Registers a handler to a particular event group.

registerEvent( event, 
Warning: Array to string conversion in /opt/phpdoc/vendor/twig/twig/src/Extension/CoreExtension.php on line 768
|Array handler) : 
inherited
since

4.0.0

Arguments

event

stringThe event name.

handler

callableThe handler, a function or an instance of an event object.

Response

$this

setName

Set the name of the application.

setName( name) : 
since

4.0.0

throws

RuntimeExceptionbecause the application name cannot be changed

Arguments

name

stringThe new application name.

Response

void

setSession

Sets the session for the application to use, if required.

setSession(\Joomla\Session\SessionInterface session) : 
since

4.0.0

Arguments

session

SessionInterfaceA session object.

Response

$this

triggerEvent

Calls all handlers associated with an event group.

triggerEvent( eventName, array|\Joomla\Event\Event args = []) : mixed||string|int
inherited deprecated

This is a legacy method, implementing old-style (Joomla! 3.x) plugin calls. It's best to go directly through the Dispatcher and handle the returned EventInterface object instead of going through this method. This method is deprecated and will be removed in Joomla! 5.x.

This method will only return the 'result' argument of the event

since

4.0.0

throws

InvalidArgumentException

deprecated

4.0 will be removed in 6.0 Use the Dispatcher method instead Example: Factory::getApplication()->getDispatcher()->dispatch($eventName, $event);

Arguments

eventName

stringThe event name.

args

array<string|int, mixed>|EventAn array of arguments or an Event object (optional).

Response

array<string|int, mixed>An array of results from each function call. Note this will be an empty array if no dispatcher is set.

Properties

identity

The application identity object.

inherited
since

4.0.0

Type(s)

User

input

The input.

since

4.0.0

Type(s)

Input

name

The name of the application.

since

4.0.0

Type(s)

string

language

The application language object.

since

4.0.0

Type(s)

Language

messages

The application message queue.

since

4.0.0

Type(s)

array<string|int, mixed>

session

The application session object.

since

4.0.0

Type(s)

SessionInterface