From 3c393a9144f5d0afdc0a0425e36b6bd3d783c661 Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Fri, 14 Nov 2014 18:02:49 +0800 Subject: [PATCH] add new ConfigService --- Westdc/EventModel/HandleFactory.php | 16 ++++-- Westdc/EventModel/ListenerFactory.php | 9 ++- Westdc/Member/Account.php | 34 ++--------- Westdc/Service/AbstractServiceManager.php | 2 - .../ServiceAgent/{User.php => Account.php} | 8 +-- Westdc/Service/ServiceAgent/Config.php | 57 +++++++++++++++++++ Westdc/Service/ServiceAgent/Event.php | 31 ++++++++++ 7 files changed, 112 insertions(+), 45 deletions(-) rename Westdc/Service/ServiceAgent/{User.php => Account.php} (50%) create mode 100644 Westdc/Service/ServiceAgent/Config.php create mode 100644 Westdc/Service/ServiceAgent/Event.php diff --git a/Westdc/EventModel/HandleFactory.php b/Westdc/EventModel/HandleFactory.php index 00185b2..529fda1 100644 --- a/Westdc/EventModel/HandleFactory.php +++ b/Westdc/EventModel/HandleFactory.php @@ -9,13 +9,21 @@ namespace Westdc\EventModel; use Westdc\EventModel\Handles; +use Westdc\Service\AbstractServiceManager; -class HandleFactory { +class HandleFactory extends AbstractServiceManager{ - static function get($handleName) + public function get($handleName) { - $handleName = __NAMESPACE__ . "\\Handles\\" . $handleName; - return new $handleName(); + $config = $this->getServiceManager()->get('Config'); + + $handleName = $config->get('application.ini')->HandlesNamespace . "\\" . $handleName; + + if(class_exists($handleName)) + { + return new $handleName(); + } + } } \ No newline at end of file diff --git a/Westdc/EventModel/ListenerFactory.php b/Westdc/EventModel/ListenerFactory.php index b6c23d9..31a35dc 100644 --- a/Westdc/EventModel/ListenerFactory.php +++ b/Westdc/EventModel/ListenerFactory.php @@ -9,12 +9,15 @@ namespace Westdc\EventModel; use Westdc\EventModel\Listeners; +use Westdc\Service\AbstractServiceManager; -class ListenerFactory { +class ListenerFactory extends AbstractServiceManager{ - static function get($listenerName,$handle = "") + public function get($listenerName,$handle = "") { - $listenerName = __NAMESPACE__ . "\\Listeners\\" . $listenerName; + $config = $this->getServiceManager()->get('Config'); + + $listenerName = $config->get('application.ini')->ListenersNamespace . "\\" . $listenerName; if(empty($handle)) return new $listenerName(); diff --git a/Westdc/Member/Account.php b/Westdc/Member/Account.php index 189936b..d218b75 100644 --- a/Westdc/Member/Account.php +++ b/Westdc/Member/Account.php @@ -1,22 +1,17 @@ db = new Db(); $this->config = Config::get(); - - $Listener = new Listener(); - $this->getEventManager()->attachAggregate($Listener); } - public function setEventManager(EventManagerInterface $events) - { - $events->setIdentifiers(array( - __CLASS__, - get_called_class(), - )); - $this->events = $events; - return $this; - } - - public function getEventManager() - { - if (NULL === $this->events) { - $this->setEventManager(new EventManager()); - } - return $this->events; - } - //获取账号信息,数组 public function getAccountInfo($id = 0) { diff --git a/Westdc/Service/AbstractServiceManager.php b/Westdc/Service/AbstractServiceManager.php index 7ac6d1f..5133892 100644 --- a/Westdc/Service/AbstractServiceManager.php +++ b/Westdc/Service/AbstractServiceManager.php @@ -8,8 +8,6 @@ namespace Westdc\Service; -use Westdc\Service\ServiceManager; - abstract class AbstractServiceManager { public function getServiceManager() diff --git a/Westdc/Service/ServiceAgent/User.php b/Westdc/Service/ServiceAgent/Account.php similarity index 50% rename from Westdc/Service/ServiceAgent/User.php rename to Westdc/Service/ServiceAgent/Account.php index 5d9f848..15834ce 100644 --- a/Westdc/Service/ServiceAgent/User.php +++ b/Westdc/Service/ServiceAgent/Account.php @@ -8,13 +8,9 @@ namespace Westdc\Service\ServiceAgent; -use Westdc\Member\Account; +use Westdc\Member\Account as Westdc_Account; -class User extends Account implements WestdcConfigureInterface{ +class Account extends Westdc_Account{ - private function init() - { - - } } \ No newline at end of file diff --git a/Westdc/Service/ServiceAgent/Config.php b/Westdc/Service/ServiceAgent/Config.php new file mode 100644 index 0000000..c0d90c0 --- /dev/null +++ b/Westdc/Service/ServiceAgent/Config.php @@ -0,0 +1,57 @@ +get($listenerName); + }else{ + $ListenerFactory->get($listenerName,$handleName); + } + } + + public function getHandle() + { + + } + +} \ No newline at end of file