Application ​
- Type
- Class
- Namespace
- craft\console
- Inherits
- craft\console\Application » yii\console\Application » yii\base\Application » yii\base\Module » yii\di\ServiceLocator » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Uses traits
- craft\base\ApplicationTrait
- Since
- 3.0.0
Craft Console Application class
An instance of the Console Application class is globally accessible to console requests in Craft via \Craft::$app
.
Public Properties ​
Property | Description |
---|---|
addresses | craft\services\Addresses – The addresses service |
aliases | array – List of path aliases to be defined. |
announcements | craft\services\Announcements – The announcements service |
api | craft\services\Api – The API service |
assetIndexer | craft\services\AssetIndexer – The asset indexer service |
assetManager | yii\web\AssetManager – The asset manager application component. |
assets | craft\services\Assets – The assets service |
auth | craft\services\Auth – The user authentication service |
authManager | yii\rbac\ManagerInterface, null – The auth manager application component or null if it's not configured. |
basePath | string – The root directory of the application. |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
bootstrap | array – List of components that should be run during the application bootstrapping process. |
cache | yii\caching\CacheInterface, null – The cache application component. |
canTestEditions | boolean – Whether Craft is running on a domain that is eligible to test out the editions |
canUpgradeEdition | boolean – Whether Craft is eligible to be upgraded to a different edition |
categories | craft\services\Categories – The categories service |
charset | string – The charset currently used for the application. |
components | array – The list of the component definitions or the loaded component instances (ID => definition or instance). |
composer | craft\services\Composer – The Composer service |
conditions | craft\services\Conditions – The conditions service |
config | craft\services\Config – The config service |
container | array – Values given in terms of name-value pairs. |
contentMigrator | craft\db\MigrationManager – The content migration manager |
controller | yii\console\Controller – The currently active controller instance |
controllerMap | array – Mapping from controller ID to controller configurations. |
controllerNamespace | string – The namespace that controller classes are located in. |
controllerPath | string – The directory that contains the controller classes. |
dashboard | craft\services\Dashboard – The dashboard service |
db | yii\db\Connection – The database connection. |
db2 | craft\db\Connection – The database connection component used for mutex locks and element bulk op records |
defaultRoute | string – The default route of this application. |
deprecator | craft\services\Deprecator – The deprecator service |
drafts | craft\services\Drafts – The drafts service |
dumper | \Symfony\Component\VarDumper\Dumper\AbstractDumper |
edition | \craft\enums\CmsEdition – The installed Craft CMS edition. |
editionHandle | string |
editionName | string |
elementSources | craft\services\ElementSources – The element sources service |
elements | craft\services\Elements – The elements service |
enableCoreCommands | boolean – Whether to enable the commands provided by the core framework. |
entries | craft\services\Entries – The entries service |
env | string, null – The environment ID Craft is currently running in. |
envId | string |
errorHandler | yii\console\ErrorHandler – The error handler application component. |
extensions | array, null – List of installed Yii extensions. |
fields | craft\services\Fields – The fields service |
formatter | yii\i18n\Formatter – The formatter application component. |
formattingLocale | craft\i18n\Locale – The Locale object that should be used to define the formatter |
fs | craft\services\Fs – The filesystems service |
gc | craft\services\Gc – The garbage collection service |
globals | craft\services\Globals – The globals service |
gql | craft\services\Gql – The GraphQl service |
hasWrongEdition | boolean – Whether Craft is running with the wrong edition |
i18n | yii\i18n\I18N – The internationalization application component. |
id | string – An ID that uniquely identifies this module among other modules which have the same parent. |
imageTransforms | craft\services\ImageTransforms – The image transforms service |
images | craft\services\Images – The images service |
info | craft\models\Info |
installedSchemaVersion | string – The installed schema version |
isInMaintenanceMode | boolean – Whether someone is currently performing a system update |
isInitialized | boolean – Whether Craft is fully initialized |
isInstalled | boolean – Whether Craft is installed |
isLive | boolean |
isMultiSite | boolean – Whether this site has multiple sites |
isSystemLive | boolean – Whether the system is live |
language | string – The language that is meant to be used for end users. |
layout | string, boolean – The layout that should be applied for views in this application. |
layoutPath | string – The root directory of layout files. |
licensedEdition | \craft\enums\CmsEdition , null |
licensedEditionName | string, null |
loadedModules | array – List of loaded modules indexed by their class names. |
locale | craft\i18n\Locale – The Locale object for the target language |
log | yii\log\Dispatcher – The log dispatcher application component. |
mailer | yii\mail\MailerInterface – The mailer application component. |
migrator | craft\db\MigrationManager – The application’s migration manager |
minVersionRequired | string – The minimum Craft build number required to update to this build. |
module | yii\base\Module, null – The parent module of this module. |
modules | array – The modules (indexed by their IDs). |
mutex | yii\mutex\Mutex – The application’s mutex service |
name | string – The application name. |
params | array – Custom module parameters (name => value). |
path | craft\services\Path – The path service |
pluginStore | craft\services\PluginStore – The plugin store service |
plugins | craft\services\Plugins – The plugins service |
projectConfig | craft\services\ProjectConfig – The project config service |
queue | yii\queue\Queue, craft\queue\QueueInterface – The job queue |
relations | craft\services\Relations – The relations service (deprecated) |
request | craft\console\Request – The request component |
requestedAction | yii\base\Action, null – The requested Action. |
requestedParams | array – The parameters supplied to the requested action. |
requestedRoute | string – The requested route |
response | yii\console\Response – The response component. |
revisions | craft\services\Revisions – The revisions service |
routes | craft\services\Routes – The routes service |
runtimePath | string – The directory that stores runtime files. |
schemaVersion | string – Craft’s schema version number. |
search | craft\services\Search – The search service |
security | yii\base\Security – The security application component. |
session | |
sites | craft\services\Sites – The sites service |
sourceLanguage | string – The language that the application is written in. |
sso | craft\services\Sso – The SSO service |
state | integer – The current application state during a request handling life cycle. |
structures | craft\services\Structures – The structures service |
systemMessages | craft\services\SystemMessages – The system email messages service |
systemName | string |
systemUid | string, null |
tags | craft\services\Tags – The tags service |
targetLanguage | string |
templateCaches | craft\services\TemplateCaches – The template caches service |
timeZone | string – The time zone used by this application. |
tokens | craft\services\Tokens – The tokens service |
uniqueId | string – The unique ID of the module. |
updates | craft\services\Updates – The updates service |
urlManager | yii\web\UrlManager – The URL manager for this application. |
user | craft\console\User – The user component |
userGroups | craft\services\UserGroups – The user groups service |
userPermissions | craft\services\UserPermissions – The user permissions service |
users | craft\services\Users – The users service |
utilities | craft\services\Utilities – The utilities service |
vendorPath | string – The directory that stores vendor files. |
version | string – The version of this module. |
view | yii\base\View, yii\web\View – The view application component that is used to render various view files. |
viewPath | string – The root directory of view files. |
volumes | craft\services\Volumes – The volumes service |
webpack | craft\services\Webpack – The webpack service |
yiiVersion | string |
request
​
- Type
- craft\console\Request
- Default value
null
The request component
session
​
- Default value
null
- Access
- Read-only
user
​
- Type
- craft\console\User
- Default value
null
The user component
Public Methods ​
Method | Description |
---|---|
__call() | Calls the named method which is not a class method. |
__clone() | This method is called after the object is created by cloning an existing one. |
__construct() | Constructor. |
__get() | Getter magic method. |
__isset() | Checks if a property value is null. |
__set() | Sets the value of a component property. |
__unset() | Sets a component property to be null. |
afterAction() | This method is invoked right after an action within this module is executed. |
attachBehavior() | Attaches a behavior to this component. |
attachBehaviors() | Attaches a list of behaviors to the component. |
beforeAction() | This method is invoked right before an action within this module is executed. |
behaviors() | Returns a list of behaviors that this component should behave as. |
bootstrap() | Initializes extensions and executes bootstrap components. |
canGetProperty() | Returns a value indicating whether a property can be read. |
canSetProperty() | Returns a value indicating whether a property can be set. |
className() | Returns the fully qualified name of this class. |
clear() | Removes the component from the locator. |
coreCommands() | Returns the configuration of the built-in commands. |
coreComponents() | Returns the configuration of core application components. |
createController() | Creates a controller instance based on the given route. |
createControllerByID() | Creates a controller based on the given controller ID. |
detachBehavior() | Detaches a behavior from the component. |
detachBehaviors() | Detaches all behaviors from the component. |
disableMaintenanceMode() | Disables Maintenance Mode. |
enableMaintenanceMode() | Enables Maintenance Mode. |
end() | Terminates the application. |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. |
get() | Returns the component instance with the specified ID. |
getAddresses() | Returns the addresses service. |
getAnnouncements() | Returns the announcements service. |
getApi() | Returns the API service. |
getAssetIndexer() | Returns the asset indexing service. |
getAssetManager() | Returns the asset manager. |
getAssets() | Returns the assets service. |
getAuth() | Returns the user authentication service. |
getAuthManager() | Returns the auth manager for this application. |
getBasePath() | Returns the root directory of the module. |
getBehavior() | Returns the named behavior object. |
getBehaviors() | Returns all behaviors attached to this component. |
getCache() | Returns the cache component. |
getCanUpgradeEdition() | Returns whether Craft is eligible to be upgraded to a different edition. |
getCategories() | Returns the categories service. |
getComponents() | Returns the list of the component definitions or the loaded component instances. |
getComposer() | Returns the Composer service. |
getConditions() | Returns the conditions service. |
getConfig() | Returns the config service. |
getContentMigrator() | Returns the content migration manager. |
getControllerPath() | Returns the directory that contains the controller classes according to controllerNamespace. |
getDashboard() | Returns the dashboard service. |
getDb() | Returns the database connection component. |
getDb2() | Returns the database connection used for mutex locks and element bulk op records. |
getDeprecator() | Returns the deprecator service. |
getDrafts() | Returns the drafts service. |
getDumper() | Returns the variable dumper. |
getEdition() | Returns the installed Craft CMS edition’s ID. |
getEditionHandle() | Returns the handle of the Craft edition. |
getEditionName() | Returns the name of the Craft edition. |
getElementSources() | Returns the element indexes service. |
getElements() | Returns the elements service. |
getEntries() | Returns the entries service. |
getEnvId() | Returns the application ID combined with the environment name. |
getErrorHandler() | Returns the error handler component. |
getFields() | Returns the fields service. |
getFormatter() | Returns the formatter component. |
getFormattingLocale() | Returns the locale that should be used to define the formatter. |
getFs() | Returns the filesystems service. |
getGc() | Returns the garbage collection service. |
getGlobals() | Returns the globals service. |
getGql() | Returns the GraphQL service. |
getHasWrongEdition() | Returns whether Craft is running with the wrong edition. |
getI18n() | Returns the internationalization (i18n) component. |
getImageTransforms() | Returns the image transforms service. |
getImages() | Returns the images service. |
getInfo() | Returns the info model, or just a particular attribute. |
getInstalledSchemaVersion() | Returns the installed schema version. |
getInstance() | Returns the currently requested instance of this module class. |
getIsInMaintenanceMode() | Returns whether someone is currently performing a system update. |
getIsInitialized() | Returns whether Craft has been fully initialized. |
getIsInstalled() | Returns whether Craft is installed. |
getIsLive() | Returns whether the system is currently live. |
getIsMultiSite() | Returns whether this Craft install has multiple sites. |
getLayoutPath() | Returns the directory that contains layout view files for this module. |
getLicensedEdition() | Returns the edition Craft is actually licensed to run in. |
getLicensedEditionName() | Returns the name of the edition Craft is actually licensed to run in. |
getLocale() | Returns a Locale object for the target language. |
getLog() | Returns the log dispatcher component. |
getMailer() | Returns the mailer component. |
getMigrator() | Returns the application’s migration manager. |
getModule() | Retrieves the child module of the specified ID. |
getModules() | Returns the sub-modules in this module. |
getMutex() | Returns the application’s mutex service. |
getPath() | Returns the path service. |
getPluginStore() | Returns the plugin store service. |
getPlugins() | Returns the plugins service. |
getProjectConfig() | Returns the system config service. |
getQueue() | Returns the queue service. |
getRelations() | Returns the relations service. |
getRequest() | Returns the request component. |
getResponse() | Returns the response component. |
getRevisions() | Returns the revisions service. |
getRoutes() | Returns the routes service. |
getRuntimePath() | Returns the directory that stores runtime files. |
getSearch() | Returns the search service. |
getSecurity() | Returns the security component. |
getSession() | |
getSites() | Returns the sites service. |
getSso() | Returns the SSO service. |
getStructures() | Returns the structures service. |
getSystemMessages() | Returns the system email messages service. |
getSystemName() | Returns the system name. |
getSystemUid() | Returns the system's UID. |
getTags() | Returns the tags service. |
getTargetLanguage() | Returns the target app language. |
getTemplateCaches() | Returns the template cache service. |
getTimeZone() | Returns the time zone used by this application. |
getTokens() | Returns the tokens service. |
getUniqueId() | Returns an ID that uniquely identifies this module among all modules within the current application. |
getUpdates() | Returns the updates service. |
getUrlManager() | Returns the URL manager for this application. |
getUser() | Returns the user component. |
getUserGroups() | Returns the user groups service. |
getUserPermissions() | Returns the user permissions service. |
getUsers() | Returns the users service. |
getUtilities() | Returns the utilities service. |
getVendorPath() | Returns the directory that stores vendor files. |
getVersion() | Returns current module version. |
getView() | Returns the view object. |
getViewPath() | Returns the directory that contains the view files for this module. |
getVolumes() | Returns the volumes service. |
getWebpack() | Returns the webpack service. |
getYiiVersion() | Returns the Yii framework version. |
handleRequest() | Handles the specified request. |
has() | Returns a value indicating whether the locator has the specified component definition or has instantiated the component. |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() | Returns a value indicating whether a method is defined. |
hasModule() | Checks whether the child module of the specified ID exists. |
hasProperty() | Returns a value indicating whether a property is defined for this component. |
init() | Initialize the application. |
off() | Detaches an existing event handler from this component. |
on() | Attaches an event handler to an event. |
onAfterRequest() | Invokes a callback function at the end of the request. |
onInit() | Invokes a callback function when Craft is fully initialized. |
preInit() | Pre-initializes the application. |
requireEdition() | Requires that Craft is running an equal or better edition than what's passed in |
run() | Runs the application. |
runAction() | Runs a controller action specified by a route. |
saveInfo() | Updates the info row. |
saveInfoAfterRequest() | Updates the info row at the end of the request. |
set() | Registers a component definition with this locator. |
setAliases() | Defines path aliases. |
setBasePath() | Sets the root directory of the application and the @app alias. |
setComponents() | Registers a set of component definitions in this locator. |
setContainer() | Configures Yii::$container with the $config. |
setControllerPath() | Sets the directory that contains the controller classes. |
setEdition() | Sets the installed Craft CMS edition. |
setInstance() | Sets the currently requested instance of this module class. |
setIsInstalled() | Sets Craft's record of whether it's installed |
setLayoutPath() | Sets the directory that contains the layout files. |
setModule() | Adds a sub-module to this module. |
setModules() | Registers sub-modules in the current module. |
setRuntimePath() | Sets the directory that stores runtime files. |
setTimeZone() | Sets the time zone used by this application. |
setVendorPath() | Sets the directory that stores vendor files. |
setVersion() | Sets current module version. |
setViewPath() | Sets the directory that contains the view files. |
trigger() | Triggers an event. |
updateTargetLanguage() | Sets the target application language. |
bootstrap()
​
Initializes extensions and executes bootstrap components.
This method is called by init() after the application has been fully configured. If you override this method, make sure you also call the parent implementation.
coreCommands()
​
Returns the configuration of the built-in commands.
Returns ​
array – The configuration of the built-in commands.
get()
​
Returns the component instance with the specified ID.
See also:
Arguments ​
$id
(string) – Component ID (e.g.db
).$throwException
(boolean) – Whether to throw an exception if$id
is not registered with the locator before.
Returns ​
object, null – The component of the specified ID. If $throwException
is false and $id
is not registered before, null will be returned.
Throws ​
- yii\base\InvalidConfigException
if$id
refers to a nonexistent component ID
getRequest()
​
Returns the request component.
Returns ​
getResponse()
​
Returns the response component.
Returns ​
getSession()
​
Throws ​
getUser()
​
Returns the user component.
Returns ​
handleRequest()
​
Handles the specified request.
Arguments ​
$request
(yii\console\Request) – The request to be handled
Returns ​
yii\console\Response – The resulting response
init()
​
Initialize the application.
runAction()
​
Runs a controller action specified by a route.
This method parses the specified route and creates the corresponding child module(s), controller and action instances. It then calls craft\console\Controller::runAction() to run the action with the given parameters. If the route is empty, the method will use defaultRoute.
For example, to run public function actionTest($a, $b)
assuming that the controller has options the following code should be used:
\Yii::$app->runAction('controller/test', ['option' => 'value', $a, $b]);
Arguments ​
$route
(string) – The route that specifies the action.$params
(array) – The parameters to be passed to the action
Returns ​
integer, yii\console\Response, null – The result of the action. This can be either an exit code or Response object. Exit code 0 means normal, and other values mean abnormal. Exit code of null
is treated as 0
as well.
Throws ​
- yii\console\Exception
if the route is invalid
setTimeZone()
​
Sets the time zone used by this application.
This is a simple wrapper of PHP function date_default_timezone_set(). Refer to the php manual for available timezones.
Arguments ​
$value
(string) – The time zone used by this application.
Protected Methods ​
Method | Description |
---|---|
defaultVersion() | Returns default module version. |
loadConfig() | Loads the configuration. |
registerErrorHandler() | Registers the errorHandler component as a PHP error handler. |
Constants ​
Constant | Description |
---|---|
OPTION_APPCONFIG | The option name for specifying the application configuration file path. |
STATE_AFTER_REQUEST | Application state used by state: application is triggering EVENT_AFTER_REQUEST. |
STATE_BEFORE_REQUEST | Application state used by state: application is triggering EVENT_BEFORE_REQUEST. |
STATE_BEGIN | Application state used by state: application just started. |
STATE_END | Application state used by state: application has ended. |
STATE_HANDLING_REQUEST | Application state used by state: application is handling the request. |
STATE_INIT | Application state used by state: application is initializing. |
STATE_SENDING_RESPONSE | Application state used by state: application is about to send response. |