|
|
@@ -16,6 +16,7 @@ namespace Cake\Core;
|
|
|
|
|
|
use Cake\Core\Exception\Exception;
|
|
|
use Cake\Utility\Hash;
|
|
|
+use InvalidArgumentException;
|
|
|
|
|
|
/**
|
|
|
* A trait for reading and writing instance config
|
|
|
@@ -109,8 +110,8 @@ trait InstanceConfigTrait
|
|
|
* ```
|
|
|
*
|
|
|
* @param string|null $key The key to get or null for the whole config.
|
|
|
- * @param mixed $default The return value when the key does not exist.
|
|
|
- * @return mixed Configuration data at the named key or null if the key does not exist.
|
|
|
+ * @param mixed|null $default The return value when the key does not exist.
|
|
|
+ * @return mixed|null Configuration data at the named key or null if the key does not exist.
|
|
|
*/
|
|
|
public function getConfig($key = null, $default = null)
|
|
|
{
|
|
|
@@ -187,6 +188,29 @@ trait InstanceConfigTrait
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Returns the config for this specific key.
|
|
|
+ *
|
|
|
+ * The config value for this key must exist, it can never be null.
|
|
|
+ *
|
|
|
+ * @param string $key The key to get.
|
|
|
+ * @return mixed Configuration data at the named key
|
|
|
+ * @throws \InvalidArgumentException
|
|
|
+ */
|
|
|
+ public function getConfigOrFail($key)
|
|
|
+ {
|
|
|
+ if (!isset($key)) {
|
|
|
+ throw new InvalidArgumentException('$key must not be null.');
|
|
|
+ }
|
|
|
+
|
|
|
+ $config = $this->getConfig($key);
|
|
|
+ if ($config === null) {
|
|
|
+ throw new InvalidArgumentException(sprintf('Expected configuration `%s` not found.', $key));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $config;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Merge provided config with existing config. Unlike `config()` which does
|
|
|
* a recursive merge for nested keys, this method does a simple merge.
|
|
|
*
|