Skip to content
This repository has been archived by the owner on Feb 7, 2021. It is now read-only.

Cleaning up factories #27

Open
wants to merge 1 commit into
base: laminas-3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions src/LmcUser/Authentication/Adapter/AdapterChainServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
namespace LmcUser\Authentication\Adapter;

use Interop\Container\ContainerInterface;
use Interop\Container\Exception\ContainerException;
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use LmcUser\Authentication\Adapter\AdapterChain;
use LmcUser\Options\ModuleOptions;
use Laminas\ServiceManager\Factory\FactoryInterface;
use LmcUser\Authentication\Adapter\Exception\OptionsNotFoundException;
use LmcUser\Options\ModuleOptions;

class AdapterChainServiceFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
/**
* {@inheritDoc}
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$chain = new AdapterChain();
$chain->setEventManager($serviceLocator->get('EventManager'));
$chain->setEventManager($container->get('EventManager'));

$options = $this->getOptions($serviceLocator);
$options = $this->getOptions($container);

//iterate and attach multiple adapters and events if offered
foreach ($options->getAuthAdapters() as $priority => $adapterName) {
$adapter = $serviceLocator->get($adapterName);
$adapter = $container->get($adapterName);

if (is_callable(array($adapter, 'authenticate'))) {
$chain->getEventManager()->attach('authenticate', array($adapter, 'authenticate'), $priority);
Expand All @@ -41,11 +41,6 @@ public function __invoke(ContainerInterface $serviceLocator, $requestedName, arr
*/
protected $options;

public function createService(ServiceLocatorInterface $serviceLocator)
{
$this->__invoke($serviceLocator, null);
}


/**
* set options
Expand Down
20 changes: 6 additions & 14 deletions src/LmcUser/Factory/Authentication/Adapter/DbFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,19 @@

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use LmcUser\Authentication\Adapter\Db;

class DbFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
/**
* {@inheritDoc}
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$db = new Db();
$db->setServiceManager($serviceLocator);
$db->setServiceManager($container);

return $db;
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, null);
}
}
20 changes: 6 additions & 14 deletions src/LmcUser/Factory/Authentication/Storage/DbFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,19 @@

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use LmcUser\Authentication\Storage\Db;

class DbFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
/**
* {@inheritDoc}
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$db = new Db();
$db->setServiceManager($serviceLocator);
$db->setServiceManager($container);

return $db;
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, null);
}
}
22 changes: 7 additions & 15 deletions src/LmcUser/Factory/AuthenticationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,18 @@

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;

class AuthenticationService implements FactoryInterface
{
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
{
return new \Laminas\Authentication\AuthenticationService(
$serviceLocator->get('LmcUser\Authentication\Storage\Db'),
$serviceLocator->get('LmcUser\Authentication\Adapter\AdapterChain')
);
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
* {@inheritDoc}
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return $this->__invoke($serviceLocator, null);
return new \Laminas\Authentication\AuthenticationService(
$container->get('LmcUser\Authentication\Storage\Db'),
$container->get('LmcUser\Authentication\Adapter\AdapterChain')
);
}
}
24 changes: 7 additions & 17 deletions src/LmcUser/Factory/Controller/Plugin/LmcUserAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,23 @@

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use LmcUser\Controller;

class LmcUserAuthentication implements FactoryInterface
{
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
/**
* {@inheritDoc}
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
$authService = $serviceLocator->get('lmcuser_auth_service');
$authAdapter = $serviceLocator->get('LmcUser\Authentication\Adapter\AdapterChain');
$authService = $container->get('lmcuser_auth_service');
$authAdapter = $container->get('LmcUser\Authentication\Adapter\AdapterChain');

$controllerPlugin = new Controller\Plugin\LmcUserAuthentication;
$controllerPlugin->setAuthService($authService);
$controllerPlugin->setAuthAdapter($authAdapter);

return $controllerPlugin;
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceManager
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceManager)
{
$serviceLocator = $serviceManager->getServiceLocator();

return $this->__invoke($serviceLocator, null);
}
}
24 changes: 8 additions & 16 deletions src/LmcUser/Factory/Controller/RedirectCallbackFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,26 @@
use Laminas\Mvc\Application;
use Laminas\Router\RouteInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use LmcUser\Controller\RedirectCallback;
use LmcUser\Options\ModuleOptions;

class RedirectCallbackFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
/**
* {@inheritDoc}
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/* @var RouteInterface $router */
$router = $serviceLocator->get('Router');
$router = $container->get('Router');

/* @var Application $application */
$application = $serviceLocator->get('Application');
$application = $container->get('Application');

/* @var ModuleOptions $options */
$options = $serviceLocator->get('lmcuser_module_options');
$options = $container->get('lmcuser_module_options');

return new RedirectCallback($application, $router, $options);
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, null);
}
}
38 changes: 13 additions & 25 deletions src/LmcUser/Factory/Controller/UserControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,32 @@
namespace LmcUser\Factory\Controller;

use Interop\Container\ContainerInterface;
use Laminas\Mvc\Controller\ControllerManager;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use LmcUser\Controller\RedirectCallback;
use LmcUser\Controller\UserController;

class UserControllerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $serviceManager, $requestedName, array $options = null)
/**
* {@inheritDoc}
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/* @var RedirectCallback $redirectCallback */
$redirectCallback = $serviceManager->get('lmcuser_redirect_callback');
$redirectCallback = $container->get('lmcuser_redirect_callback');

/* @var UserController $controller */
$controller = new UserController($redirectCallback);
$controller->setServiceLocator($serviceManager);
$controller->setServiceLocator($container);

$controller->setChangeEmailForm($serviceManager->get('lmcuser_change_email_form'));
$controller->setOptions($serviceManager->get('lmcuser_module_options'));
$controller->setChangePasswordForm($serviceManager->get('lmcuser_change_password_form'));
$controller->setLoginForm($serviceManager->get('lmcuser_login_form'));
$controller->setRegisterForm($serviceManager->get('lmcuser_register_form'));
$controller->setUserService($serviceManager->get('lmcuser_user_service'));
$controller->setChangeEmailForm($container->get('lmcuser_change_email_form'));
$controller->setOptions($container->get('lmcuser_module_options'));
$controller->setChangePasswordForm($container->get('lmcuser_change_password_form'));
$controller->setLoginForm($container->get('lmcuser_login_form'));
$controller->setRegisterForm($container->get('lmcuser_register_form'));
$controller->setUserService($container->get('lmcuser_user_service'));

return $controller;
}

/**
* Create service
*
* @param ServiceLocatorInterface $controllerManager
* @return mixed
*/
public function createService(ServiceLocatorInterface $controllerManager)
{
/* @var ControllerManager $controllerManager*/
$serviceManager = $controllerManager->getServiceLocator();

return $this->__invoke($serviceManager, null);
}
}
22 changes: 7 additions & 15 deletions src/LmcUser/Factory/Mapper/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use LmcUser\Mapper;
use LmcUser\Options\ModuleOptions;

class User implements FactoryInterface
{
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
/**
* {@inheritDoc}
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
/** @var ModuleOptions $options */
$options = $serviceLocator->get('lmcuser_module_options');
$dbAdapter = $serviceLocator->get('lmcuser_laminas_db_adapter');
$options = $container->get('lmcuser_module_options');
$dbAdapter = $container->get('lmcuser_laminas_db_adapter');

$entityClass = $options->getUserEntityClass();
$tableName = $options->getTableName();
Expand All @@ -27,15 +30,4 @@ public function __invoke(ContainerInterface $serviceLocator, $requestedName, arr

return $mapper;
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return $this->__invoke($serviceLocator, null);
}
}
20 changes: 6 additions & 14 deletions src/LmcUser/Factory/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,18 @@

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Laminas\ServiceManager\ServiceLocatorInterface;
use LmcUser\Options;

class ModuleOptions implements FactoryInterface
{
public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
{
$config = $serviceLocator->get('Config');

return new Options\ModuleOptions(isset($config['lmcuser']) ? $config['lmcuser'] : array());
}

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
* {@inheritDoc}
* @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
*/
public function createService(ServiceLocatorInterface $serviceLocator)
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return $this->__invoke($serviceLocator, null);
$config = $container->get('Config');

return new Options\ModuleOptions(isset($config['lmcuser']) ? $config['lmcuser'] : array());
}
}
Loading