From 1a1e4e1c1f52335e7612ea51c237db52e8e3cd54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Thu, 21 Feb 2019 14:58:47 +0100 Subject: [PATCH] EZP-29140: deprecations improvments --- bundle/Controller/UserRegisterController.php | 34 ++++++++++- bundle/Resources/config/services.yml | 20 ++++--- lib/Data/Mapper/UserRegisterMapper.php | 32 +++++++++- .../User/UserRegisterFormProcessor.php | 18 ------ ...figurableRegistrationContentTypeLoader.php | 37 +++++++++++- .../ConfigurableRegistrationGroupLoader.php | 37 +++++++++++- lib/User/ConfigurableSudoRepositoryLoader.php | 59 ++++++++++++++++++- lib/User/View/UserRegisterConfirmView.php | 4 +- lib/User/View/UserRegisterFormView.php | 4 +- 9 files changed, 207 insertions(+), 38 deletions(-) delete mode 100644 lib/Form/Processor/User/UserRegisterFormProcessor.php diff --git a/bundle/Controller/UserRegisterController.php b/bundle/Controller/UserRegisterController.php index 179b54a65..36b20218a 100644 --- a/bundle/Controller/UserRegisterController.php +++ b/bundle/Controller/UserRegisterController.php @@ -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(); + } } diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index 472ede137..f4c62cf96 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -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 @@ -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: @@ -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%" diff --git a/lib/Data/Mapper/UserRegisterMapper.php b/lib/Data/Mapper/UserRegisterMapper.php index 9294b0a84..68c6544d7 100644 --- a/lib/Data/Mapper/UserRegisterMapper.php +++ b/lib/Data/Mapper/UserRegisterMapper.php @@ -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(); + } } diff --git a/lib/Form/Processor/User/UserRegisterFormProcessor.php b/lib/Form/Processor/User/UserRegisterFormProcessor.php deleted file mode 100644 index 8448406a8..000000000 --- a/lib/Form/Processor/User/UserRegisterFormProcessor.php +++ /dev/null @@ -1,18 +0,0 @@ -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(); + } } diff --git a/lib/User/ConfigurableRegistrationGroupLoader.php b/lib/User/ConfigurableRegistrationGroupLoader.php index 323c5a56c..e5ed73f24 100644 --- a/lib/User/ConfigurableRegistrationGroupLoader.php +++ b/lib/User/ConfigurableRegistrationGroupLoader.php @@ -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(); + } } diff --git a/lib/User/ConfigurableSudoRepositoryLoader.php b/lib/User/ConfigurableSudoRepositoryLoader.php index dcddfa0b9..87c94bccd 100644 --- a/lib/User/ConfigurableSudoRepositoryLoader.php +++ b/lib/User/ConfigurableSudoRepositoryLoader.php @@ -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. @@ -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); } diff --git a/lib/User/View/UserRegisterConfirmView.php b/lib/User/View/UserRegisterConfirmView.php index 979d21491..6a1e63567 100644 --- a/lib/User/View/UserRegisterConfirmView.php +++ b/lib/User/View/UserRegisterConfirmView.php @@ -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 { diff --git a/lib/User/View/UserRegisterFormView.php b/lib/User/View/UserRegisterFormView.php index e670bf43c..b1cf172e8 100644 --- a/lib/User/View/UserRegisterFormView.php +++ b/lib/User/View/UserRegisterFormView.php @@ -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 {