Created
July 25, 2012 11:46
-
-
Save bakura10/3175711 to your computer and use it in GitHub Desktop.
Authentication Factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Common\Authentication\Service; | |
use DoctrineModule\Authentication\Adapter\ObjectRepository as DoctrineAdapter; | |
use DoctrineModule\Authentication\Storage\ObjectRepository as DoctrineStorage; | |
use DoctrineModule\Options\Authentication as AuthenticationOptions; | |
use Zend\Authentication\AuthenticationService; | |
use Zend\Authentication\Storage\Session as SessionStorage; | |
use Zend\ServiceManager\FactoryInterface; | |
use Zend\ServiceManager\ServiceLocatorInterface; | |
class ConfigFactory implements FactoryInterface | |
{ | |
/** | |
* @param ServiceLocatorInterface $serviceLocator | |
* @return AuthenticationService | |
*/ | |
public function createService(ServiceLocatorInterface $serviceLocator) | |
{ | |
/** @var $options AuthenticationOptions */ | |
$options = $this->getOptions($serviceLocator); | |
$em = $serviceLocator->get('doctrine.entitymanager.orm_default'); | |
$metadataFactory = $em->getMetadataFactory(); | |
$options->setObjectManager($em); | |
$storage = new DoctrineStorage($options->getObjectRepository(), $metadataFactory, new SessionStorage()); | |
$adapter = new DoctrineAdapter($options); | |
$authenticationService = new AuthenticationService($storage, $adapter); | |
return $authenticationService; | |
} | |
/** | |
* @param ServiceLocatorInterface $serviceLocator | |
* @return AuthenticationOptions | |
* @throws \RuntimeException | |
*/ | |
public function getOptions(ServiceLocatorInterface $serviceLocator) | |
{ | |
$options = $serviceLocator->get('Configuration'); | |
$options = $options['authentication']; | |
if ($options === null) { | |
throw new \RuntimeException('Configuration could not be found in authentication'); | |
} | |
return new AuthenticationOptions($options); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment