westdc-core/Westdc/Service/ServiceAgent/Config.php

60 lines
1.3 KiB
PHP
Raw Normal View History

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 = "")
{
if(defined(CONFIG_PATH))
2014-11-14 10:02:49 +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";
if(!preg_match("/(\\/|\\\)$/",$config_path))
2014-11-14 10:02:49 +00:00
{
$config_path .= "/";
2014-11-14 10:02:49 +00:00
}
$configFile = $config_path .'autoload/' . $configName;
2014-11-14 10:02:49 +00:00
unset($config_path);
unset($configName);
if(!file_exists($configFile))
{
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")
{
$config_arr = include $configFile;
return new Zend_Config($config_arr);
2014-11-14 10:02:49 +00:00
}
if($configFileExt == 'ini')
{
$ini = new ReaderIni();
$ini->fromFile($configFile);
return $ini->fromFile($configFile);
2014-11-14 10:02:49 +00:00
}
}
}