diff --git a/config/module.config.php b/config/module.config.php index c38cfe09..0ab05b92 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -7,8 +7,8 @@ ), ), 'controller_plugins' => array( - 'invokables' => array( - 'scnsocialauthprovider' => 'ScnSocialAuth\Controller\Plugin\ScnSocialAuthProvider', + 'factories' => array( + 'scnSocialAuthProvider' => 'ScnSocialAuth\Service\ProviderControllerPluginFactory', ), ), 'router' => array( diff --git a/src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php b/src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php index f3bb8187..9a68eacd 100644 --- a/src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php +++ b/src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php @@ -6,8 +6,6 @@ use ScnSocialAuth\Mapper\UserProviderInterface; use ScnSocialAuth\Options\ModuleOptions; use Zend\Authentication\Result; -use Zend\ServiceManager\ServiceManagerAwareInterface; -use Zend\ServiceManager\ServiceManager; use ZfcUser\Authentication\Adapter\AbstractAdapter; use ZfcUser\Authentication\Adapter\AdapterChainEvent as AuthEvent; use ZfcUser\Entity\UserInterface; @@ -17,18 +15,13 @@ use Zend\EventManager\EventManager; use Zend\EventManager\EventManagerAwareInterface; -class HybridAuth extends AbstractAdapter implements ServiceManagerAwareInterface, EventManagerAwareInterface +class HybridAuth extends AbstractAdapter implements EventManagerAwareInterface { /** * @var Hybrid_Auth */ protected $hybridAuth; - /** - * @var ServiceManager - */ - protected $serviceManager; - /** * @var ModuleOptions */ @@ -179,10 +172,6 @@ public function authenticate(AuthEvent $authEvent) */ public function getHybridAuth() { - if (!$this->hybridAuth) { - $this->hybridAuth = $this->getServiceManager()->get('HybridAuth'); - } - return $this->hybridAuth; } @@ -199,27 +188,6 @@ public function setHybridAuth(Hybrid_Auth $hybridAuth) return $this; } - /** - * Retrieve service manager instance - * - * @return ServiceManager - */ - public function getServiceManager() - { - return $this->serviceManager; - } - - /** - * Set service manager instance - * - * @param ServiceManager $serviceManager - * @return void - */ - public function setServiceManager(ServiceManager $serviceManager) - { - $this->serviceManager = $serviceManager; - } - /** * set options * @@ -240,10 +208,6 @@ public function setOptions(ModuleOptions $options) */ public function getOptions() { - if (!$this->options instanceof ModuleOptions) { - $this->setOptions($this->getServiceManager()->get('ScnSocialAuth-ModuleOptions')); - } - return $this->options; } @@ -263,10 +227,6 @@ public function setZfcUserOptions(UserServiceOptionsInterface $options) */ public function getZfcUserOptions() { - if (!$this->zfcUserOptions instanceof UserServiceOptionsInterface) { - $this->setZfcUserOptions($this->getServiceManager()->get('zfcuser_module_options')); - } - return $this->zfcUserOptions; } @@ -290,10 +250,6 @@ public function setMapper(UserProviderInterface $mapper) */ public function getMapper() { - if (!$this->mapper instanceof UserProviderInterface) { - $this->setMapper($this->getServiceManager()->get('ScnSocialAuth-UserProviderMapper')); - } - return $this->mapper; } @@ -317,10 +273,6 @@ public function setZfcUserMapper(UserMapperInterface $zfcUserMapper) */ public function getZfcUserMapper() { - if (!$this->zfcUserMapper instanceof UserMapperInterface) { - $this->setZfcUserMapper($this->getServiceManager()->get('zfcuser_user_mapper')); - } - return $this->zfcUserMapper; } diff --git a/src/ScnSocialAuth/Controller/Plugin/ScnSocialAuthProvider.php b/src/ScnSocialAuth/Controller/Plugin/ScnSocialAuthProvider.php index 817975e2..713f626b 100644 --- a/src/ScnSocialAuth/Controller/Plugin/ScnSocialAuthProvider.php +++ b/src/ScnSocialAuth/Controller/Plugin/ScnSocialAuthProvider.php @@ -4,17 +4,10 @@ use ScnSocialAuth\Mapper\UserProviderInterface; use Zend\Mvc\Controller\Plugin\AbstractPlugin; -use Zend\ServiceManager\ServiceLocatorAwareInterface; -use Zend\ServiceManager\ServiceLocatorInterface; use ZfcUser\Entity\UserInterface; -class ScnSocialAuthProvider extends AbstractPlugin implements ServiceLocatorAwareInterface +class ScnSocialAuthProvider extends AbstractPlugin { - /** - * @var ServiceLocator - */ - protected $serviceLocator; - /** * @var UserProviderInterface */ @@ -61,30 +54,6 @@ public function setMapper(UserProviderInterface $mapper) */ public function getMapper() { - if (!$this->mapper instanceof UserProviderInterface) { - $this->setMapper($this->getServiceLocator()->get('ScnSocialAuth-UserProviderMapper')); - } - return $this->mapper; } - - /** - * Retrieve service manager instance - * - * @return ServiceLocator - */ - public function getServiceLocator() - { - return $this->serviceLocator->getServiceLocator(); - } - - /** - * Set service locator - * - * @param ServiceLocatorInterface $serviceLocator - */ - public function setServiceLocator(ServiceLocatorInterface $serviceLocator) - { - $this->serviceLocator = $serviceLocator; - } } diff --git a/src/ScnSocialAuth/Controller/UserController.php b/src/ScnSocialAuth/Controller/UserController.php index 4324b588..72dfd7f1 100644 --- a/src/ScnSocialAuth/Controller/UserController.php +++ b/src/ScnSocialAuth/Controller/UserController.php @@ -21,6 +21,11 @@ class UserController extends AbstractActionController */ protected $hybridAuth; + /** + * @var \ZfcUser\Authentication\Adapter\AdapterChain + */ + protected $scnAuthAdapterChain; + /** * @var ModuleOptions */ @@ -158,7 +163,7 @@ public function providerAuthenticateAction() } // For provider authentication, change the auth adapter in the ZfcUser Controller Plugin - $this->zfcUserAuthentication()->setAuthAdapter($this->getServiceLocator()->get('ScnSocialAuth-AuthenticationAdapterChain')); + $this->zfcUserAuthentication()->setAuthAdapter($this->getScnAuthAdapterChain()); // Adding the provider to request metadata to be used by HybridAuth adapter $this->getRequest()->setMetadata('provider', $provider); @@ -206,10 +211,6 @@ public function setMapper(UserProviderInterface $mapper) */ public function getMapper() { - if (!$this->mapper instanceof UserProviderInterface) { - $this->setMapper($this->getServiceLocator()->get('ScnSocialAuth-UserProviderMapper')); - } - return $this->mapper; } @@ -220,10 +221,6 @@ public function getMapper() */ public function getHybridAuth() { - if (!$this->hybridAuth) { - $this->hybridAuth = $this->getServiceLocator()->get('HybridAuth'); - } - return $this->hybridAuth; } @@ -240,6 +237,29 @@ public function setHybridAuth(Hybrid_Auth $hybridAuth) return $this; } + /** + * Set the scnAuthAdapterChain + * + * @param \ZfcUser\Authentication\Adapter\AdapterChain + * @return UserController + */ + public function setScnAuthAdapterChain(\ZfcUser\Authentication\Adapter\AdapterChain $chain) + { + $this->scnAuthAdapterChain = $chain; + + return $this; + } + + /** + * Get the scnAuthAdapterChain + * + * @return \ZfcUser\Authentication\Adapter\AdapterChain + */ + public function getScnAuthAdapterChain() + { + return $this->scnAuthAdapterChain; + } + /** * set options * @@ -260,10 +280,6 @@ public function setOptions(ModuleOptions $options) */ public function getOptions() { - if (!$this->options instanceof ModuleOptions) { - $this->setOptions($this->getServiceLocator()->get('ScnSocialAuth-ModuleOptions')); - } - return $this->options; } diff --git a/src/ScnSocialAuth/Service/HybridAuthAdapterFactory.php b/src/ScnSocialAuth/Service/HybridAuthAdapterFactory.php index b23206ee..9020ea93 100644 --- a/src/ScnSocialAuth/Service/HybridAuthAdapterFactory.php +++ b/src/ScnSocialAuth/Service/HybridAuthAdapterFactory.php @@ -26,11 +26,14 @@ public function createService(ServiceLocatorInterface $services) $mapper = $services->get('ScnSocialAuth-UserProviderMapper'); $zfcUserMapper = $services->get('zfcuser_user_mapper'); + $hybridAuth = $services->get('HybridAuth'); + $adapter = new HybridAuthAdapter(); $adapter->setOptions($moduleOptions); $adapter->setZfcUserOptions($zfcUserOptions); $adapter->setMapper($mapper); $adapter->setZfcUserMapper($zfcUserMapper); + $adapter->setHybridAuth($hybridAuth); return $adapter; } diff --git a/src/ScnSocialAuth/Service/ProviderControllerPluginFactory.php b/src/ScnSocialAuth/Service/ProviderControllerPluginFactory.php new file mode 100644 index 00000000..55517c2e --- /dev/null +++ b/src/ScnSocialAuth/Service/ProviderControllerPluginFactory.php @@ -0,0 +1,30 @@ +getServiceLocator()->get('ScnSocialAuth-UserProviderMapper'); + + $controllerPlugin = new ScnSocialAuthProvider(); + $controllerPlugin->setMapper($mapper); + + return $controllerPlugin; + } +} diff --git a/src/ScnSocialAuth/Service/UserControllerFactory.php b/src/ScnSocialAuth/Service/UserControllerFactory.php index d000dec7..f0294ebd 100644 --- a/src/ScnSocialAuth/Service/UserControllerFactory.php +++ b/src/ScnSocialAuth/Service/UserControllerFactory.php @@ -24,11 +24,13 @@ public function createService(ServiceLocatorInterface $controllerManager) $moduleOptions = $controllerManager->getServiceLocator()->get('ScnSocialAuth-ModuleOptions'); $redirectCallback = $controllerManager->getServiceLocator()->get('zfcuser_redirect_callback'); $zfcuserModuleOptions = $controllerManager->getServiceLocator()->get('zfcuser_module_options'); + $scnAuthAdapterChain = $controllerManager->getServiceLocator()->get('ScnSocialAuth-AuthenticationAdapterChain'); $controller = new UserController($redirectCallback); $controller->setMapper($mapper); $controller->setOptions($moduleOptions); $controller->setZfcModuleOptions($zfcuserModuleOptions); + $controller->setScnAuthAdapterChain($scnAuthAdapterChain); try { $hybridAuth = $controllerManager->getServiceLocator()->get('HybridAuth'); diff --git a/test/ScnSocialAuthTest/Controller/UserControllerTest.php b/test/ScnSocialAuthTest/Controller/UserControllerTest.php index b5a12b6f..f84825a9 100644 --- a/test/ScnSocialAuthTest/Controller/UserControllerTest.php +++ b/test/ScnSocialAuthTest/Controller/UserControllerTest.php @@ -12,15 +12,9 @@ use Zend\Mvc\Controller\PluginManager; use Zend\Mvc\MvcEvent; use Zend\Http\PhpEnvironment\Request; -use Zend\ServiceManager\ServiceManager; class UserControllerTest extends TestCase { - /** - * @var \Zend\ServiceManager\ServiceManager - */ - protected $sm; - /** * @var \Zend\Mvc\Controller\PluginManager */ @@ -43,13 +37,11 @@ class UserControllerTest extends TestCase public function setUp() { - $this->sm = new ServiceManager(); $this->pm = new PluginManager(); $this->event = new MvcEvent(); $this->request = new Request(); $this->controller = new UserController(\Mockery::mock('ScnSocialAuth\Controller\RedirectCallback')); $this->controller->setEvent($this->event); - $this->controller->setServiceLocator($this->sm); $this->controller->setPluginManager($this->pm); $forwardPlugin = \Mockery::mock('Zend\Mvc\Controller\Plugin\Forward[dispatch]');