将ServiceManager修改为单例模式,修改几处ServiceManager调用

This commit is contained in:
Jack Freeman 2015-02-21 23:17:27 +08:00
parent d668cc6aa4
commit dee53af2fc
5 changed files with 17 additions and 11 deletions

View File

@ -54,6 +54,7 @@ class Dbh
}
}else{
$sql = "INSERT INTO \"".$table."\" ($fields) VALUES ($datas) RETURNING id";
//exit($sql);
try{
$sth = $this->db->prepare($sql);
if($sth->execute())

View File

@ -14,7 +14,7 @@ class DefaultFileUploadListener implements ListenerAggregateInterface
function __construct()
{
$this->serviceManager = new ServiceManager();
$this->serviceManager = ServiceManager::getInstance();
$this->serviceManager = $this->serviceManager->getServiceManager();
}

View File

@ -43,7 +43,7 @@ class Mail extends AbstractEventManager implements ServiceManagerAwareInterface{
{
if(!$this->serviceManager instanceof ServiceManager)
{
$serviceManager = new WestdcServiceManager();
$serviceManager = WestdcServiceManager::getInstance();
$this->serviceManager = $serviceManager->getServiceManager();
}

View File

@ -29,7 +29,7 @@ class Sender implements ServiceManagerAwareInterface{
{
if(!$this->serviceManager instanceof ServiceManager)
{
$serviceManager = new WestdcServiceManager();
$serviceManager = WestdcServiceManager::getInstance();
$this->serviceManager = $serviceManager->getServiceManager();
}
}

View File

@ -1,20 +1,25 @@
<?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 static $instance = NULL;
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = new self;
}
return self::$instance;
}
private $serviceManager;
function __construct()
private function __construct()
{
$this->serviceManager = new Zend_ServiceManager;
$this->serviceManager->addAbstractFactory(new ServiceFactory);