use null instead of an exception again
This commit is contained in:
parent
c27418dd11
commit
ed444b00d1
3 changed files with 2 additions and 29 deletions
|
@ -8,7 +8,6 @@ namespace Sakura;
|
|||
|
||||
use Sakura\Exceptions\ConfigNonExistentException;
|
||||
use Sakura\Exceptions\ConfigParseException;
|
||||
use Sakura\Exceptions\ConfigValueNotFoundException;
|
||||
|
||||
/**
|
||||
* Handles the configuration settings of Sakura.
|
||||
|
@ -50,7 +49,6 @@ class Config
|
|||
* Get a value from the configuration.
|
||||
* @param string $section
|
||||
* @param string $key
|
||||
* @throws ConfigValueNotFoundException
|
||||
* @return array|string
|
||||
*/
|
||||
public static function get(string $section, string $key = null)
|
||||
|
@ -66,6 +64,6 @@ class Config
|
|||
return self::$config[$section];
|
||||
}
|
||||
|
||||
throw new ConfigValueNotFoundException;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Holds an exception class.
|
||||
* @package Sakura
|
||||
*/
|
||||
|
||||
namespace Sakura\Exceptions;
|
||||
|
||||
/**
|
||||
* Thrown when a non-existent config value is requested.
|
||||
* @package Sakura
|
||||
* @author Julian van de Groep <me@flash.moe>
|
||||
*/
|
||||
class ConfigValueNotFoundException extends BaseException
|
||||
{
|
||||
}
|
11
utility.php
11
utility.php
|
@ -4,7 +4,6 @@
|
|||
*/
|
||||
|
||||
use Sakura\Config;
|
||||
use Sakura\Exceptions\ConfigValueNotFoundException;
|
||||
use Sakura\FileSystem;
|
||||
use Sakura\Net;
|
||||
use Sakura\Router;
|
||||
|
@ -17,15 +16,7 @@ function config($value)
|
|||
$key = array_pop($split);
|
||||
$section = implode('.', $split);
|
||||
|
||||
try {
|
||||
return Config::get($section, $key);
|
||||
} catch (ConfigValueNotFoundException $e) {
|
||||
try {
|
||||
return Config::get($value);
|
||||
} catch (ConfigValueNotFoundException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return Config::get($section, $key) ?? Config::get($value) ?? null;
|
||||
}
|
||||
|
||||
// Alias for Router::route
|
||||
|
|
Reference in a new issue