Skip to content

Commit

Permalink
EZP-29140: deprecations improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou committed Feb 21, 2019
1 parent c862b50 commit 1a1e4e1
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 38 deletions.
34 changes: 33 additions & 1 deletion bundle/Controller/UserRegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,43 @@
*/
namespace EzSystems\RepositoryFormsBundle\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller;
use EzSystems\EzPlatformUserBundle\Controller\UserRegisterController as BaseUserRegisterController;
use Symfony\Component\HttpFoundation\Request;

/**
* @deprecated Deprecated in 2.5 and will be removed in 3.0. Please use \EzSystems\EzPlatformUserBundle\Controller\UserRegisterController instead.
*/
class UserRegisterController extends BaseUserRegisterController
class UserRegisterController extends Controller
{
/** @var \EzSystems\EzPlatformUserBundle\Controller\UserRegisterController */
private $userRegisterController;

/**
* @param \EzSystems\EzPlatformUserBundle\Controller\UserRegisterController $userRegisterController
*/
public function __construct(BaseUserRegisterController $userRegisterController)
{
$this->userRegisterController = $userRegisterController;
}

/**
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return \EzSystems\EzPlatformUser\View\Register\FormView|\Symfony\Component\HttpFoundation\Response|null
*/
public function registerAction(Request $request)
{
return $this->userRegisterController->registerAction($request);
}

/**
* @return \EzSystems\EzPlatformUser\View\Register\ConfirmView
*
* @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType
*/
public function registerConfirmAction()
{
return $this->userRegisterController->registerConfirmAction();
}
}
20 changes: 12 additions & 8 deletions bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ parameters:
ezrepoforms.form_processor.content.class: EzSystems\RepositoryForms\Form\Processor\ContentFormProcessor
ezrepoforms.form_processor.user_create.class: EzSystems\RepositoryForms\Form\Processor\User\UserCreateFormProcessor
ezrepoforms.form_processor.user_update.class: EzSystems\RepositoryForms\Form\Processor\User\UserUpdateFormProcessor
ezrepoforms.form_processor.user_register.class: EzSystems\RepositoryForms\Form\Processor\User\UserRegisterFormProcessor
ezrepoforms.form_processor.user_cancel.class: EzSystems\RepositoryForms\Form\Processor\User\UserCancelFormProcessor

ezrepoforms.controller.content_edit.class: EzSystems\RepositoryFormsBundle\Controller\ContentEditController
Expand Down Expand Up @@ -239,9 +238,6 @@ services:
tags:
- { name: kernel.event_subscriber }

ezrepoforms.form_processor.user_register:
alias: EzSystems\EzPlatformUser\Form\Processor\UserRegisterFormProcessor

ezrepoforms.form_processor.user:
class: "%ezrepoforms.form_processor.user_cancel.class%"
arguments:
Expand Down Expand Up @@ -280,19 +276,27 @@ services:
parent: ezpublish.controller.base

ezrepoforms.controller.user_register:
alias: EzSystems\EzPlatformUserBundle\Controller\UserRegisterController
deprecated: 'Deprecated in 2.5 and will be removed in 3.0. Please use \EzSystems\EzPlatformUserBundle\Controller\UserRegisterController instead.'
autowire: true

ez_content_edit:
alias: ezrepoforms.controller.content_edit

ezrepoforms.user_register.registration_group_loader.configurable:
alias: EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationGroupLoader
deprecated: 'Deprecated in 2.5 and will be removed in 3.0. Please use \EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationGroupLoader instead.'
autowire: true
calls:
- [setParam, ["groupId", "$user_registration.group_id$"]]

ezrepoforms.user_register.registration_content_type_loader.configurable:
alias: EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationContentTypeLoader
deprecated: 'Deprecated in 2.5 and will be removed in 3.0. Please use \EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationContentTypeLoader instead.'
autowire: true
calls:
- [setParam, ["contentTypeIdentifier", "%ezrepoforms.user_content_type_identifier%"]]

ezrepoforms.form_data_mapper.user_register:
alias: EzSystems\EzPlatformUser\Form\DataMapper\UserRegisterMapper
deprecated: 'Deprecated in 2.5 and will be removed in 3.0. Please use EzSystems\EzPlatformUser\Form\DataMapper\UserRegisterMapper instead.'
autowire: true

ezrepoforms.view_templates_listener:
class: "%ezrepoforms.view_templates_listener.class%"
Expand Down
32 changes: 30 additions & 2 deletions lib/Data/Mapper/UserRegisterMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,36 @@

/**
* Form data mapper for user creation.
* @deprecated Deprecated in 1.1 and will be removed in 2.0. Please use EzSystems\EzPlatformUser\Form\DataMapper\UserRegisterMapper instead.
* @deprecated Deprecated in 2.5 and will be removed in 3.0. Please use EzSystems\EzPlatformUser\Form\DataMapper\UserRegisterMapper instead.
*/
class UserRegisterMapper extends BaseUserRegisterMapper
class UserRegisterMapper
{
/** @var \EzSystems\EzPlatformUser\Form\DataMapper\UserRegisterMapper */
private $baseUserRegisterMapper;

/**
* @param \EzSystems\EzPlatformUser\Form\DataMapper\UserRegisterMapper $baseUserRegisterMapper
*/
public function __construct(
BaseUserRegisterMapper $baseUserRegisterMapper
) {
$this->baseUserRegisterMapper = $baseUserRegisterMapper;
}

/**
* @param $name
* @param $value
*/
public function setParam($name, $value)
{
$this->baseUserRegisterMapper->setParam($name, $value);
}

/**
* @return \EzSystems\EzPlatformUser\Form\Data\UserRegisterData
*/
public function mapToFormData()
{
return $this->baseUserRegisterMapper->mapToFormData();
}
}
18 changes: 0 additions & 18 deletions lib/Form/Processor/User/UserRegisterFormProcessor.php

This file was deleted.

37 changes: 36 additions & 1 deletion lib/User/ConfigurableRegistrationContentTypeLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,47 @@
*/
namespace EzSystems\RepositoryForms\User;

use eZ\Publish\API\Repository\Repository;
use EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationContentTypeLoader as BaseConfigurableRegistrationContentTypeLoader;
use EzSystems\EzPlatformUser\ConfigResolver\RegistrationContentTypeLoader;
use EzSystems\RepositoryForms\ConfigResolver\ConfigurableSudoRepositoryLoader;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Loads the registration content type from a configured, injected content type identifier.
* @deprecated Deprecated in 2.5 and will be removed in 3.0. Please use \EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationContentTypeLoader instead.
*/
class ConfigurableRegistrationContentTypeLoader extends BaseConfigurableRegistrationContentTypeLoader
class ConfigurableRegistrationContentTypeLoader extends ConfigurableSudoRepositoryLoader implements RegistrationContentTypeLoader
{
/** @var \EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationContentTypeLoader */
private $configurableRegistrationContentTypeLoader;

/**
* @param \eZ\Publish\API\Repository\Repository $repository
* @param null $params
* @param \EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationContentTypeLoader $configurableRegistrationContentTypeLoader
*/
public function __construct(
Repository $repository,
$params = null,
BaseConfigurableRegistrationContentTypeLoader $configurableRegistrationContentTypeLoader
) {
$this->configurableRegistrationContentTypeLoader = $configurableRegistrationContentTypeLoader;
parent::__construct($repository, $params);
}

protected function configureOptions(OptionsResolver $optionsResolver)
{
$optionsResolver->setRequired('contentTypeIdentifier');
}

/**
* Gets the Content Type used by user registration.
*
* @return \eZ\Publish\API\Repository\Values\ContentType\ContentType
*/
public function loadContentType()
{
return $this->configurableRegistrationContentTypeLoader->loadContentType();
}
}
37 changes: 36 additions & 1 deletion lib/User/ConfigurableRegistrationGroupLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,47 @@
*/
namespace EzSystems\RepositoryForms\User;

use eZ\Publish\API\Repository\Repository;
use EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationGroupLoader as BaseConfigurableRegistrationGroupLoader;
use EzSystems\EzPlatformUser\ConfigResolver\RegistrationGroupLoader;
use EzSystems\RepositoryForms\ConfigResolver\ConfigurableSudoRepositoryLoader;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Loads the registration user group from a configured, injected group ID.
* @deprecated Deprecated in 2.5 and will be removed in 3.0. Please use \EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationGroupLoader instead.
*/
class ConfigurableRegistrationGroupLoader extends BaseConfigurableRegistrationGroupLoader
class ConfigurableRegistrationGroupLoader extends ConfigurableSudoRepositoryLoader implements RegistrationGroupLoader
{
/** @var \EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationGroupLoader */
private $configurableRegistrationGroupLoader;

/**
* @param \eZ\Publish\API\Repository\Repository $repository
* @param null $params
* @param \EzSystems\EzPlatformUser\ConfigResolver\ConfigurableRegistrationGroupLoader $configurableRegistrationGroupLoader
*/
public function __construct(
Repository $repository,
$params = null,
BaseConfigurableRegistrationGroupLoader $configurableRegistrationGroupLoader
) {
$this->configurableRegistrationGroupLoader = $configurableRegistrationGroupLoader;
parent::__construct($repository, $params);
}

protected function configureOptions(OptionsResolver $optionsResolver)
{
$optionsResolver->setRequired('groupId');
}

/**
* Loads a parent group.
*
* @return \eZ\Publish\API\Repository\Values\User\UserGroup
*/
public function loadGroup()
{
return $this->configurableRegistrationGroupLoader->loadGroup();
}
}
59 changes: 56 additions & 3 deletions lib/User/ConfigurableSudoRepositoryLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*/
namespace EzSystems\RepositoryForms\User;

use EzSystems\RepositoryForms\ConfigResolver\ConfigurableSudoRepositoryLoader as BaseConfigurableSudoRepositoryLoader;
use Closure;
use eZ\Publish\API\Repository\Repository;
use OutOfBoundsException;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* A repository data loader that uses the sudo() method.
Expand All @@ -19,8 +22,58 @@
* The repository can be accessed using getRepository().
*
* ** Use with care**.
* @deprecated Deprecated in 1.1 and will be removed in 2.0. Please use \EzSystems\RepositoryForms\ConfigResolver\ConfigurableSudoRepositoryLoader instead.
* @deprecated Deprecated in 2.5 and will be removed in 3.0. Please use \EzSystems\RepositoryForms\ConfigResolver\ConfigurableSudoRepositoryLoader instead.
*/
abstract class ConfigurableSudoRepositoryLoader extends BaseConfigurableSudoRepositoryLoader
abstract class ConfigurableSudoRepositoryLoader
{
/**
* @var Repository
*/
private $repository;

/**
* @var array
*/
private $params = [];

public function __construct(Repository $repository, $params = null)
{
$this->repository = $repository;
$this->params = $params;
}

public function setParam($name, $value)
{
$this->params[$name] = $value;

return $this;
}

protected function getParam($name)
{
if (!isset($this->params[$name])) {
throw new OutOfBoundsException("No such param '$name'");
}

return $this->params[$name];
}

/**
* @return Repository
*/
protected function getRepository()
{
return $this->repository;
}

protected function sudo(Closure $callback)
{
$resolver = new OptionsResolver();
$this->configureOptions($resolver);
$this->params = $resolver->resolve($this->params);

return $this->repository->sudo($callback);
}

abstract protected function configureOptions(OptionsResolver $optionsResolver);
}
4 changes: 2 additions & 2 deletions lib/User/View/UserRegisterConfirmView.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/
namespace EzSystems\RepositoryForms\User\View;

use EzSystems\EzPlatformUser\View\ForgotPassword\UserRegisterConfirmView as BaseRegisterConfirmView;
use EzSystems\EzPlatformUser\View\Register\ConfirmView as BaseRegisterConfirmView;

/**
* @deprecated Deprecated in 1.1 and will be removed in 2.0. Please use EzSystems\EzPlatformUser\View\UserRegisterConfirmView instead.
* @deprecated Deprecated in 2.5 and will be removed in 3.0. Please use EzSystems\EzPlatformUser\View\UserRegisterConfirmView instead.
*/
class UserRegisterConfirmView extends BaseRegisterConfirmView
{
Expand Down
4 changes: 2 additions & 2 deletions lib/User/View/UserRegisterFormView.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/
namespace EzSystems\RepositoryForms\User\View;

use EzSystems\EzPlatformUser\View\ForgotPassword\UserRegisterFormView as BaseUserRegisterFormView;
use EzSystems\EzPlatformUser\View\Register\FormView as BaseUserRegisterFormView;

/**
* @deprecated Deprecated in 1.1 and will be removed in 2.0. Please use EzSystems\EzPlatformUser\View\UserRegisterFormView instead.
* @deprecated Deprecated in 2.5 and will be removed in 3.0. Please use EzSystems\EzPlatformUser\View\UserRegisterFormView instead.
*/
class UserRegisterFormView extends BaseUserRegisterFormView
{
Expand Down

0 comments on commit 1a1e4e1

Please sign in to comment.