Skip to content

Instantly share code, notes, and snippets.

@bakura10
Created July 26, 2012 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakura10/3184348 to your computer and use it in GitHub Desktop.
Save bakura10/3184348 to your computer and use it in GitHub Desktop.
<?php
namespace Common\Service;
use Doctrine\ORM\EntityManager;
use Zend\Authentication\AuthenticationService;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceManagerAwareInterface;
abstract class AbstractService implements ServiceManagerAwareInterface
{
/**
* @var ServiceManager
*/
protected $serviceManager;
/**
* @var EntityManager
*/
protected $entityManager;
/**
* @var AuthenticationService
*/
protected $authenticationService;
/**
* @param ServiceManager $serviceManager
* @return AbstractService
*/
public function setServiceManager(ServiceManager $serviceManager)
{
$this->serviceManager = $serviceManager;
return $this;
}
/**
* @return ServiceManager
*/
public function getServiceManager()
{
return $this->serviceManager;
}
/**
* @return AuthenticationService
*/
public function getAuthenticationService()
{
if (!$this->authenticationService) {
$this->authenticationService = $this->serviceManager->get('common.service.authentication');
}
return $this->authenticationService;
}
/**
* @return EntityManager
*/
public function getEntityManager()
{
if (!$this->entityManager) {
$this->entityManager = $this->serviceManager->get('doctrine.entitymanager.orm_default');
}
return $this->entityManager;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment