ProjectConfigController

Type
Class
Namespace
craft\console\controllers
Inherits
craft\console\controllers\ProjectConfigController » craft\console\Controller » yii\console\Controller (opens new window) » yii\base\Controller (opens new window) » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
Implements
yii\base\Configurable (opens new window), yii\base\ViewContextInterface (opens new window)
Uses traits
craft\console\ControllerTrait
Since
3.1.0

Manages the Project Config.

View source (opens new window)

# Public Properties

Property Description
action (opens new window) yii\base\Action (opens new window), null (opens new window) – The action that is currently being executed.
behaviors (opens new window) yii\base\Behavior (opens new window) – List of behaviors attached to this component.
color (opens new window) boolean (opens new window), null (opens new window) – Whether to enable ANSI color in the output.
defaultAction (opens new window) string (opens new window) – The ID of the action that is used when the action ID is not specified in the request.
external boolean (opens new window) – Whether to pull values from the project config YAML files instead of the loaded config.
force boolean (opens new window) – Whether every entry change should be force-applied.
help (opens new window) boolean (opens new window) – Whether to display help information about current command.
helpSummary (opens new window) string (opens new window)
id (opens new window) string (opens new window) – The ID of this controller.
interactive (opens new window) boolean (opens new window) – Whether to run the command interactively.
invert boolean (opens new window) – Whether to treat the loaded project config as the source of truth, instead of the YAML files.
isolated – Whether the command should ensure it is only being run once at a time.
layout (opens new window) string (opens new window), null (opens new window), false (opens new window) – The name of the layout to be applied to this controller's views.
message string (opens new window), null (opens new window) – A message describing the changes.
module (opens new window) yii\base\Module (opens new window) – The module that this controller belongs to.
modules (opens new window) yii\base\Module (opens new window) – All ancestor modules that this controller is located within.
overwrite boolean (opens new window) – Whether to overwrite an existing export file, if a specific file path is given.
passedOptionValues (opens new window) array (opens new window) – The properties corresponding to the passed options.
passedOptions (opens new window) array (opens new window) – The names of the options passed during execution.
quiet boolean (opens new window) – Whether to reduce the command output.
request craft\console\Request
response (opens new window) yii\base\Response (opens new window), array (opens new window), string (opens new window) – The response.
route (opens new window) string (opens new window) – The route (module ID, controller ID and action ID) of the current request.
silentExitOnException (opens new window) boolean (opens new window), null (opens new window) – If true - script finish with ExitCode::OK in case of exception.
uniqueId (opens new window) string (opens new window) – The controller ID that is prefixed with the module ID (if any).
updateTimestamp boolean (opens new window) – Whether the dateModified value should be updated
view (opens new window) yii\base\View (opens new window), yii\web\View (opens new window) – The view object that can be used to render views or view files.
viewPath (opens new window) string (opens new window) – The directory containing the view files for this controller.

# external

Type
boolean (opens new window)
Default value
false
Since
4.1.0

Whether to pull values from the project config YAML files instead of the loaded config.

View source (opens new window)

# force

Type
boolean (opens new window)
Default value
false

Whether every entry change should be force-applied.

View source (opens new window)

# invert

Type
boolean (opens new window)
Default value
false
Since
3.5.13

Whether to treat the loaded project config as the source of truth, instead of the YAML files.

View source (opens new window)

# message

Type
string (opens new window), null (opens new window)
Default value
null
Since
4.1.0

A message describing the changes.

See also craft\services\ProjectConfig::set()

View source (opens new window)

# overwrite

Type
boolean (opens new window)
Default value
false
Since
4.2.1

Whether to overwrite an existing export file, if a specific file path is given.

View source (opens new window)

# quiet

Type
boolean (opens new window)
Default value
false
Since
4.4.0

Whether to reduce the command output.

View source (opens new window)

# updateTimestamp

Type
boolean (opens new window)
Default value
false
Since
4.1.0

Whether the dateModified value should be updated

See also craft\services\ProjectConfig::set()

View source (opens new window)

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__clone() (opens new window) This method is called after the object is created by cloning an existing one.
__construct() (opens new window)
__get() Returns the value of a component property.
__isset() Checks if a property is set, i.e. defined and not null.
__set() Sets the value of a component property.
__unset() (opens new window) Sets a component property to be null.
actionApply() Applies project config file changes.
actionDiff() Outputs a diff of the pending project config YAML changes.
actionExport() Exports the entire project config to a single file.
actionGet() Outputs a project config value.
actionRebuild() Rebuilds the project config.
actionRemove() Removes a project config value.
actionSet() Sets a project config value.
actionSync() DEPRECATED. Use project-config/apply instead.
actionTouch() Updates the dateModified value in config/project/project.yaml, attempting to resolve a Git conflict for it.
actionWrite() Writes out the currently-loaded project config as YAML files to the config/project/ folder, discarding any pending YAML changes.
actions() Declares external actions for the controller.
afterAction() (opens new window) This method is invoked right after an action is executed.
ansiFormat() (opens new window) Formats a string with ANSI codes.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
beforeAction() This method is invoked right before an action is executed.
behaviors() (opens new window) Returns a list of behaviors that this component should behave as.
bindActionParams() (opens new window) Binds the parameters to the action.
canGetProperty() (opens new window) Returns a value indicating whether a property can be read.
canSetProperty() (opens new window) Returns a value indicating whether a property can be set.
className() (opens new window) Returns the fully qualified name of this class.
confirm() (opens new window) Asks user to confirm by typing y or n.
createAction() (opens new window) Creates an action based on the given action ID.
createDirectory() Creates a directory, and outputs to the console.
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
do() Performs an action with descriptive output.
ensureBehaviors() (opens new window) Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component.
failure() Outputs a failure message to the console.
findLayoutFile() (opens new window) Finds the applicable layout file.
getActionArgsHelp() Returns the help information for the anonymous arguments for the action.
getActionHelp() Returns the detailed help information for the specified action.
getActionHelpSummary() Returns a one-line short summary describing the specified action.
getActionOptionsHelp() Returns the help information for the options for the action.
getBehavior() (opens new window) Returns the named behavior object.
getBehaviors() (opens new window) Returns all behaviors attached to this component.
getHelp() (opens new window) Returns help information for this controller.
getHelpSummary() (opens new window) Returns one-line short summary describing this controller.
getModules() (opens new window) Returns all ancestor modules of this controller.
getOptionValues() (opens new window) Returns properties corresponding to the options for the action id Child classes may override this method to specify possible properties.
getPassedOptionValues() (opens new window) Returns the properties corresponding to the passed options.
getPassedOptions() (opens new window) Returns the names of valid options passed during execution.
getRoute() (opens new window) Returns the route of the current request.
getUniqueId() (opens new window) Returns the unique ID of the controller.
getView() (opens new window) Returns the view object that can be used to render views or view files.
getViewPath() (opens new window) Returns the directory containing view files for this controller.
hasEventHandlers() (opens new window) Returns a value indicating whether there is any handler attached to the named event.
hasMethod() (opens new window) Returns a value indicating whether a method is defined.
hasProperty() (opens new window) Returns a value indicating whether a property is defined for this component.
init() Initializes the object.
isColorEnabled() (opens new window) Returns a value indicating whether ANSI color is enabled.
markdownToAnsi() Converts Markdown to be better readable in console environments by applying some ANSI format.
note() Outputs a note to the console.
off() (opens new window) Detaches an existing event handler from this component.
on() (opens new window) Attaches an event handler to an event.
onFinishProcessingItem() Called when a project config item has finished getting processed.
onStartProcessingItem() Called when a project config item has started getting processed.
optionAliases() (opens new window) Returns option alias names.
options() Returns the names of valid options for the action (id) An option requires the existence of a public member variable whose name is the option name.
passwordPrompt() Prompts the user for a password and validates it.
prompt() (opens new window) Prompts the user for input and validates it.
render() (opens new window) Renders a view and applies layout if available.
renderContent() (opens new window) Renders a static string by applying a layout.
renderFile() (opens new window) Renders a view file.
renderPartial() (opens new window) Renders a view without applying layout.
run() Runs a request specified in terms of a route.
runAction() Runs an action within this controller with the specified action ID and parameters.
select() (opens new window) Gives the user an option to choose from. Giving '?' as an input will show a list of options to choose from and their explanations.
setView() (opens new window) Sets the view object to be used by this controller.
setViewPath() (opens new window) Sets the directory that contains the view files.
stderr() (opens new window) Prints a string to STDERR.
stdout() (opens new window) Prints a string to STDOUT.
success() Outputs a success message to the console.
table() Outputs a table via craft\helpers\Console::table().
tip() Outputs a tip to the console.
trigger() (opens new window) Triggers an event.
warning() Outputs a warning to the console.
writeJson() JSON-encodes a value and writes it to a file.
writeToFile() Writes contents to a file, and outputs to the console.

# actionApply()

Applies project config file changes.

View source (opens new window)

Returns

integer (opens new window)

# actionDiff()

Since
3.5.6

Outputs a diff of the pending project config YAML changes.

View source (opens new window)

Returns

integer (opens new window)

# actionExport()

Since
4.2.1

Exports the entire project config to a single file.

View source (opens new window)

Arguments

  • $path (string (opens new window), null (opens new window)) – The path the project config should be exported to. Can be any of the following:

  • A full file path

  • A folder path (export will be saved in there with a dynamically-generated name)

  • A filename (export will be saved in the working directory with the given name)

  • Blank (export will be saved in the working directly with a dynamically-generated name)

# actionGet()

Since
4.1.0

Outputs a project config value.

Example:

php craft project-config/get system.edition

The “path” syntax used here may be composed of directory and filenames (within your config/project folder), YAML object keys (including UUIDs for many Craft resources), and integers (referencing numerically-indexed arrays), joined by a dot (.): path.to.nested.array.0.property.

View source (opens new window)

Arguments

Returns

integer (opens new window)

# actionRebuild()

Since
3.1.20

Rebuilds the project config.

View source (opens new window)

Returns

integer (opens new window)

# actionRemove()

Since
4.1.0

Removes a project config value.

Example:

php craft project-config/remove some.nested.key

DANGER

This should only be used when the equivalent change is not possible through the control panel or other Craft APIs. By directly modifying project config values, you are bypassing all validation and can easily destabilize configuration.

As with set, removing values only updates the root dateModified key when using the --update-timestamp flag. If you do not include this flag, you must run project-config/touch before changes will be detected or applied in other environments!

View source (opens new window)

Arguments

Returns

integer (opens new window)

# actionSet()

Since
4.1.0

Sets a project config value.

Example:

php craft project-config/set some.nested.key

See get for the accepted key formats.

DANGER

This should only be used when the equivalent change is not possible through the control panel or other Craft APIs. By directly modifying project config values, you are bypassing all validation and can easily destabilize configuration.

Values are updated in the database and in your local YAML files, but the root dateModified project config property is only touched when using the --update-timestamp flag. If you do not update the timestamp along with the value, the change may not be detected or applied in other environments!

View source (opens new window)

Arguments

Returns

integer (opens new window)

# actionSync()

DEPRECATED

Deprecated in 3.5.0. Use actionApply() instead.

DEPRECATED. Use project-config/apply instead.

View source (opens new window)

Returns

integer (opens new window)

# actionTouch()

Updates the dateModified value in config/project/project.yaml, attempting to resolve a Git conflict for it.

View source (opens new window)

Returns

integer (opens new window)

# actionWrite()

Since
3.5.13

Writes out the currently-loaded project config as YAML files to the config/project/ folder, discarding any pending YAML changes.

View source (opens new window)

Returns

integer (opens new window)

# onFinishProcessingItem()

Since
3.6.10

Called when a project config item has finished getting processed.

View source (opens new window)

Arguments

# onStartProcessingItem()

Since
3.6.10

Called when a project config item has started getting processed.

View source (opens new window)

Arguments

# options()

Returns the names of valid options for the action (id) An option requires the existence of a public member variable whose name is the option name.

Child classes may override this method to specify possible options.

Note that the values setting via options are not available until beforeAction() is being called.

View source (opens new window)

Arguments

Returns

string (opens new window)[] – The names of the options valid for the action

# Protected Methods

Method Description
bindInjectedParams() (opens new window) Fills parameters based on types and names in action method signature.
checkRootUser() Returns whether a command should be executed depending on whether it's being run as a root user, and whether they're OK with that.
checkTty() Sets yii\console\Controller::$interactive (opens new window) to false if this isn’t a TTY shell.
createAttributeValidator() Creates a function for the validator option of Controller::prompt.
defineActions() Returns an array of custom actions that should be available on the controller.
getActionMethodReflection()
outputCommand()
parseDocCommentDetail() (opens new window) Returns full description from the docblock.
parseDocCommentSummary() (opens new window) Returns the first line of docblock.
parseDocCommentTags() (opens new window) Parses the comment block into tags.

# Constants

Constant Description
EXIT_CODE_ERROR
EXIT_CODE_NORMAL