Last active
December 31, 2015 13:24
-
-
Save ionas/62fc3f7f00a1f291d2c5 to your computer and use it in GitHub Desktop.
CakePHP 3 App Core Configuration - require configuration to be set.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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