2014-11-14 10:02:49 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: Administrator
|
|
|
|
* Date: 2014/11/14
|
|
|
|
* Time: 11:34
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Westdc\Service\ServiceAgent;
|
|
|
|
|
|
|
|
use Zend\Config\Config as Zend_Config;
|
|
|
|
use Zend\Config\Reader\Ini as ReaderIni;
|
|
|
|
|
|
|
|
class Config {
|
|
|
|
|
|
|
|
public function get($configName = "")
|
|
|
|
{
|
2014-11-17 06:07:56 +00:00
|
|
|
if(defined(CONFIG_PATH))
|
2014-11-14 10:02:49 +00:00
|
|
|
{
|
2014-11-17 06:07:56 +00:00
|
|
|
throw new \RuntimeException('Not found the config files path');
|
2014-11-14 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$config_path = CONFIG_PATH;
|
|
|
|
|
|
|
|
if(empty($configName))
|
|
|
|
$configName = "global.php";
|
|
|
|
|
2014-11-17 06:07:56 +00:00
|
|
|
if(!preg_match("/(\\/|\\\)$/",$config_path))
|
2014-11-14 10:02:49 +00:00
|
|
|
{
|
2014-11-17 06:07:56 +00:00
|
|
|
$config_path .= "/";
|
2014-11-14 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
2014-11-17 06:07:56 +00:00
|
|
|
$configFile = $config_path .'autoload/' . $configName;
|
2014-11-14 10:02:49 +00:00
|
|
|
|
|
|
|
unset($config_path);
|
|
|
|
unset($configName);
|
|
|
|
|
|
|
|
if(!file_exists($configFile))
|
|
|
|
{
|
2014-11-17 06:07:56 +00:00
|
|
|
throw new \RuntimeException('The Config file is not exists');
|
2014-11-14 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$configFileExt = pathinfo($configFile,PATHINFO_EXTENSION);
|
|
|
|
|
|
|
|
if($configFileExt == "php")
|
|
|
|
{
|
2014-11-19 04:21:05 +00:00
|
|
|
$config_arr = include $configFile;
|
|
|
|
return new Zend_Config($config_arr);
|
2014-11-14 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if($configFileExt == 'ini')
|
|
|
|
{
|
2014-11-17 06:07:56 +00:00
|
|
|
$ini = new ReaderIni();
|
|
|
|
$ini->fromFile($configFile);
|
|
|
|
return $ini->fromFile($configFile);
|
2014-11-14 10:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|