add new ConfigService
This commit is contained in:
parent
65b89e1870
commit
3c393a9144
|
@ -9,13 +9,21 @@
|
||||||
namespace Westdc\EventModel;
|
namespace Westdc\EventModel;
|
||||||
|
|
||||||
use Westdc\EventModel\Handles;
|
use Westdc\EventModel\Handles;
|
||||||
|
use Westdc\Service\AbstractServiceManager;
|
||||||
|
|
||||||
class HandleFactory {
|
class HandleFactory extends AbstractServiceManager{
|
||||||
|
|
||||||
static function get($handleName)
|
public function get($handleName)
|
||||||
|
{
|
||||||
|
$config = $this->getServiceManager()->get('Config');
|
||||||
|
|
||||||
|
$handleName = $config->get('application.ini')->HandlesNamespace . "\\" . $handleName;
|
||||||
|
|
||||||
|
if(class_exists($handleName))
|
||||||
{
|
{
|
||||||
$handleName = __NAMESPACE__ . "\\Handles\\" . $handleName;
|
|
||||||
return new $handleName();
|
return new $handleName();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,12 +9,15 @@
|
||||||
namespace Westdc\EventModel;
|
namespace Westdc\EventModel;
|
||||||
|
|
||||||
use Westdc\EventModel\Listeners;
|
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))
|
if(empty($handle))
|
||||||
return new $listenerName();
|
return new $listenerName();
|
||||||
|
|
|
@ -1,22 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Westdc\Member;
|
namespace Westdc\Member;
|
||||||
|
|
||||||
use Zend\EventManager\EventManagerInterface;
|
use Westdc\EventModel\AbstractEventManager;
|
||||||
use Zend\EventManager\EventManager;
|
|
||||||
use Zend\EventManager\EventManagerAwareInterface;
|
|
||||||
use Zend\Authentication\AuthenticationService;
|
use Zend\Authentication\AuthenticationService;
|
||||||
use Zend\Authentication\Storage\Session as SessionStorage;
|
use Zend\Authentication\Storage\Session as SessionStorage;
|
||||||
use Westdc\Helpers\View as view;
|
use Westdc\Helpers\Assist as view;
|
||||||
use Westdc\Helpers\Config;
|
use Westdc\Helpers\Config;
|
||||||
use Westdc\Helpers\Dbh as dbh;
|
use Westdc\Helpers\Dbh as dbh;
|
||||||
use Westdc\Helpers\PDO as Db;
|
use Westdc\Db\PDO as Db;
|
||||||
use Westdc\Helpers\Db as Zend_Db;
|
|
||||||
use Westdc\Mail\Mail;
|
use Westdc\Mail\Mail;
|
||||||
use Westdc\User\Listener\AccountListener as Listener;
|
|
||||||
use Westdc\User\Listener\PwdListener;
|
|
||||||
use Westdc\User\Member;
|
use Westdc\User\Member;
|
||||||
|
|
||||||
class Account implements EventManagerAwareInterface
|
class Account extends AbstractEventManager
|
||||||
{
|
{
|
||||||
public $memberTable = "tbl_member";
|
public $memberTable = "tbl_member";
|
||||||
public $FieldUsername = "username";
|
public $FieldUsername = "username";
|
||||||
|
@ -36,27 +31,6 @@ class Account implements EventManagerAwareInterface
|
||||||
{
|
{
|
||||||
$this->db = new Db();
|
$this->db = new Db();
|
||||||
$this->config = Config::get();
|
$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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取账号信息,数组
|
//获取账号信息,数组
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
|
|
||||||
namespace Westdc\Service;
|
namespace Westdc\Service;
|
||||||
|
|
||||||
use Westdc\Service\ServiceManager;
|
|
||||||
|
|
||||||
abstract class AbstractServiceManager {
|
abstract class AbstractServiceManager {
|
||||||
|
|
||||||
public function getServiceManager()
|
public function getServiceManager()
|
||||||
|
|
|
@ -8,13 +8,9 @@
|
||||||
|
|
||||||
namespace Westdc\Service\ServiceAgent;
|
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()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?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))
|
||||||
|
{
|
||||||
|
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 .= PATH_SEPARATOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
$configFile = $config_path . $configName;
|
||||||
|
|
||||||
|
unset($config_path);
|
||||||
|
unset($configName);
|
||||||
|
|
||||||
|
if(!file_exists($configFile))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
$configFileExt = pathinfo($configFile,PATHINFO_EXTENSION);
|
||||||
|
|
||||||
|
if($configFileExt == "php")
|
||||||
|
{
|
||||||
|
return new Zend_Config(include_once($configFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
if($configFileExt == 'ini')
|
||||||
|
{
|
||||||
|
return new ReaderIni($configFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Administrator
|
||||||
|
* Date: 2014/11/14
|
||||||
|
* Time: 11:43
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Westdc\Service\ServiceAgent;
|
||||||
|
|
||||||
|
use Westdc\EventModel\ListenerFactory;
|
||||||
|
use Westdc\EventModel\HandleFactory;
|
||||||
|
|
||||||
|
class Event {
|
||||||
|
|
||||||
|
public function getListener($listenerName,$handleName = ""){
|
||||||
|
$ListenerFactory = new ListenerFactory();
|
||||||
|
if(empty($handleName))
|
||||||
|
{
|
||||||
|
$ListenerFactory->get($listenerName);
|
||||||
|
}else{
|
||||||
|
$ListenerFactory->get($listenerName,$handleName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHandle()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue