Skip to content

Commit

Permalink
Merge pull request #578 from claytondaley/form-upgrades
Browse files Browse the repository at this point in the history
Form Upgrades 1.x
  • Loading branch information
Danielss89 committed Dec 12, 2015
2 parents 6e286ef + 7947c97 commit c7aa895
Show file tree
Hide file tree
Showing 32 changed files with 684 additions and 247 deletions.
140 changes: 14 additions & 126 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use ZfcUser\Controller\RedirectCallback;
use ZfcUser\Controller\UserController;

class Module implements
AutoloaderProviderInterface,
Expand Down Expand Up @@ -36,15 +34,7 @@ public function getControllerPluginConfig()
{
return array(
'factories' => array(
'zfcUserAuthentication' => function ($sm) {
$serviceLocator = $sm->getServiceLocator();
$authService = $serviceLocator->get('zfcuser_auth_service');
$authAdapter = $serviceLocator->get('ZfcUser\Authentication\Adapter\AdapterChain');
$controllerPlugin = new Controller\Plugin\ZfcUserAuthentication;
$controllerPlugin->setAuthService($authService);
$controllerPlugin->setAuthAdapter($authAdapter);
return $controllerPlugin;
},
'zfcUserAuthentication' => 'ZfcUser\Factory\Controller\Plugin\ZfcUserAuthentication',
),
);
}
Expand All @@ -53,18 +43,7 @@ public function getControllerConfig()
{
return array(
'factories' => array(
'zfcuser' => function($controllerManager) {
/* @var ControllerManager $controllerManager*/
$serviceManager = $controllerManager->getServiceLocator();

/* @var RedirectCallback $redirectCallback */
$redirectCallback = $serviceManager->get('zfcuser_redirect_callback');

/* @var UserController $controller */
$controller = new UserController($redirectCallback);

return $controller;
},
'zfcuser' => 'ZfcUser\Factory\Controller\UserController',
),
);
}
Expand All @@ -73,25 +52,9 @@ public function getViewHelperConfig()
{
return array(
'factories' => array(
'zfcUserDisplayName' => function ($sm) {
$locator = $sm->getServiceLocator();
$viewHelper = new View\Helper\ZfcUserDisplayName;
$viewHelper->setAuthService($locator->get('zfcuser_auth_service'));
return $viewHelper;
},
'zfcUserIdentity' => function ($sm) {
$locator = $sm->getServiceLocator();
$viewHelper = new View\Helper\ZfcUserIdentity;
$viewHelper->setAuthService($locator->get('zfcuser_auth_service'));
return $viewHelper;
},
'zfcUserLoginWidget' => function ($sm) {
$locator = $sm->getServiceLocator();
$viewHelper = new View\Helper\ZfcUserLoginWidget;
$viewHelper->setViewTemplate($locator->get('zfcuser_module_options')->getUserLoginWidgetViewTemplate());
$viewHelper->setLoginForm($locator->get('zfcuser_login_form'));
return $viewHelper;
},
'zfcUserDisplayName' => 'ZfcUser\Factory\View\Helper\ZfcUserDisplayName',
'zfcUserIdentity' => 'ZfcUser\Factory\View\Helper\ZfcUserIdentity',
'zfcUserLoginWidget' => 'ZfcUser\Factory\View\Helper\ZfcUserLoginWidget',
),
);

Expand All @@ -100,102 +63,27 @@ public function getViewHelperConfig()
public function getServiceConfig()
{
return array(
'aliases' => array(
'zfcuser_zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
),
'invokables' => array(
'ZfcUser\Authentication\Adapter\Db' => 'ZfcUser\Authentication\Adapter\Db',
'ZfcUser\Authentication\Storage\Db' => 'ZfcUser\Authentication\Storage\Db',
'ZfcUser\Form\Login' => 'ZfcUser\Form\Login',
'zfcuser_user_service' => 'ZfcUser\Service\User',
'zfcuser_register_form_hydrator' => 'Zend\Stdlib\Hydrator\ClassMethods',
),
'factories' => array(
'zfcuser_redirect_callback' => function ($sm) {
/* @var RouteInterface $router */
$router = $sm->get('Router');

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

/* @var ModuleOptions $options */
$options = $sm->get('zfcuser_module_options');
'zfcuser_redirect_callback' => 'ZfcUser\Factory\Controller\RedirectCallback',
'zfcuser_module_options' => 'ZfcUser\Factory\Options\ModuleOptions',
'ZfcUser\Authentication\Adapter\AdapterChain' => 'ZfcUser\Authentication\Adapter\AdapterChainServiceFactory',

return new RedirectCallback($application, $router, $options);
},
'zfcuser_module_options' => function ($sm) {
$config = $sm->get('Config');
return new Options\ModuleOptions(isset($config['zfcuser']) ? $config['zfcuser'] : array());
},
// We alias this one because it's ZfcUser's instance of
// Zend\Authentication\AuthenticationService. We don't want to
// hog the FQCN service alias for a Zend\* class.
'zfcuser_auth_service' => function ($sm) {
return new \Zend\Authentication\AuthenticationService(
$sm->get('ZfcUser\Authentication\Storage\Db'),
$sm->get('ZfcUser\Authentication\Adapter\AdapterChain')
);
},

'ZfcUser\Authentication\Adapter\AdapterChain' => 'ZfcUser\Authentication\Adapter\AdapterChainServiceFactory',

'zfcuser_login_form' => function ($sm) {
$options = $sm->get('zfcuser_module_options');
$form = new Form\Login(null, $options);
$form->setInputFilter(new Form\LoginFilter($options));
return $form;
},

'zfcuser_register_form' => function ($sm) {
$options = $sm->get('zfcuser_module_options');
$form = new Form\Register(null, $options);
//$form->setCaptchaElement($sm->get('zfcuser_captcha_element'));
$form->setInputFilter(new Form\RegisterFilter(
new Validator\NoRecordExists(array(
'mapper' => $sm->get('zfcuser_user_mapper'),
'key' => 'email'
)),
new Validator\NoRecordExists(array(
'mapper' => $sm->get('zfcuser_user_mapper'),
'key' => 'username'
)),
$options
));
return $form;
},

'zfcuser_change_password_form' => function ($sm) {
$options = $sm->get('zfcuser_module_options');
$form = new Form\ChangePassword(null, $sm->get('zfcuser_module_options'));
$form->setInputFilter(new Form\ChangePasswordFilter($options));
return $form;
},

'zfcuser_change_email_form' => function ($sm) {
$options = $sm->get('zfcuser_module_options');
$form = new Form\ChangeEmail(null, $options);
$form->setInputFilter(new Form\ChangeEmailFilter(
$options,
new Validator\NoRecordExists(array(
'mapper' => $sm->get('zfcuser_user_mapper'),
'key' => 'email'
))
));
return $form;
},

'zfcuser_user_hydrator' => function ($sm) {
$hydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
return $hydrator;
},
'zfcuser_auth_service' => 'ZfcUser\Factory\AuthenticationService',

'zfcuser_user_mapper' => function ($sm) {
$options = $sm->get('zfcuser_module_options');
$mapper = new Mapper\User();
$mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter'));
$entityClass = $options->getUserEntityClass();
$mapper->setEntityPrototype(new $entityClass);
$mapper->setHydrator(new Mapper\UserHydrator());
$mapper->setTableName($options->getTableName());
return $mapper;
},
'zfcuser_user_hydrator' => 'ZfcUser\Factory\UserHydrator',
'zfcuser_user_mapper' => 'ZfcUser\Factory\Mapper\User',
),
);
}
Expand Down
12 changes: 8 additions & 4 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
'zfcuser' => __DIR__ . '/../view',
),
),
'service_manager' => array(
'aliases' => array(
'zfcuser_zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
),
'form_elements' => array(
'factories' => array(
'zfcuser_login_form' => 'ZfcUser\Factory\Form\Login',
'zfcuser_register_form' => 'ZfcUser\Factory\Form\Register',
'zfcuser_change_password_form' => 'ZfcUser\Factory\Form\ChangePassword',
'zfcuser_change_email_form' => 'ZfcUser\Factory\Form\ChangeEmail',
)
),

'router' => array(
'routes' => array(
'zfcuser' => array(
Expand Down
30 changes: 15 additions & 15 deletions src/ZfcUser/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ZfcUser\Controller;

use Zend\Form\Form;
use Zend\Form\FormInterface;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Stdlib\ResponseInterface as Response;
use Zend\Stdlib\Parameters;
Expand All @@ -25,22 +25,22 @@ class UserController extends AbstractActionController
protected $userService;

/**
* @var Form
* @var FormInterface
*/
protected $loginForm;

/**
* @var Form
* @var FormInterface
*/
protected $registerForm;

/**
* @var Form
* @var FormInterface
*/
protected $changePasswordForm;

/**
* @var Form
* @var FormInterface
*/
protected $changeEmailForm;

Expand Down Expand Up @@ -362,25 +362,25 @@ public function setUserService(UserService $userService)
public function getRegisterForm()
{
if (!$this->registerForm) {
$this->setRegisterForm($this->getServiceLocator()->get('zfcuser_register_form'));
$this->setRegisterForm($this->getServiceLocator()->get('FormElementManager')->get('zfcuser_register_form'));
}
return $this->registerForm;
}

public function setRegisterForm(Form $registerForm)
public function setRegisterForm(FormInterface$registerForm)
{
$this->registerForm = $registerForm;
}

public function getLoginForm()
{
if (!$this->loginForm) {
$this->setLoginForm($this->getServiceLocator()->get('zfcuser_login_form'));
$this->setLoginForm($this->getServiceLocator()->get('FormElementManager')->get('zfcuser_login_form'));
}
return $this->loginForm;
}

public function setLoginForm(Form $loginForm)
public function setLoginForm(FormInterface $loginForm)
{
$this->loginForm = $loginForm;
$fm = $this->flashMessenger()->setNamespace('zfcuser-login-form')->getMessages();
Expand All @@ -395,12 +395,12 @@ public function setLoginForm(Form $loginForm)
public function getChangePasswordForm()
{
if (!$this->changePasswordForm) {
$this->setChangePasswordForm($this->getServiceLocator()->get('zfcuser_change_password_form'));
$this->setChangePasswordForm($this->getServiceLocator()->get('FormElementManager')->get('zfcuser_change_password_form'));
}
return $this->changePasswordForm;
}

public function setChangePasswordForm(Form $changePasswordForm)
public function setChangePasswordForm(FormInterface $changePasswordForm)
{
$this->changePasswordForm = $changePasswordForm;
return $this;
Expand Down Expand Up @@ -433,21 +433,21 @@ public function getOptions()

/**
* Get changeEmailForm.
*
* @return changeEmailForm.
* @return ChangeEmailForm
*/
public function getChangeEmailForm()
{
if (!$this->changeEmailForm) {
$this->setChangeEmailForm($this->getServiceLocator()->get('zfcuser_change_email_form'));
$this->setChangeEmailForm($this->getServiceLocator()->get('FormElementManager')->get('zfcuser_change_email_form'));
}
return $this->changeEmailForm;
}

/**
* Set changeEmailForm.
*
* @param changeEmailForm the value to set.
* @param $changeEmailForm - the value to set.
* @return $this
*/
public function setChangeEmailForm($changeEmailForm)
{
Expand Down
30 changes: 30 additions & 0 deletions src/ZfcUser/Factory/AuthenticationService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Created by PhpStorm.
* User: Clayton Daley
* Date: 5/6/2015
* Time: 6:40 PM
*/

namespace ZfcUser\Factory;

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

class AuthenticationService implements FactoryInterface
{

/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
return new \Zend\Authentication\AuthenticationService(
$serviceLocator->get('ZfcUser\Authentication\Storage\Db'),
$serviceLocator->get('ZfcUser\Authentication\Adapter\AdapterChain')
);
}
}
34 changes: 34 additions & 0 deletions src/ZfcUser/Factory/Controller/Plugin/ZfcUserAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Created by PhpStorm.
* User: Clayton Daley
* Date: 5/6/2015
* Time: 6:48 PM
*/

namespace ZfcUser\Factory\Controller\Plugin;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfcUser\Controller;

class ZfcUserAuthentication implements FactoryInterface
{

/**
* Create service
*
* @param ServiceLocatorInterface $serviceManager
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceManager)
{
$serviceLocator = $serviceManager->getServiceLocator();
$authService = $serviceLocator->get('zfcuser_auth_service');
$authAdapter = $serviceLocator->get('ZfcUser\Authentication\Adapter\AdapterChain');
$controllerPlugin = new Controller\Plugin\ZfcUserAuthentication;
$controllerPlugin->setAuthService($authService);
$controllerPlugin->setAuthAdapter($authAdapter);
return $controllerPlugin;
}
}
Loading

0 comments on commit c7aa895

Please sign in to comment.