From 1864044f8e7f24d688baee099b85b16b2d8c4586 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Fri, 9 Jan 2015 23:33:25 +0800 Subject: [PATCH 1/2] profection the base classes --- Westdc/Helpers/Auth.php | 5 ++--- Westdc/Helpers/Config.php | 39 ++++++++++++++++++++++++++++----------- Westdc/Helpers/Layout.php | 20 +++++--------------- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/Westdc/Helpers/Auth.php b/Westdc/Helpers/Auth.php index 5334bc1..ecd87f0 100644 --- a/Westdc/Helpers/Auth.php +++ b/Westdc/Helpers/Auth.php @@ -1,9 +1,8 @@ "config/autoload/local.php", - 'global' => "config/autoload/global.php" - ); - + function __construct() { //$reader = new \Zend\Config\Reader\Ini(); //$data = $reader->fromFile('config/config.ini'); } - static function get($type = 'global') + static function get($configName = 'global') { - $config_path = array( - 'local' => "config/autoload/local.php", - 'global' => "config/autoload/global.php", - 'file' => "config/autoload/file.php" + if(defined(CONFIG_PATH)) + { + throw new \RuntimeException('Not found the config files path'); + } + + $config_path = CONFIG_PATH; + + if(empty($configName)) + $configName = "global.php"; + + if(!preg_match("/(\\/|\\\)$/",$config_path)) + { + $config_path .= "/"; + } + + $config_names = array( + 'local' => "local.php", + 'global' => "global.php", + 'file' => "file.php" ); + + $configFile = $config_path .'autoload/' . $config_names[$configName]; + + unset($config_path); + unset($configName); - $config = new \Zend\Config\Config(include $config_path[$type]); + $config = new \Zend\Config\Config(include $configFile); + return $config; } diff --git a/Westdc/Helpers/Layout.php b/Westdc/Helpers/Layout.php index 136c77a..44ce42a 100644 --- a/Westdc/Helpers/Layout.php +++ b/Westdc/Helpers/Layout.php @@ -3,17 +3,15 @@ namespace Westdc\Helpers; use \Zend\Authentication\AuthenticationService; use \Zend\Authentication\Storage\Session as SessionStorage; -use \Westdc\Helpers\Config; -use Westdc\Helpers\MobileDetect; use View as view; class Layout { - public $config; + function __construct() { - $this->config = Config::get(); + } //设置网页标题 @@ -26,8 +24,8 @@ class Layout return; } - $action = $matches->getParam('action'); - $controller = $matches->getParam('controller'); +// $action = $matches->getParam('action'); +// $controller = $matches->getParam('controller'); $viewHelperManager = $e->getApplication()->getServiceManager()->get('viewHelperManager'); @@ -36,15 +34,7 @@ class Layout // Setting a separator string for segments $headTitleHelper->setSeparator(' - '); - if(isset($this->config->title_map->$controller->action->$action)) - { - $headTitleHelper->append($this->config->title_map->$controller->action->$action->title); - } - - if(isset($this->config->title_map->$controller)) - { - $headTitleHelper->append($this->config->title_map->$controller->title); - } + return; } //导航条按钮激活 From 3b0b9a12c88167decb98de265fa01e01bef64ca3 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Sun, 11 Jan 2015 11:24:31 +0800 Subject: [PATCH 2/2] profection the base classes --- Westdc/Db/Pdo.php | 7 ++----- Westdc/Helpers/Tools.php | 6 +++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Westdc/Db/Pdo.php b/Westdc/Db/Pdo.php index ce6f3f5..83ea8c5 100644 --- a/Westdc/Db/Pdo.php +++ b/Westdc/Db/Pdo.php @@ -1,20 +1,17 @@ config_local_path); + $config_local = Config::get('local'); $dsn = "pgsql:host={$config_local->db->hostname};" . "port={$config_local->db->port};" diff --git a/Westdc/Helpers/Tools.php b/Westdc/Helpers/Tools.php index ee0658f..d8e4d3d 100644 --- a/Westdc/Helpers/Tools.php +++ b/Westdc/Helpers/Tools.php @@ -45,8 +45,12 @@ class Tools { { $response = array(); $handle = popen("$cmd 2>&1", 'r'); - $read = ''; + while ($read = fread($handle, 20096)) { + + if(!mb_detect_encoding($read, 'UTF-8', true)) + iconv("GB2312","UTF-8",$read); + $response[] = trim($read); } pclose($handle);