profection the EventModel and EventService

This commit is contained in:
Jianxuan Li 2014-11-17 14:07:56 +08:00
parent 3c393a9144
commit f9dbc3e3db
5 changed files with 31 additions and 14 deletions

View File

@ -17,11 +17,15 @@ class HandleFactory extends AbstractServiceManager{
{
$config = $this->getServiceManager()->get('Config');
$handleName = $config->get('application.ini')->HandlesNamespace . "\\" . $handleName;
$appConfig = $config->get('application.ini');
$handleName = $appConfig['HandlesNamespace'] . "\\" . $handleName;
if(class_exists($handleName))
{
return new $handleName();
}else{
throw new \RuntimeException("Handle not exists");
}
}

View File

@ -17,7 +17,14 @@ class ListenerFactory extends AbstractServiceManager{
{
$config = $this->getServiceManager()->get('Config');
$listenerName = $config->get('application.ini')->ListenersNamespace . "\\" . $listenerName;
$appConfig = $config->get('application.ini');
$listenerName =$appConfig['ListenersNamespace'] . "\\" . $listenerName;
if(!class_exists($listenerName))
{
throw new \RuntimeException("Listener [" . $listenerName . "] not found");
}
if(empty($handle))
return new $listenerName();

View File

@ -13,4 +13,5 @@ use Westdc\Member\Account as Westdc_Account;
class Account extends Westdc_Account{
}

View File

@ -15,9 +15,9 @@ class Config {
public function get($configName = "")
{
if(!defined(CONFIG_PATH))
if(defined(CONFIG_PATH))
{
throw new RuntimeException('Not found the config files path');
throw new \RuntimeException('Not found the config files path');
}
$config_path = CONFIG_PATH;
@ -25,19 +25,19 @@ class Config {
if(empty($configName))
$configName = "global.php";
if(!preg_match("/(\\/|\\)$/",$config_path))
if(!preg_match("/(\\/|\\\)$/",$config_path))
{
$config_path .= PATH_SEPARATOR;
$config_path .= "/";
}
$configFile = $config_path . $configName;
$configFile = $config_path .'autoload/' . $configName;
unset($config_path);
unset($configName);
if(!file_exists($configFile))
{
return NULL;
throw new \RuntimeException('The Config file is not exists');
}
$configFileExt = pathinfo($configFile,PATHINFO_EXTENSION);
@ -49,7 +49,9 @@ class Config {
if($configFileExt == 'ini')
{
return new ReaderIni($configFile);
$ini = new ReaderIni();
$ini->fromFile($configFile);
return $ini->fromFile($configFile);
}
}

View File

@ -13,18 +13,21 @@ use Westdc\EventModel\HandleFactory;
class Event {
public function getListener($listenerName,$handleName = ""){
public function getListener($listenerName,$handle = ""){
$ListenerFactory = new ListenerFactory();
if(empty($handleName))
if(empty($handle))
{
$ListenerFactory->get($listenerName);
return $ListenerFactory->get($listenerName);
}else{
$ListenerFactory->get($listenerName,$handleName);
return $ListenerFactory->get($listenerName,$handle);
}
}
public function getHandle()
public function getHandle($handleName = "")
{
$handleFactory = new HandleFactory();
return $handleFactory->get($handleName);
}