Configuration class. Used for managing runtime configuration information.
Provides features for reading and writing to the runtime configuration, as well as methods for loading additional configuration files or storing runtime configuration for future use.
arrayCake\Core\Configure\ConfigEngineInterface>
Configured engine classes, used to load config files from resources
bool|null
Flag to track whether ini_set exists.
array<string, mixed>
Array of values currently stored in Configure.
Get the configured engine. Internally used by Configure::load()
and Configure::dump()
Will create new PhpConfig for default if not configured yet.
Returns true if given variable is set in Configure.
Clear all values stored in Configure.
Add a new engine to Configure. Engines allow you to read configuration files in various formats/storage locations. CakePHP comes with two built-in engines PhpConfig and IniConfig. You can also implement your own engine classes in your application.
Gets the names of the configured Engine objects.
Used to read and delete a variable from Configure.
Used to consume information stored in Configure. It's not possible to store null
values in Configure.
Used to delete a variable from Configure.
Remove a configured engine. This will unset the engine and make any future attempts to use it cause an Exception.
Dump data currently in Configure into $key. The serialization format is decided by the config engine attached as $config. For example, if the 'default' adapter is a PhpConfig, the generated file will be a PHP configuration file loadable by the PhpConfig.
Returns true if the Engine objects is configured.
Loads stored configuration information from a resource. You can add config file resource engines with Configure::config()
.
Used to read information stored in Configure. It's not possible to store null
values in Configure.
Used to get information stored in Configure. It's not possible to store null
values in Configure.
Restores configuration data stored in the Cache into configure. Restored values will overwrite existing ones.
Used to write runtime configuration into Cache. Stored runtime configuration can be restored using Configure::restore()
. These methods can be used to enable configuration managers frontends, or other GUI type interfaces for configuration.
Used to determine the current version of CakePHP.
Used to store a dynamic variable in Configure.
_getEngine(string $config): Cake\Core\Configure\ConfigEngineInterface|null
Get the configured engine. Internally used by Configure::load()
and Configure::dump()
Will create new PhpConfig for default if not configured yet.
string
$config The name of the configured adapter
Cake\Core\Configure\ConfigEngineInterface|null
check(string $var): bool
Returns true if given variable is set in Configure.
string
$var Variable name to check for
bool
clear(): void
Clear all values stored in Configure.
void
config(string $name, Cake\Core\Configure\ConfigEngineInterface $engine): void
Add a new engine to Configure. Engines allow you to read configuration files in various formats/storage locations. CakePHP comes with two built-in engines PhpConfig and IniConfig. You can also implement your own engine classes in your application.
To add a new engine to Configure:
Configure::config('ini', new IniConfig());
string
$name The name of the engine being configured. This alias is used later to read values from a specific engine.
Cake\Core\Configure\ConfigEngineInterface
$engine The engine to append.
void
configured(): array<string>
Gets the names of the configured Engine objects.
array<string>
consume(string $var): array|string|null
Used to read and delete a variable from Configure.
This is primarily used during bootstrapping to move configuration data out of configure into the various other classes in CakePHP.
string
$var The key to read and remove.
array|string|null
consumeOrFail(string $var): mixed
Used to consume information stored in Configure. It's not possible to store null
values in Configure.
Acts as a wrapper around Configure::consume() and Configure::check(). The configure key/value pair consumed via this method is expected to exist. In case it does not an exception will be thrown.
string
$var Variable to consume. Use '.' to access array elements.
mixed
RuntimeException
delete(string $var): void
Used to delete a variable from Configure.
Usage:
Configure::delete('Name'); will delete the entire Configure::Name Configure::delete('Name.key'); will delete only the Configure::Name[key]
string
$var the var to be deleted
void
drop(string $name): bool
Remove a configured engine. This will unset the engine and make any future attempts to use it cause an Exception.
string
$name Name of the engine to drop.
bool
dump(string $key, string $config = 'default', array<string> $keys = []): bool
Dump data currently in Configure into $key. The serialization format is decided by the config engine attached as $config. For example, if the 'default' adapter is a PhpConfig, the generated file will be a PHP configuration file loadable by the PhpConfig.
Given that the 'default' engine is an instance of PhpConfig. Save all data in Configure to the file my_config.php
:
Configure::dump('my_config', 'default');
Save only the error handling configuration:
Configure::dump('error', 'default', ['Error', 'Exception'];
string
$key The identifier to create in the config adapter. This could be a filename or a cache key depending on the adapter being used.
string
$config optional The name of the configured adapter to dump data with.
array<string>
$keys optional The name of the top-level keys you want to dump. This allows you save only some data stored in Configure.
bool
Cake\Core\Exception\CakeException
isConfigured(string $name): bool
Returns true if the Engine objects is configured.
string
$name Engine name.
bool
load(string $key, string $config = 'default', bool $merge = true): bool
Loads stored configuration information from a resource. You can add config file resource engines with Configure::config()
.
Loaded configuration information will be merged with the current runtime configuration. You can load configuration files from plugins by preceding the filename with the plugin name.
Configure::load('Users.user', 'default')
Would load the 'user' config file using the default config engine. You can load app config files by giving the name of the resource you want loaded.
Configure::load('setup', 'default');
If using default
config and no engine has been configured for it yet, one will be automatically created using PhpConfig
string
$key name of configuration resource to load.
string
$config optional Name of the configured engine to use to read the resource identified by $key.
bool
$merge optional if config files should be merged instead of simply overridden
bool
Cake\Core\Exception\CakeException
read(string|null $var = null, mixed $default = null): mixed
Used to read information stored in Configure. It's not possible to store null
values in Configure.
Usage:
Configure::read('Name'); will return all values for Name Configure::read('Name.key'); will return only the value of Configure::Name[key]
string|null
$var optional Variable to obtain. Use '.' to access array elements.
mixed
$default optional The return value when the configure does not exist
mixed
readOrFail(string $var): mixed
Used to get information stored in Configure. It's not possible to store null
values in Configure.
Acts as a wrapper around Configure::read() and Configure::check(). The configure key/value pair fetched via this method is expected to exist. In case it does not an exception will be thrown.
Usage:
Configure::readOrFail('Name'); will return all values for Name Configure::readOrFail('Name.key'); will return only the value of Configure::Name[key]
string
$var Variable to obtain. Use '.' to access array elements.
mixed
RuntimeException
restore(string $name, string $cacheConfig = 'default'): bool
Restores configuration data stored in the Cache into configure. Restored values will overwrite existing ones.
string
$name Name of the stored config file to load.
string
$cacheConfig optional Name of the Cache configuration to read from.
bool
RuntimeException
store(string $name, string $cacheConfig = 'default', array|null $data = null): bool
Used to write runtime configuration into Cache. Stored runtime configuration can be restored using Configure::restore()
. These methods can be used to enable configuration managers frontends, or other GUI type interfaces for configuration.
string
$name The storage name for the saved configuration.
string
$cacheConfig optional The cache configuration to save into. Defaults to 'default'
array|null
$data optional Either an array of data to store, or leave empty to store all values.
bool
RuntimeException
version(): string
Used to determine the current version of CakePHP.
Usage
Configure::version();
string
write(array<string, mixed>|string $config, mixed $value = null): void
Used to store a dynamic variable in Configure.
Usage:
Configure::write('One.key1', 'value of the Configure::One[key1]'); Configure::write(['One.key1' => 'value of the Configure::One[key1]']); Configure::write('One', [ 'key1' => 'value of the Configure::One[key1]', 'key2' => 'value of the Configure::One[key2]' ]); Configure::write([ 'One.key1' => 'value of the Configure::One[key1]', 'One.key2' => 'value of the Configure::One[key2]' ]);
array<string, mixed>|string
$config The key to write, can be a dot notation value. Alternatively can be an array containing key(s) and value(s).
mixed
$value optional Value to set for var
void
Configured engine classes, used to load config files from resources
arrayCake\Core\Configure\ConfigEngineInterface>
Flag to track whether ini_set exists.
bool|null
Array of values currently stored in Configure.
array<string, mixed>
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.Core.Configure.html