Skip to content

Commit

Permalink
Merge pull request #239 from SocalNick/deprecated-service-manager-awa…
Browse files Browse the repository at this point in the history
…re-interface

Deprecated service manager aware interface
  • Loading branch information
SocalNick authored Dec 18, 2016
2 parents f96e209 + ad0bd66 commit 4f97a79
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 104 deletions.
4 changes: 2 additions & 2 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
),
),
'controller_plugins' => array(
'invokables' => array(
'scnsocialauthprovider' => 'ScnSocialAuth\Controller\Plugin\ScnSocialAuthProvider',
'factories' => array(
'scnSocialAuthProvider' => 'ScnSocialAuth\Service\ProviderControllerPluginFactory',
),
),
'router' => array(
Expand Down
50 changes: 1 addition & 49 deletions src/ScnSocialAuth/Authentication/Adapter/HybridAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -179,10 +172,6 @@ public function authenticate(AuthEvent $authEvent)
*/
public function getHybridAuth()
{
if (!$this->hybridAuth) {
$this->hybridAuth = $this->getServiceManager()->get('HybridAuth');
}

return $this->hybridAuth;
}

Expand All @@ -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
*
Expand All @@ -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;
}

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

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

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

Expand Down
33 changes: 1 addition & 32 deletions src/ScnSocialAuth/Controller/Plugin/ScnSocialAuthProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}
}
42 changes: 29 additions & 13 deletions src/ScnSocialAuth/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class UserController extends AbstractActionController
*/
protected $hybridAuth;

/**
* @var \ZfcUser\Authentication\Adapter\AdapterChain
*/
protected $scnAuthAdapterChain;

/**
* @var ModuleOptions
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -220,10 +221,6 @@ public function getMapper()
*/
public function getHybridAuth()
{
if (!$this->hybridAuth) {
$this->hybridAuth = $this->getServiceLocator()->get('HybridAuth');
}

return $this->hybridAuth;
}

Expand All @@ -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
*
Expand All @@ -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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/ScnSocialAuth/Service/HybridAuthAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
30 changes: 30 additions & 0 deletions src/ScnSocialAuth/Service/ProviderControllerPluginFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* ScnSocialAuth Module
*
* @category ScnSocialAuth
* @package ScnSocialAuth_Service
*/

namespace ScnSocialAuth\Service;

use ScnSocialAuth\Controller\Plugin\ScnSocialAuthProvider;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* @category ScnSocialAuth
* @package ScnSocialAuth_Service
*/
class ProviderControllerPluginFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceManager)
{
$mapper = $serviceManager->getServiceLocator()->get('ScnSocialAuth-UserProviderMapper');

$controllerPlugin = new ScnSocialAuthProvider();
$controllerPlugin->setMapper($mapper);

return $controllerPlugin;
}
}
2 changes: 2 additions & 0 deletions src/ScnSocialAuth/Service/UserControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 0 additions & 8 deletions test/ScnSocialAuthTest/Controller/UserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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]');
Expand Down

0 comments on commit 4f97a79

Please sign in to comment.