add EventModel ,add AbstractServiceManager
This commit is contained in:
parent
69ea4689a6
commit
65b89e1870
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2014/11/10
|
||||
* Time: 11:43
|
||||
*/
|
||||
|
||||
namespace Westdc\EventModel;
|
||||
|
||||
use Zend\EventManager\EventManagerInterface;
|
||||
use Zend\EventManager\EventManager;
|
||||
use Zend\EventManager\EventManagerAwareInterface;
|
||||
|
||||
abstract class AbstractEventManager {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2014/11/10
|
||||
* Time: 13:36
|
||||
*/
|
||||
|
||||
namespace Westdc\EventModel;
|
||||
|
||||
use Westdc\EventModel\Handles;
|
||||
|
||||
class HandleFactory {
|
||||
|
||||
static function get($handleName)
|
||||
{
|
||||
$handleName = __NAMESPACE__ . "\\Handles\\" . $handleName;
|
||||
return new $handleName();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2014/11/10
|
||||
* Time: 11:46
|
||||
*/
|
||||
|
||||
namespace Westdc\EventModel;
|
||||
|
||||
use Westdc\EventModel\Listeners;
|
||||
|
||||
class ListenerFactory {
|
||||
|
||||
static function get($listenerName,$handle = "")
|
||||
{
|
||||
$listenerName = __NAMESPACE__ . "\\Listeners\\" . $listenerName;
|
||||
|
||||
if(empty($handle))
|
||||
return new $listenerName();
|
||||
|
||||
return new $listenerName($handle);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2014/11/10
|
||||
* Time: 13:26
|
||||
*/
|
||||
|
||||
namespace Westdc\EventModel\Listeners;
|
||||
|
||||
use Zend\EventManager\ListenerAggregateInterface;
|
||||
use Zend\EventManager\EventManagerInterface;
|
||||
|
||||
class StandardFormListener implements ListenerAggregateInterface{
|
||||
|
||||
protected $listeners = array();
|
||||
protected $handle;
|
||||
|
||||
function __construct($handle)
|
||||
{
|
||||
$this->handle = $handle;
|
||||
unset($handle);
|
||||
}
|
||||
|
||||
public function attach(EventManagerInterface $events)
|
||||
{
|
||||
$this->listeners[] = $events->attach('submit.checkParam', array($this->handle, 'checkParam'), 100);
|
||||
$this->listeners[] = $events->attach('submit.processData', array($this->handle, 'processData'), 100);
|
||||
$this->listeners[] = $events->attach('submit.recordPosted', array($this->handle, 'recordPosted'), 100);
|
||||
$this->listeners[] = $events->attach('submit.recordChanged', array($this->handle, 'recordChanged'), 100);
|
||||
}
|
||||
|
||||
public function detach(EventManagerInterface $events)
|
||||
{
|
||||
foreach ($this->listeners as $index => $listener) {
|
||||
if ($events->detach($listener)) {
|
||||
unset($this->listeners[$index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2014/11/11
|
||||
* Time: 11:05
|
||||
*/
|
||||
|
||||
namespace Westdc\Service;
|
||||
|
||||
use Westdc\Service\ServiceManager;
|
||||
|
||||
abstract class AbstractServiceManager {
|
||||
|
||||
public function getServiceManager()
|
||||
{
|
||||
$sm = new ServiceManager();
|
||||
return $sm->getServiceManager();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2014/11/11
|
||||
* Time: 11:12
|
||||
*/
|
||||
|
||||
namespace Westdc\Service;
|
||||
|
||||
use Zend\ServiceManager\ServiceManager as Zend_ServiceManager;
|
||||
|
||||
class ServiceManager {
|
||||
|
||||
private $serviceManager;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->serviceManager = new Zend_ServiceManager();
|
||||
$this->serviceManager->addAbstractFactory(new ServiceFactory);
|
||||
}
|
||||
|
||||
public function addKey($key,$value = "")
|
||||
{
|
||||
if(!empty($value))
|
||||
$this->serviceManager->$key($value);
|
||||
else
|
||||
$this->serviceManager->$key();
|
||||
}
|
||||
|
||||
public function setServiceManager(Zend_ServiceManager $service)
|
||||
{
|
||||
$this->serviceManager = $service;
|
||||
}
|
||||
|
||||
public function getServiceManager()
|
||||
{
|
||||
return $this->serviceManager;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue