|
@@ -18,6 +18,8 @@
|
|
namespace Qii\Config;
|
|
namespace Qii\Config;
|
|
|
|
|
|
use \Qii\Autoloader\Psr4;
|
|
use \Qii\Autoloader\Psr4;
|
|
|
|
+use Qii\Exceptions\InvalidFormat;
|
|
|
|
+use Qii\Exceptions\Variable;
|
|
|
|
|
|
class Register
|
|
class Register
|
|
{
|
|
{
|
|
@@ -83,7 +85,7 @@ class Register
|
|
*/
|
|
*/
|
|
public static function get($key, $default = null)
|
|
public static function get($key, $default = null)
|
|
{
|
|
{
|
|
- if (!$key) throw new \Qii\Exceptions\Variable(\Qii::i(1003), __LINE__);
|
|
|
|
|
|
+ if (!$key) throw new Variable(\Qii::i(1003), __LINE__);
|
|
//优先调用存在的get方法
|
|
//优先调用存在的get方法
|
|
$method = 'get' . $key;
|
|
$method = 'get' . $key;
|
|
if (method_exists('\Qii\Config\Register', $method)) return Register::$method();
|
|
if (method_exists('\Qii\Config\Register', $method)) return Register::$method();
|
|
@@ -135,9 +137,9 @@ class Register
|
|
*/
|
|
*/
|
|
public static function ini($fileName)
|
|
public static function ini($fileName)
|
|
{
|
|
{
|
|
- if (!$fileName) throw new \Qii\Exceptions\Variable(\Qii::i(1408), __LINE__);
|
|
|
|
|
|
+ if (!$fileName) throw new Variable(\Qii::i(1408), __LINE__);
|
|
$ini = parse_ini_file($fileName, true);
|
|
$ini = parse_ini_file($fileName, true);
|
|
- if (!$ini) throw new \Qii\Exceptions\InvalidFormat($fileName, __LINE__);
|
|
|
|
|
|
+ if (!$ini) throw new InvalidFormat($fileName, __LINE__);
|
|
$config = array();
|
|
$config = array();
|
|
foreach ($ini AS $namespace => $properties) {
|
|
foreach ($ini AS $namespace => $properties) {
|
|
$properties = Register::feval($properties);
|
|
$properties = Register::feval($properties);
|
|
@@ -268,7 +270,7 @@ class Register
|
|
//如果文件不可写,touch就有问题,就不写缓存文件
|
|
//如果文件不可写,touch就有问题,就不写缓存文件
|
|
if (self::$isWrite && is_writeable($iniFile)) {
|
|
if (self::$isWrite && is_writeable($iniFile)) {
|
|
file_put_contents($cacheFile, "<?php \n return " . var_export($common, true) . "\n?>", LOCK_EX);
|
|
file_put_contents($cacheFile, "<?php \n return " . var_export($common, true) . "\n?>", LOCK_EX);
|
|
- touch($iniFile);
|
|
|
|
|
|
+ touch($cacheFile, filemtime($iniFile));
|
|
}
|
|
}
|
|
Register::set($cacheName, $common);
|
|
Register::set($cacheName, $common);
|
|
return $common;
|
|
return $common;
|