Craft 3 Class Reference

Class craft\services\Config

Inheritance
craft\services\Config » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/services/Config.php

The Config service provides APIs for retrieving the values of Craft’s config settings, as well as the values of any plugins’ config settings.

An instance of the Config service is globally accessible in Craft via Craft::$app->config.

Public Properties
Property Type Description Defined By
$appDefaultsDir string The path to the directory containing the default application config settings craft\services\Config
$configDir string The path to the config directory craft\services\Config
$env string, null The environment ID Craft is currently running in. craft\services\Config
Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getConfigFilePath() Returns the path to a config file. craft\services\Config
getConfigFromFile() Loads a config file from the config/ folder, checks if it's a multi-environment config, and returns the values. craft\services\Config
getConfigSettings() Returns all of the config settings for a given category. craft\services\Config
getDb() Returns the DB config settings. craft\services\Config
getDotEnvPath() Returns the path to the .env file (regardless of whether it exists). craft\services\Config
getGeneral() Returns the general config settings. craft\services\Config
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
setDotEnvVar() Sets an environment variable value in the project's .env file. craft\services\Config
trigger() Triggers an event. yii\base\Component
Constants
Constant Value Description Defined By
CATEGORY_DB 'db' craft\services\Config
CATEGORY_GENERAL 'general' craft\services\Config

Property Details

$appDefaultsDir public property #

The path to the directory containing the default application config settings

public string $appDefaultsDir ''

$configDir public property #

The path to the config directory

public string $configDir ''

$env public property #

The environment ID Craft is currently running in.

public string, null $env null

Method Details

getConfigFilePath() public method #

Returns the path to a config file.

public string getConfigFilePath ( \craft\services\string $filename )
$filename string The filename (sans .php extension)

getConfigFromFile() public method #

Loads a config file from the config/ folder, checks if it's a multi-environment config, and returns the values.

public array getConfigFromFile ( \craft\services\string $filename )
$filename

getConfigSettings() public method #

Returns all of the config settings for a given category.

public yii\base\BaseObject getConfigSettings ( \craft\services\string $category )
$category string The config category
return yii\base\BaseObject The config settings
throws yii\base\InvalidArgumentException if $category is invalid
throws yii\base\InvalidConfigException if the securityKey general config setting is not set, and a auto-generated one could not be saved

getDb() public method #

Returns the DB config settings.

public craft\config\DbConfig getDb ( )

getDotEnvPath() public method #

Returns the path to the .env file (regardless of whether it exists).

public string getDotEnvPath ( )

getGeneral() public method #

Returns the general config settings.

public craft\config\GeneralConfig getGeneral ( )

setDotEnvVar() public method #

Sets an environment variable value in the project's .env file.

public void setDotEnvVar ( $name, $value )
$name string The environment variable name
$value string The environment variable value
throws yii\base\Exception if the .env file doesn't exist