add EventModel ,add AbstractServiceManager

This commit is contained in:
Jianxuan Li 2014-11-14 10:47:39 +08:00
parent 69ea4689a6
commit 65b89e1870
6 changed files with 185 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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);
}
}

View File

@ -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]);
}
}
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}