A trait that provides a set of static methods to manage configuration for classes that provide an adapter facade or need to have sets of configuration data registered and manipulated.
Implementing objects are expected to declare a static $_dsnClassMap
property.
array<string, mixed>
Configuration sets.
Returns an array containing the named configurations
Drops a constructed adapter.
Reads existing configuration.
Reads existing configuration for a specific key.
Returns the DSN class map for this class.
Parses a DSN into a valid connection configuration
This method can be used to define configuration adapters for an application.
Updates the DSN class map for this class.
configured(): array<string>
Returns an array containing the named configurations
array<string>
drop(string $config): bool
Drops a constructed adapter.
If you wish to modify an existing configuration, you should drop it, change configuration and then re-add it.
If the implementing objects supports a $_registry
object the named configuration will also be unloaded from the registry.
string
$config An existing configuration you wish to remove.
bool
getConfig(string $key): mixed|null
Reads existing configuration.
string
$key The name of the configuration.
mixed|null
getConfigOrFail(string $key): mixed
Reads existing configuration for a specific key.
The config value for this key must exist, it can never be null.
string
$key The name of the configuration.
mixed
InvalidArgumentException
getDsnClassMap(): array<string, string>
Returns the DSN class map for this class.
array<string, string>
parseDsn(string $dsn): array<string, mixed>
Parses a DSN into a valid connection configuration
This method allows setting a DSN using formatting similar to that used by PEAR::DB. The following is an example of its usage:
$dsn = 'mysql://user:pass@localhost/database?'; $config = ConnectionManager::parseDsn($dsn); $dsn = 'Cake\Log\Engine\FileLog://?types=notice,info,debug&file=debug&path=LOGS'; $config = Log::parseDsn($dsn); $dsn = 'smtp://user:secret@localhost:25?timeout=30&client=null&tls=null'; $config = Email::parseDsn($dsn); $dsn = 'file:///?className=\My\Cache\Engine\FileEngine'; $config = Cache::parseDsn($dsn); $dsn = 'File://?prefix=myapp_cake_core_&serialize=true&duration=+2 minutes&path=/tmp/persistent/'; $config = Cache::parseDsn($dsn);
For all classes, the value of scheme
is set as the value of both the className
unless they have been otherwise specified.
Note that querystring arguments are also parsed and set as values in the returned configuration.
string
$dsn The DSN string to convert to a configuration array
array<string, mixed>
InvalidArgumentException
setConfig(array<string, mixed>|string $key, object|array<string, mixed>|null $config = null): void
This method can be used to define configuration adapters for an application.
To change an adapter's configuration at runtime, first drop the adapter and then reconfigure it.
Adapters will not be constructed until the first operation is done.
Assuming that the class' name is Cache
the following scenarios are supported:
Setting a cache engine up.
Cache::setConfig('default', $settings);
Injecting a constructed adapter in:
Cache::setConfig('default', $instance);
Configure multiple adapters at once:
Cache::setConfig($arrayOfConfig);
array<string, mixed>|string
$key The name of the configuration, or an array of multiple configs.
object|array<string, mixed>|null
$config optional An array of name => configuration data for adapter.
void
BadMethodCallException
LogicException
setDsnClassMap(array<string, string> $map): void
Updates the DSN class map for this class.
array<string, string>
$map Additions/edits to the class map to apply.
void
Configuration sets.
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/trait-Cake.Core.StaticConfigTrait.html