ConsoleApp

Type
Class
Namespace
Craft
Inherits
Craft\ConsoleApp » CConsoleApplication » CApplication » CModule » CComponent
Since
1.0

Class ConsoleApp

See also http://craftcms.com

View source

Public Properties

PropertyDescription
$behaviorsarray – The behaviors that should be attached to the module.
$charsetstring – The charset currently used for the application.
$commandMaparray – Mapping from command name to command configurations.
$componentAliases
$localeClassstring – The class used to get locale data.
$namestring – The application name.
$preloadarray – The IDs of the application components that should be preloaded.
$sourceLanguagestring – The language that the application is written in.

$componentAliases

Signature

public  $componentAliases = null

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__construct()Constructor.
__get()Returns a property value, an event handler list or a behavior based on its name.
__isset()Checks if a property value is null.
__set()Sets value of a component property.
__unset()Sets a component property to be null.
asa()Returns the named behavior object.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
attachEventHandler()Attaches an event handler to an event.
canGetProperty()Determines whether a property can be read.
canSetProperty()Determines whether a property can be set.
clearGlobalState()Clears a global value.
configure()Configures the module with the specified configuration.
createAbsoluteUrl()Creates an absolute URL based on the given controller and action information.
createUrl()Creates a relative URL based on the given controller and action information.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
detachEventHandler()Detaches an existing event handler.
disableBehavior()Disables an attached behavior.
disableBehaviors()Disables all behaviors attached to this component.
displayError()Displays the captured PHP error.
displayException()Displays the uncaught PHP exception.
enableBehavior()Enables an attached behavior.
enableBehaviors()Enables all behaviors attached to this component.
end()Terminates the application.
evaluateExpression()Evaluates a PHP expression or callback under the context of this component.
findLocalizedFile()Returns the localized version of a specified file.
getBasePath()Returns the root path of the application.
getBaseUrl()Returns the relative URL for the application.
getCache()Returns the cache component.
getCommand()Returns the currently running command.
getCommandPath()
getCommandRunner()Returns the command runner.
getComponent()Override getComponent() so we can attach any pending events if the component is getting initialized as well as do some special logic around creating the craft()->db application component.
getComponents()Returns the application components.
getController()
getCoreMessages()Returns the core message translations component.
getDateFormatter()Returns the locale-dependent date formatter.
getDb()Returns the database connection component.
getErrorHandler()Returns the error handler component.
getEventHandlers()Returns the list of attached event handlers for an event.
getExtensionPath()Returns the root directory that holds all third-party extensions.
getFormat()Returns the formatter component.
getGlobalState()Returns a global value.
getHomeUrl()
getId()Returns the unique identifier for the application.
getLanguage()Returns the target application language.
getLocale()Returns the locale instance.
getLocaleDataPath()Returns the directory that contains the locale data.
getMessages()Returns the application message translations component.
getModule()Retrieves the named application module.
getModulePath()Returns the directory that contains the application modules.
getModules()Returns the configuration of the currently installed modules.
getNumberFormatter()
getParams()Returns user-defined parameters.
getParentModule()Returns the parent module.
getRequest()Returns the request component.
getRuntimePath()Returns the directory that stores runtime files.
getSecurityManager()Returns the security manager component.
getStatePersister()Returns the state persister component.
getTimeZone()Returns the system time zone. Note that this method cannot be in {@link AppBehavior}, because Yii will check {@link \CApplication::getTimeZone()} instead.
getUrlManager()Returns the URL manager component.
handleError()
handleException()Handles uncaught PHP exceptions.
hasComponent()Checks whether the named component exists.
hasEvent()Determines whether an event is defined.
hasEventHandler()Checks whether the named event has attached handlers.
hasModule()Returns a value indicating whether the specified module is installed.
hasProperty()Determines whether a property is defined.
init()Initializes the console app by creating the command runner.
isConsole()Returns whether we are executing in the context on a console app.
loadGlobalState()Loads the global state data from persistent storage.
on()Attaches an event handler, or remembers it for later if the component has not been initialized yet.
onBeginRequest()Raised right BEFORE the application processes the request.
onEndRequest()Raised right AFTER the application processes the request.
onError()Raised when a PHP execution error occurs.
onException()Raised when an uncaught PHP exception occurs.
processRequest()Processes the request.
raiseEvent()Raises an event.
run()Runs the application.
saveGlobalState()Saves the global state data into persistent storage.
setAliases()Defines the root aliases.
setBasePath()Sets the root directory of the application.
setCommand()This is shortcut method for {@link CConsoleCommandRunner::setCommand()}.
setCommandPath()
setComponent()Puts a component under the management of the module.
setComponents()Sets the application components.
setExtensionPath()Sets the root directory that holds all third-party extensions.
setGlobalState()Sets a global value.
setHomeUrl()
setId()Sets the unique identifier for the application.
setImport()Sets the aliases that are used in the module.
setLanguage()Sets the target application language.
setLocaleDataPath()Sets the directory that contains the locale data.
setModulePath()Sets the directory that contains the application modules.
setModules()Configures the sub-modules of this module.
setParams()Sets user-defined parameters.
setRuntimePath()Sets the directory that stores runtime files.
setTimeZone()Sets the time zone used by this application.

getComponent()

Override getComponent() so we can attach any pending events if the component is getting initialized as well as do some special logic around creating the craft()->db application component.

View source

Arguments

Returns

mixed

Signature

public mixed getComponent ( $id, $createIfNull = true )

getLanguage()

Returns the target application language.

View source

Returns

string

Signature

public string getLanguage ( )

getTimeZone()

Returns the system time zone. Note that this method cannot be in {@link AppBehavior}, because Yii will check {@link \CApplication::getTimeZone()} instead.

View source

Returns

string

Signature

public string getTimeZone ( )

handleError()

View source

Arguments

  • $code (integer) – The level of the error raised.
  • $message (string) – The error message.
  • $file (string) – The filename that the error was raised in.
  • $line (integer) – The line number the error was raised at.

Signature

public void handleError ( $code, $message, $file, $line )

init()

Initializes the console app by creating the command runner.

View source

Returns

null

Signature

public null init ( )

isConsole()

Returns whether we are executing in the context on a console app.

View source

Returns

boolean

Signature

public boolean isConsole ( )

on()

Attaches an event handler, or remembers it for later if the component has not been initialized yet. The event should be identified in a serviceHandle.eventName format. For example, if you want to add an event handler for {@link EntriesService::onSaveEntry()}, you would do this:

craft()->on('entries.saveEntry', function(Event $event) {
    // ...
});

Note that the actual event name (saveEntry) does not need to include the “on”.

By default, event handlers will not get attached if Craft is current in the middle of updating itself or a plugin. If you want the event to fire even in that condition, pass true to the $evenDuringUpdates argument.

View source

Arguments

  • $event (string) – The event to listen for.
  • $handler (mixed) – The event handler.
  • $evenDuringUpdates (boolean) – Whether the event handler should be attached when Craft’s updater is running. Default is false.

Returns

null

Signature

public null on ( $event, $handler, $evenDuringUpdates = false )

setComponents()

Sets the application components.

View source

Arguments

Returns

null

Signature

public null setComponents ( $components, $merge = true )

setLanguage()

Sets the target application language.

View source

Arguments

Returns

null

Signature

public null setLanguage ( $language )

Protected Methods

MethodDescription
createCommandRunner()
initSystemHandlers()Initializes the error handlers.
preinit()Preinitializes the module.
preloadComponents()Loads static application components.
registerCoreComponents()Registers the core application components.

createCommandRunner()

Signature

protected Craft\ConsoleCommandRunner createCommandRunner ( )