diff --git a/composer.json b/composer.json index ef2d4e3..72b2089 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,11 @@ "homepage": "https://github.com/kokspflanze/SmallUser", "autoload": { "psr-0": { - "SmallUser\\": "src/", + "SmallUser\\": "src/" + } + }, + "autoload-dev": { + "psr-0": { "SmallUserTest\\": "tests/" } }, diff --git a/config/module.config.php b/config/module.config.php index 9a757a6..3941a30 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -2,6 +2,7 @@ use SmallUser\Controller; use SmallUser\Entity; +use SmallUser\Form; use SmallUser\Service; return [ @@ -25,16 +26,20 @@ ], 'service_manager' => [ 'abstract_factories' => [ - 'Zend\Cache\Service\StorageCacheAbstractServiceFactory', - 'Zend\Log\LoggerAbstractServiceFactory', + \Zend\Cache\Service\StorageCacheAbstractServiceFactory::class, + \Zend\Log\LoggerAbstractServiceFactory::class, ], 'aliases' => [ 'zfcuser_zend_db_adapter' => Zend\Db\Adapter\Adapter::class, 'small_user_service' => Service\User::class, 'zfcuser_user_service' => Service\User::class, + 'small_user_auth_service' => Service\UserAuthFactory::class, + 'small_user_login_form' => Form\LoginFactory::class, ], 'factories' => [ - Service\User::class => Service\UserFactory::class + Service\User::class => Service\UserFactory::class, + Service\UserAuthFactory::class => Service\UserAuthFactory::class, + Form\LoginFactory::class => Form\LoginFactory::class, ], ], 'controllers' => [ diff --git a/src/SmallUser/Form/LoginFactory.php b/src/SmallUser/Form/LoginFactory.php new file mode 100644 index 0000000..4d7dfdc --- /dev/null +++ b/src/SmallUser/Form/LoginFactory.php @@ -0,0 +1,24 @@ +setInputFilter(new LoginFilter()); + + return $form; + } + +} \ No newline at end of file diff --git a/src/SmallUser/Module.php b/src/SmallUser/Module.php index b65710f..30e1319 100644 --- a/src/SmallUser/Module.php +++ b/src/SmallUser/Module.php @@ -2,8 +2,6 @@ namespace SmallUser; -use SmallUser\Model\AuthStorage; - class Module { /** @@ -36,30 +34,7 @@ public function getAutoloaderConfig() */ public function getServiceConfig() { - return [ - 'factories' => [ - 'small_user_auth_service' => function ($sm) { - /** @var $sm \Zend\ServiceManager\ServiceLocatorInterface */ - /** @var \DoctrineModule\Authentication\Adapter\ObjectRepository $adapter */ - $adapter = $sm->get('doctrine.authenticationadapter.odm_default'); - - // In Config there is not EntityManager =(, so we have to add it now =) - $config = $sm->get('Config'); - $config = $config['authenticationadapter']['odm_default']; - $config['objectManager'] = $sm->get('Doctrine\ORM\EntityManager'); - $adapter->setOptions($config); - - $authService = new \Zend\Authentication\AuthenticationService(); - $authService->setStorage(new AuthStorage()); - return $authService->setAdapter($adapter); - }, - 'small_user_login_form' => function () { - $form = new Form\Login(); - $form->setInputFilter(new Form\LoginFilter()); - return $form; - }, - ], - ]; + return []; } } diff --git a/src/SmallUser/Service/User.php b/src/SmallUser/Service/User.php index 709d8a0..c8e7083 100644 --- a/src/SmallUser/Service/User.php +++ b/src/SmallUser/Service/User.php @@ -16,7 +16,6 @@ class User protected $failedLoginMessage = 'Authentication failed. Please try again.'; /** @var FlashMessenger */ protected $flashMessenger; - /** @var AuthenticationService */ protected $authService; /** @var Login */ diff --git a/src/SmallUser/Service/UserAuthFactory.php b/src/SmallUser/Service/UserAuthFactory.php new file mode 100644 index 0000000..b88a56a --- /dev/null +++ b/src/SmallUser/Service/UserAuthFactory.php @@ -0,0 +1,33 @@ +get('doctrine.authenticationadapter.odm_default'); + + // In Config there is not EntityManager =(, so we have to add it now =) + $config = $serviceLocator->get('Config'); + $config = $config['authenticationadapter']['odm_default']; + $config['objectManager'] = $serviceLocator->get(EntityManager::class); + $adapter->setOptions($config); + + $authService = new \Zend\Authentication\AuthenticationService(); + $authService->setStorage(new AuthStorage()); + return $authService->setAdapter($adapter); + } + +} \ No newline at end of file diff --git a/src/SmallUser/Service/UserFactory.php b/src/SmallUser/Service/UserFactory.php index 576c037..9670fb9 100644 --- a/src/SmallUser/Service/UserFactory.php +++ b/src/SmallUser/Service/UserFactory.php @@ -4,6 +4,7 @@ namespace SmallUser\Service; +use Zend\Mvc\Controller\PluginManager; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -19,10 +20,10 @@ public function createService(ServiceLocatorInterface $serviceLocator) { /** @noinspection PhpParamsInspection */ return new $this->className( - $serviceLocator->get('small_user_auth_service'), + $serviceLocator->get(UserAuthFactory::class), $serviceLocator->get('small_user_login_form'), $serviceLocator->get('Config')['small-user'], - $serviceLocator->get('ControllerPluginManager') + $serviceLocator->get(PluginManager::class) ); }