Skip to content

Commit

Permalink
updated composer
Browse files Browse the repository at this point in the history
created more factories
cs fixes
  • Loading branch information
kokspflanze committed Apr 22, 2016
1 parent d8d3021 commit 5a167b1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 33 deletions.
6 changes: 5 additions & 1 deletion composer.json
Expand Up @@ -12,7 +12,11 @@
"homepage": "https://github.com/kokspflanze/SmallUser",
"autoload": {
"psr-0": {
"SmallUser\\": "src/",
"SmallUser\\": "src/"
}
},
"autoload-dev": {
"psr-0": {
"SmallUserTest\\": "tests/"
}
},
Expand Down
11 changes: 8 additions & 3 deletions config/module.config.php
Expand Up @@ -2,6 +2,7 @@

use SmallUser\Controller;
use SmallUser\Entity;
use SmallUser\Form;
use SmallUser\Service;

return [
Expand All @@ -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' => [
Expand Down
24 changes: 24 additions & 0 deletions src/SmallUser/Form/LoginFactory.php
@@ -0,0 +1,24 @@
<?php


namespace SmallUser\Form;


use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class LoginFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $serviceLocator
* @return Login
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$form = new Login();
$form->setInputFilter(new LoginFilter());

return $form;
}

}
27 changes: 1 addition & 26 deletions src/SmallUser/Module.php
Expand Up @@ -2,8 +2,6 @@

namespace SmallUser;

use SmallUser\Model\AuthStorage;

class Module
{
/**
Expand Down Expand Up @@ -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 [];
}

}
1 change: 0 additions & 1 deletion src/SmallUser/Service/User.php
Expand Up @@ -16,7 +16,6 @@ class User
protected $failedLoginMessage = 'Authentication failed. Please try again.';
/** @var FlashMessenger */
protected $flashMessenger;

/** @var AuthenticationService */
protected $authService;
/** @var Login */
Expand Down
33 changes: 33 additions & 0 deletions src/SmallUser/Service/UserAuthFactory.php
@@ -0,0 +1,33 @@
<?php


namespace SmallUser\Service;

use Doctrine\ORM\EntityManager;
use SmallUser\Model\AuthStorage;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class UserAuthFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface $serviceLocator
* @return \Zend\Authentication\AuthenticationService
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
/** @var \DoctrineModule\Authentication\Adapter\ObjectRepository $adapter */
$adapter = $serviceLocator->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);
}

}
5 changes: 3 additions & 2 deletions src/SmallUser/Service/UserFactory.php
Expand Up @@ -4,6 +4,7 @@
namespace SmallUser\Service;


use Zend\Mvc\Controller\PluginManager;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

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

Expand Down

0 comments on commit 5a167b1

Please sign in to comment.