Skip to content

Instantly share code, notes, and snippets.

@ionas
Last active December 31, 2015 13:24
Show Gist options
  • Save ionas/62fc3f7f00a1f291d2c5 to your computer and use it in GitHub Desktop.
Save ionas/62fc3f7f00a1f291d2c5 to your computer and use it in GitHub Desktop.
CakePHP 3 App Core Configuration - require configuration to be set.
<?php
/**
* 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 value fetched via get is expected to exist.
* In case it does not an exception will be thrown.
*
* Usage:
* ```
* Configure::get('Name'); will return all values for Name
* Configure::get('Name.key'); will return only the value of Configure::Name[key]
* ```
*
* @param string $var Variable to obtain. Use '.' to access array elements.
* @return mixed value stored in configure.
* @link http://book.cakephp.org/3.0/en/development/configuration.html#reading-configuration-data
* @throws \Cake\Core\Exception\Exception if the requested configuration is not set.
*/
public static function get($var) {
if (static::check($var) === false) {
throw new Exception(sprintf('Expected "%s" configuration.', $var));
}
return static::read($var);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment