From 0bf7b99763f594b97a308163ddbed4cb2c057565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ste=CC=A8pien=CC=81?= Date: Wed, 3 Jan 2024 01:39:28 +0100 Subject: [PATCH] Module code refactorization part 1 --- config/admin/form.yml | 83 +++++++ config/admin/grid.yml | 45 ++++ config/admin/services.yml | 211 +++--------------- config/common.yml | 81 +------ config/front/services.yml | 15 ++ config/routes.yml | 14 +- ...ntroller.php => ImagesliderController.php} | 2 +- .../ImageSliderFormDataHandler.php | 28 +-- src/Form/ImageSliderType.php | 11 +- ...ageSliderConfigurationFormDataProvider.php | 10 +- .../Provider/ImageSliderFormDataProvider.php | 13 +- .../Factory/ImageSliderGridDataFactory.php | 12 +- src/Grid/Query/ImageSliderQueryBuilder.php | 12 +- src/Handler/FileEraser.php | 10 +- src/Handler/FileUploader.php | 8 +- src/Installer/DatabaseYamlParser.php | 5 +- src/Presenter/ImageSlidePresenter.php | 6 +- src/Repository/HookModuleRepository.php | 16 +- src/Repository/ImageSliderRepository.php | 12 +- 19 files changed, 262 insertions(+), 332 deletions(-) create mode 100644 config/admin/form.yml create mode 100644 config/admin/grid.yml rename src/Controller/{IsImagesliderController.php => ImagesliderController.php} (99%) diff --git a/config/admin/form.yml b/config/admin/form.yml new file mode 100644 index 0000000..44b601e --- /dev/null +++ b/config/admin/form.yml @@ -0,0 +1,83 @@ +services: + oksydan.is_imageslider.image_slider.configuration: + class: 'Oksydan\IsImageslider\Form\DataConfiguration\ImageSliderDataConfiguration' + arguments: + - '@prestashop.adapter.legacy.configuration' + - '@prestashop.adapter.shop.context' + - '@prestashop.adapter.multistore_feature' + + oksydan.is_imageslider.image_slider_configuration.form_provider: + class: 'Oksydan\IsImageslider\Form\Provider\ImageSliderConfigurationFormDataProvider' + arguments: + - '@oksydan.is_imageslider.image_slider.configuration' + + oksydan.is_imageslider.image_slider_configuration.form_handler: + class: 'PrestaShop\PrestaShop\Core\Form\Handler' + arguments: + - '@form.factory' + - '@prestashop.core.hook.dispatcher' + - '@oksydan.is_imageslider.image_slider_configuration.form_provider' + - 'Oksydan\IsImageslider\Form\ImageSliderConfigurationType' + - 'ConfigurationForm' + + oksydan.is_imageslider.form.image_slider_type: + class: 'Oksydan\IsImageslider\Form\ImageSliderType' + parent: 'form.type.translatable.aware' + arguments: + - '@=service("prestashop.adapter.multistore_feature").isUsed()' + public: true + tags: + - { name: form.type } + + oksydan.is_imageslider.form.image_slider_configuration_type: + class: 'Oksydan\IsImageslider\Form\ImageSliderConfigurationType' + parent: 'form.type.translatable.aware' + public: true + tags: + - { name: form.type } + + Oksydan\IsImageslider\Type\TranslatableFile: + class: 'Oksydan\IsImageslider\Type\TranslatableFile' + parent: 'form.type.common.translatable' + public: true + tags: + - { name: form.type } + + + oksydan.is_imageslider.provider.image_provider: + class: 'Oksydan\IsImageslider\Provider\ImageProvider' + public: true + arguments: + - '%is_imageslider_images_uri%' + + oksydan.is_imageslider.form.identifiable_object.data_provider.image_slider_form_data_provider: + class: 'Oksydan\IsImageslider\Form\Provider\ImageSliderFormDataProvider' + arguments: + - '@oksydan.is_imageslider.repository.image_slider' + - '@oksydan.is_imageslider.provider.image_provider' + - '@prestashop.core.admin.lang.repository' + - '%is_imageslider_placeholder_img%' + - '@prestashop.adapter.shop.context' + + oksydan.is_imageslider.form.identifiable_object.builder.image_slider_form_builder: + class: 'PrestaShop\PrestaShop\Core\Form\IdentifiableObject\Builder\FormBuilder' + factory: 'prestashop.core.form.builder.form_builder_factory:create' + arguments: + - 'Oksydan\IsImageslider\Form\ImageSliderType' + - '@oksydan.is_imageslider.form.identifiable_object.data_provider.image_slider_form_data_provider' + + oksydan.is_imageslider.form.identifiable_object.data_handler.image_slider_form_data_handler: + class: 'Oksydan\IsImageslider\Form\DataHandler\ImageSliderFormDataHandler' + arguments: + - '@oksydan.is_imageslider.repository.image_slider' + - '@prestashop.core.admin.lang.repository' + - '@doctrine.orm.default_entity_manager' + - '@oksydan.is_imageslider.handler.file_uploader' + - '@oksydan.is_imageslider.handler.file_eraser' + - "@=service('prestashop.adapter.legacy.context').getLanguages()" + + oksydan.is_imageslider.form.identifiable_object.handler.image_slider_form_handler: + class: 'PrestaShop\PrestaShop\Core\Form\IdentifiableObject\Handler\FormHandler' + factory: 'prestashop.core.form.identifiable_object.handler.form_handler_factory:create' + arguments: + - '@oksydan.is_imageslider.form.identifiable_object.data_handler.image_slider_form_data_handler' diff --git a/config/admin/grid.yml b/config/admin/grid.yml new file mode 100644 index 0000000..e44b440 --- /dev/null +++ b/config/admin/grid.yml @@ -0,0 +1,45 @@ +services: + + oksydan.is_imageslider.grid.definition.factory.image_sliders: + class: 'Oksydan\IsImageslider\Grid\Definition\Factory\ImageSliderGridDefinitionFactory' + parent: 'prestashop.core.grid.definition.factory.abstract_grid_definition' + public: true + + oksydan.is_imageslider.grid.query.image_slider_query_builder: + class: 'Oksydan\IsImageslider\Grid\Query\ImageSliderQueryBuilder' + parent: 'prestashop.core.grid.abstract_query_builder' + public: true + arguments: + - '@prestashop.adapter.shop.context' + - "@=service('prestashop.adapter.legacy.context').getContext().language.id" + + oksydan.is_imageslider.grid.image_slider_grid_factory: + class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory' + arguments: + - '@oksydan.is_imageslider.grid.definition.factory.image_sliders' + - '@oksydan.is_imageslider.grid.data.factory.image_slider_decorator' + - '@prestashop.core.grid.filter.form_factory' + - '@prestashop.core.hook.dispatcher' + + + oksydan.is_imageslider.grid.data.factory.image_slider_data_factory: + class: '%prestashop.core.grid.data.factory.doctrine_grid_data_factory%' + arguments: + - '@oksydan.is_imageslider.grid.query.image_slider_query_builder' + - '@prestashop.core.hook.dispatcher' + - '@prestashop.core.grid.query.doctrine_query_parser' + - 'is_imageslider' + + + oksydan.is_imageslider.grid.data.factory.image_slider_decorator: + class: 'Oksydan\IsImageslider\Grid\Data\Factory\ImageSliderGridDataFactory' + arguments: + - '@oksydan.is_imageslider.grid.data.factory.image_slider_data_factory' + - '@oksydan.is_imageslider.provider.image_provider' + + oksydan.is_imageslider.grid.position_definition: + class: PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinition + arguments: + - 'image_slider' + - 'id_slide' + - 'position' diff --git a/config/admin/services.yml b/config/admin/services.yml index 570ebd7..8105578 100644 --- a/config/admin/services.yml +++ b/config/admin/services.yml @@ -1,191 +1,36 @@ imports: - { resource: ../common.yml } + - { resource: ./grid.yml } + - { resource: ./form.yml } services: _defaults: public: true + autowire: true + autoconfigure: true + bind: + $module: '@oksydan.is_imageslider.module' + $context: '@oksydan.is_imageslider.context' + $locales: '@=service("prestashop.adapter.legacy.context").getLanguages()' + $availableLocales: "@=service('prestashop.adapter.legacy.context').getAvailableLanguages()" + $saveFormLocaleChoice: "@=service('prestashop.adapter.legacy.configuration').getBoolean('PS_BO_ALLOW_EMPLOYEE_FORM_LANG')" + $defaultFormLanguageId: "@=service('prestashop.adapter.legacy.context').getContext().cookie.employee_form_lang" + $defaultShopLanguageId: "@=service('prestashop.adapter.legacy.configuration').getInt('PS_LANG_DEFAULT')" + $shopContext: '@prestashop.adapter.shop.context' + $multistoreFeature: '@prestashop.adapter.multistore_feature' + $langRepository: '@prestashop.core.admin.lang.repository' + $placeholderImage: '%is_imageslider_placeholder_img%' + $imageSliderDataFactory: '@oksydan.is_imageslider.grid.data.factory.image_slider_decorator' + $dbPrefix: '%database_prefix%' + $imagesUri: '%is_imageslider_images_uri%' + $imagesDir: '%is_imageslider_images_directory%' + + Oksydan\IsImageslider\: + resource: '../../src/*' + exclude: + - '../../src/{Controller}' + - '../../src/index.php' + - '../../src/*/index.php' + - '../../src/**/index.php' - # Controller - Oksydan\IsImageslider\Controller\IsImagesliderController: - public: true - class: Oksydan\IsImageslider\Controller\IsImagesliderController - arguments: - - '@oksydan.is_imageslider.handler.file_eraser' - - "@=service('prestashop.adapter.legacy.context').getLanguages(false)" - - "@oksydan.is_imageslider.cache.template_cache" - - # installer - oksydan.is_imageslider.image_slider_installer: - class: 'Oksydan\IsImageslider\Installer\ImageSliderInstaller' - arguments: - - '@doctrine.dbal.default_connection' - - '@oksydan.is_imageslider.installer.database_yml_parser' - - "@=service('prestashop.adapter.legacy.context').getContext()" - - oksydan.is_imageslider.installer.database_yml_parser: - class: 'Oksydan\IsImageslider\Installer\DatabaseYamlParser' - arguments: - - '@oksydan.is_imageslider.installer.database_yml_parser_provider' - - oksydan.is_imageslider.installer.database_yml_parser_provider: - class: 'Oksydan\IsImageslider\Installer\Provider\DatabaseYamlProvider' - arguments: - - '@oksydan.is_imageslider.module' - - oksydan.is_imageslider.installer.action_databse_create_table: - class: 'Oksydan\IsImageslider\Installer\ActionDatabaseCrateTable' - parent: 'oksydan.is_imageslider.installer.abstract_action_databse' - public: true - - oksydan.is_imageslider.installer.action_databse_drop_table: - class: 'Oksydan\IsImageslider\Installer\ActionDatabaseDropTable' - parent: 'oksydan.is_imageslider.installer.abstract_action_databse' - public: true - - oksydan.is_imageslider.installer.abstract_action_databse: - class: 'Oksydan\IsImageslider\Installer\ActionDatabaseAbstract' - abstract: true - arguments: - - '@doctrine.dbal.default_connection' - - '%database_prefix%' - - oksydan.is_imageslider.handler.file_uploader: - class: 'Oksydan\IsImageslider\Handler\FileUploader' - arguments: - $targetDirectory: '%is_imageslider_images_directory%' - - oksydan.is_imageslider.handler.file_eraser: - class: 'Oksydan\IsImageslider\Handler\FileEraser' - arguments: - $targetDirectory: '%is_imageslider_images_directory%' - - - #creation/edition form - oksydan.is_imageslider.form.identifiable_object.data_provider.image_slider_form_data_provider: - class: 'Oksydan\IsImageslider\Form\Provider\ImageSliderFormDataProvider' - arguments: - - '@oksydan.is_imageslider.repository.image_slider' - - '@oksydan.is_imageslider.provider.image_provider' - - '@prestashop.core.admin.lang.repository' - - '%is_imageslider_placeholder_img%' - - '@prestashop.adapter.shop.context' - - oksydan.is_imageslider.form.identifiable_object.builder.image_slider_form_builder: - class: 'PrestaShop\PrestaShop\Core\Form\IdentifiableObject\Builder\FormBuilder' - factory: 'prestashop.core.form.builder.form_builder_factory:create' - arguments: - - 'Oksydan\IsImageslider\Form\ImageSliderType' - - '@oksydan.is_imageslider.form.identifiable_object.data_provider.image_slider_form_data_provider' - - oksydan.is_imageslider.form.identifiable_object.data_handler.image_slider_form_data_handler: - class: 'Oksydan\IsImageslider\Form\DataHandler\ImageSliderFormDataHandler' - arguments: - - '@oksydan.is_imageslider.repository.image_slider' - - '@prestashop.core.admin.lang.repository' - - '@doctrine.orm.default_entity_manager' - - '@oksydan.is_imageslider.handler.file_uploader' - - '@oksydan.is_imageslider.handler.file_eraser' - - "@=service('prestashop.adapter.legacy.context').getLanguages()" - - oksydan.is_imageslider.form.identifiable_object.handler.image_slider_form_handler: - class: 'PrestaShop\PrestaShop\Core\Form\IdentifiableObject\Handler\FormHandler' - factory: 'prestashop.core.form.identifiable_object.handler.form_handler_factory:create' - arguments: - - '@oksydan.is_imageslider.form.identifiable_object.data_handler.image_slider_form_data_handler' - - #grid services - oksydan.is_imageslider.grid.definition.factory.image_sliders: - class: 'Oksydan\IsImageslider\Grid\Definition\Factory\ImageSliderGridDefinitionFactory' - parent: 'prestashop.core.grid.definition.factory.abstract_grid_definition' - public: true - - oksydan.is_imageslider.grid.query.image_slider_query_builder: - class: 'Oksydan\IsImageslider\Grid\Query\ImageSliderQueryBuilder' - parent: 'prestashop.core.grid.abstract_query_builder' - public: true - arguments: - - '@prestashop.adapter.shop.context' - - "@=service('prestashop.adapter.legacy.context').getContext().language.id" - - oksydan.is_imageslider.grid.image_slider_grid_factory: - class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory' - arguments: - - '@oksydan.is_imageslider.grid.definition.factory.image_sliders' - - '@oksydan.is_imageslider.grid.data.factory.image_slider_decorator' - - '@prestashop.core.grid.filter.form_factory' - - '@prestashop.core.hook.dispatcher' - - - oksydan.is_imageslider.grid.data.factory.image_slider_data_factory: - class: '%prestashop.core.grid.data.factory.doctrine_grid_data_factory%' - arguments: - - '@oksydan.is_imageslider.grid.query.image_slider_query_builder' - - '@prestashop.core.hook.dispatcher' - - '@prestashop.core.grid.query.doctrine_query_parser' - - 'is_imageslider' - - - oksydan.is_imageslider.grid.data.factory.image_slider_decorator: - class: 'Oksydan\IsImageslider\Grid\Data\Factory\ImageSliderGridDataFactory' - arguments: - - '@oksydan.is_imageslider.grid.data.factory.image_slider_data_factory' - - '@oksydan.is_imageslider.provider.image_provider' - - # config form - oksydan.is_imageslider.image_slider.configuration: - class: 'Oksydan\IsImageslider\Form\DataConfiguration\ImageSliderDataConfiguration' - arguments: - - '@prestashop.adapter.legacy.configuration' - - '@prestashop.adapter.shop.context' - - '@prestashop.adapter.multistore_feature' - - oksydan.is_imageslider.image_slider_configuration.form_provider: - class: 'Oksydan\IsImageslider\Form\Provider\ImageSliderConfigurationFormDataProvider' - arguments: - - '@oksydan.is_imageslider.image_slider.configuration' - - oksydan.is_imageslider.image_slider_configuration.form_handler: - class: 'PrestaShop\PrestaShop\Core\Form\Handler' - arguments: - - '@form.factory' - - '@prestashop.core.hook.dispatcher' - - '@oksydan.is_imageslider.image_slider_configuration.form_provider' - - 'Oksydan\IsImageslider\Form\ImageSliderConfigurationType' - - 'ConfigurationForm' - - oksydan.is_imageslider.form.image_slider_type: - class: 'Oksydan\IsImageslider\Form\ImageSliderType' - parent: 'form.type.translatable.aware' - arguments: - - '@=service("prestashop.adapter.multistore_feature").isUsed()' - public: true - tags: - - { name: form.type } - - oksydan.is_imageslider.form.image_slider_configuration_type: - class: 'Oksydan\IsImageslider\Form\ImageSliderConfigurationType' - parent: 'form.type.translatable.aware' - public: true - tags: - - { name: form.type } - - Oksydan\IsImageslider\Type\TranslatableFile: - class: 'Oksydan\IsImageslider\Type\TranslatableFile' - parent: 'form.type.common.translatable' - public: true - tags: - - { name: form.type } - - oksydan.is_imageslider.grid.position_definition: - class: PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinition - arguments: - - 'image_slider' - - 'id_slide' - - 'position' - - oksydan.is_imageslider.provider.image_provider: - class: 'Oksydan\IsImageslider\Provider\ImageProvider' - public: true - arguments: - - '%is_imageslider_images_uri%' diff --git a/config/common.yml b/config/common.yml index 6c1acad..6d8c1cf 100644 --- a/config/common.yml +++ b/config/common.yml @@ -5,8 +5,6 @@ parameters: is_imageslider_placeholder_img: '/modules/is_imageslider/views/img/placeholder.jpeg' services: - _defaults: - public: true oksydan.is_imageslider.module: class: Is_imageslider @@ -14,78 +12,7 @@ services: public: false arguments: - 'is_imageslider' - - oksydan.is_imageslider.repository.image_slider: - class: Oksydan\IsImageslider\Repository\ImageSliderRepository - public: true - factory: ['@doctrine.orm.default_entity_manager', getRepository] - arguments: - - Oksydan\IsImageslider\Entity\ImageSlider - - oksydan.is_imageslider.repository.hook_module_repository: - class: Oksydan\IsImageslider\Repository\HookModuleRepository - public: true - arguments: - - '@doctrine.dbal.default_connection' - - '%database_prefix%' - - oksydan.is_imageslider.presenter.image_slide_presenter: - class: Oksydan\IsImageslider\Presenter\ImageSlidePresenter - public: true - arguments: - - '%is_imageslider_images_uri%' - - '%is_imageslider_images_directory%' - - "@=service('prestashop.adapter.legacy.context').getContext()" - - oksydan.is_imageslider.configuration.slider_configuration: - class: Oksydan\IsImageslider\Configuration\SliderConfiguration - public: true - - oksydan.is_imageslider.hook.abstract_hook: - class: Oksydan\IsImageslider\Hook\AbstractHook - public: true - arguments: - - '@oksydan.is_imageslider.module' - - "@=service('prestashop.adapter.legacy.context').getContext()" - - oksydan.is_imageslider.hook.abstract_display_hook: - class: Oksydan\IsImageslider\Hook\AbstractDisplayHook - parent: 'oksydan.is_imageslider.hook.abstract_hook' - public: true - arguments: - - '@oksydan.is_imageslider.configuration.slider_configuration' - - oksydan.is_imageslider.hook.abstract_cacheable_display_hook: - class: Oksydan\IsImageslider\Hook\AbstractCacheableDisplayHook - parent: 'oksydan.is_imageslider.hook.abstract_display_hook' - public: true - arguments: - - '@oksydan.is_imageslider.repository.image_slider' - - '@oksydan.is_imageslider.presenter.image_slide_presenter' - - '@oksydan.is_imageslider.cache.template_cache' - - oksydan.is_imageslider.hook.display_home: - class: Oksydan\IsImageslider\Hook\DisplayHome - parent: 'oksydan.is_imageslider.hook.abstract_cacheable_display_hook' - public: true - - oksydan.is_imageslider.hook.display_header: - class: Oksydan\IsImageslider\Hook\DisplayHeader - parent: 'oksydan.is_imageslider.hook.abstract_cacheable_display_hook' - public: true - - # Modification of the module into a widget - oksydan.is_imageslider.hook.widget_capability: - class: Oksydan\IsImageslider\Hook\WidgetCapability - parent: 'oksydan.is_imageslider.hook.abstract_cacheable_display_hook' - public: true - - oksydan.is_imageslider.cache.template_cache: - class: Oksydan\IsImageslider\Cache\TemplateCache - public: true - arguments: - - '@oksydan.is_imageslider.module' - - "@=service('prestashop.adapter.legacy.context').getContext()" - - '@oksydan.is_imageslider.repository.hook_module_repository' - - '@prestashop.adapter.legacy.configuration' - - '@oksydan.is_imageslider.repository.image_slider' + - + oksydan.is_imageslider.context: + class: Context + factory: [ '\Context', getContext ] diff --git a/config/front/services.yml b/config/front/services.yml index 6e16e43..78393fe 100644 --- a/config/front/services.yml +++ b/config/front/services.yml @@ -1,2 +1,17 @@ imports: - { resource: ../common.yml } + +services: + _defaults: + public: false + autowire: true + autoconfigure: true + bind: + $module: '@oksydan.is_imageslider.module' + $context: '@oksydan.is_imageslider.context' + + Oksydan\IsImageslider\: + resource: '../../src/*' + exclude: + - '../../src/index.php' + - '../../src/*/index.php' diff --git a/config/routes.yml b/config/routes.yml index bf2e718..a83152f 100644 --- a/config/routes.yml +++ b/config/routes.yml @@ -2,41 +2,41 @@ is_imageslider_controller: path: /is_imageslider/configuration methods: [GET] defaults: - _controller: 'Oksydan\IsImageslider\Controller\IsImagesliderController::index' + _controller: 'Oksydan\IsImageslider\Controller\ImagesliderController::index' is_imageslider_controller_configuration_save: path: /is_imageslider/configuration methods: [POST, PATCH] defaults: - _controller: 'Oksydan\IsImageslider\Controller\IsImagesliderController::saveConfiguration' + _controller: 'Oksydan\IsImageslider\Controller\ImagesliderController::saveConfiguration' is_imageslider_controller_create: path: /is_imageslider/imageslide/create methods: [GET, POST] defaults: - _controller: 'Oksydan\IsImageslider\Controller\IsImagesliderController::create' + _controller: 'Oksydan\IsImageslider\Controller\ImagesliderController::create' is_imageslider_controller_edit: path: /is_imageslider/imageslide/{slideId}/edit methods: [GET, POST] defaults: - _controller: 'Oksydan\IsImageslider\Controller\IsImagesliderController::edit' + _controller: 'Oksydan\IsImageslider\Controller\ImagesliderController::edit' is_imageslider_controller_delete: path: /is_imageslider/imageslide/{slideId}/delete methods: [GET, POST] defaults: - _controller: 'Oksydan\IsImageslider\Controller\IsImagesliderController::delete' + _controller: 'Oksydan\IsImageslider\Controller\ImagesliderController::delete' is_imageslider_controller_toggle_status: path: /is_imageslider/imageslide/{slideId}/toggle methods: [POST] defaults: - _controller: 'Oksydan\IsImageslider\Controller\IsImagesliderController::toggleStatus' + _controller: 'Oksydan\IsImageslider\Controller\ImagesliderController::toggleStatus' is_imageslider_controller_update_positions: path: /is_imageslider/imageslide/update_positions methods: [POST] defaults: - _controller: 'Oksydan\IsImageslider\Controller\IsImagesliderController::updatePositionAction' + _controller: 'Oksydan\IsImageslider\Controller\ImagesliderController::updatePositionAction' diff --git a/src/Controller/IsImagesliderController.php b/src/Controller/ImagesliderController.php similarity index 99% rename from src/Controller/IsImagesliderController.php rename to src/Controller/ImagesliderController.php index dd922d4..97d757f 100644 --- a/src/Controller/IsImagesliderController.php +++ b/src/Controller/ImagesliderController.php @@ -17,7 +17,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -class IsImagesliderController extends FrameworkBundleAdminController +class ImagesliderController extends FrameworkBundleAdminController { /** * @var FileEraser diff --git a/src/Form/DataHandler/ImageSliderFormDataHandler.php b/src/Form/DataHandler/ImageSliderFormDataHandler.php index 273c22a..f7ee072 100644 --- a/src/Form/DataHandler/ImageSliderFormDataHandler.php +++ b/src/Form/DataHandler/ImageSliderFormDataHandler.php @@ -5,63 +5,63 @@ namespace Oksydan\IsImageslider\Form\DataHandler; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\EntityRepository; use Oksydan\IsImageslider\Entity\ImageSlider; use Oksydan\IsImageslider\Entity\ImageSliderLang; use Oksydan\IsImageslider\Exceptions\DateRangeNotValidException; use Oksydan\IsImageslider\Handler\FileEraser; use Oksydan\IsImageslider\Handler\FileUploader; +use Oksydan\IsImageslider\Repository\ImageSliderRepository; use PrestaShop\PrestaShop\Core\Form\IdentifiableObject\DataHandler\FormDataHandlerInterface; -use PrestaShopBundle\Entity\Repository\LangRepository; use PrestaShopBundle\Entity\Shop; use Symfony\Component\HttpFoundation\File\UploadedFile; +use PrestaShopBundle\Entity\Repository\LangRepository; class ImageSliderFormDataHandler implements FormDataHandlerInterface { /** - * @var EntityRepository + * @var ImageSliderRepository */ - private $imageSliderRepository; + private ImageSliderRepository $imageSliderRepository; /** * @var LangRepository */ - private $langRepository; + private LangRepository $langRepository; /** * @var EntityManagerInterface */ - private $entityManager; + private EntityManagerInterface $entityManager; /** * @var FileUploader */ - private $fileUploader; + private FileUploader $fileUploader; /** * @var FileEraser */ - private $fileEraser; + private FileEraser $fileEraser; /** * @var array */ - private $languages; + private array $locales; public function __construct( - EntityRepository $imageSliderRepository, + ImageSliderRepository $imageSliderRepository, LangRepository $langRepository, EntityManagerInterface $entityManager, FileUploader $fileUploader, FileEraser $fileEraser, - array $languages + array $locales ) { $this->imageSliderRepository = $imageSliderRepository; $this->langRepository = $langRepository; $this->entityManager = $entityManager; $this->fileUploader = $fileUploader; $this->fileEraser = $fileEraser; - $this->languages = $languages; + $this->locales = $locales; } /** @@ -79,7 +79,7 @@ public function create(array $data): int $imageSlide->setPosition($this->imageSliderRepository->getHighestPosition() + 1); $this->addAssociatedShops($imageSlide, $data['shop_association'] ?? null); - foreach ($this->languages as $language) { + foreach ($this->locales as $language) { $langId = (int) $language['id_lang']; $lang = $this->langRepository->findOneById($langId); $imageSliderLang = new ImageSliderLang(); @@ -122,7 +122,7 @@ public function update($id, array $data): int $imageSlide->setDisplayTo($data['display_to'] ?? new \DateTime()); $this->addAssociatedShops($imageSlide, $data['shop_association'] ?? null); - foreach ($this->languages as $language) { + foreach ($this->locales as $language) { $langId = (int) $language['id_lang']; $imageSliderLang = $imageSlide->getImageSliderLangByLangId($langId); diff --git a/src/Form/ImageSliderType.php b/src/Form/ImageSliderType.php index 7621f53..a0c17ea 100644 --- a/src/Form/ImageSliderType.php +++ b/src/Form/ImageSliderType.php @@ -6,6 +6,7 @@ use Oksydan\IsImageslider\Translations\TranslationDomains; use Oksydan\IsImageslider\Type\TranslatableFile; +use PrestaShop\PrestaShop\Adapter\Feature\MultistoreFeature; use PrestaShopBundle\Form\Admin\Type\FormattedTextareaType; use PrestaShopBundle\Form\Admin\Type\ImagePreviewType; use PrestaShopBundle\Form\Admin\Type\ShopChoiceTreeType; @@ -23,9 +24,9 @@ class ImageSliderType extends TranslatorAwareType { /** - * @var bool + * @var MultistoreFeature */ - private $isMultistoreUsed; + private MultistoreFeature $multistoreFeature; /** * @param TranslatorInterface $translator @@ -35,11 +36,11 @@ class ImageSliderType extends TranslatorAwareType public function __construct( TranslatorInterface $translator, array $locales, - bool $isMultistoreUsed + MultistoreFeature $multistoreFeature ) { parent::__construct($translator, $locales); - $this->isMultistoreUsed = $isMultistoreUsed; + $this->multistoreFeature = $multistoreFeature; } /** @@ -145,7 +146,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'with_seconds' => true, ]); - if ($this->isMultistoreUsed) { + if ($this->multistoreFeature->isUsed()) { $builder->add( 'shop_association', ShopChoiceTreeType::class, diff --git a/src/Form/Provider/ImageSliderConfigurationFormDataProvider.php b/src/Form/Provider/ImageSliderConfigurationFormDataProvider.php index af6c383..d3d45ef 100644 --- a/src/Form/Provider/ImageSliderConfigurationFormDataProvider.php +++ b/src/Form/Provider/ImageSliderConfigurationFormDataProvider.php @@ -4,20 +4,20 @@ namespace Oksydan\IsImageslider\Form\Provider; -use PrestaShop\PrestaShop\Core\Configuration\DataConfigurationInterface; +use Oksydan\IsImageslider\Form\DataConfiguration\ImageSliderDataConfiguration; use PrestaShop\PrestaShop\Core\Form\FormDataProviderInterface; class ImageSliderConfigurationFormDataProvider implements FormDataProviderInterface { /** - * @var DataConfigurationInterface + * @var ImageSliderDataConfiguration */ - private $imageSlideConfigurationDataConfiguration; + private ImageSliderDataConfiguration $imageSlideConfigurationDataConfiguration; /** - * @param DataConfigurationInterface $imageSlideConfigurationDataConfiguration + * @param ImageSliderDataConfiguration $imageSlideConfigurationDataConfiguration */ - public function __construct(DataConfigurationInterface $imageSlideConfigurationDataConfiguration) + public function __construct(ImageSliderDataConfiguration $imageSlideConfigurationDataConfiguration) { $this->imageSlideConfigurationDataConfiguration = $imageSlideConfigurationDataConfiguration; } diff --git a/src/Form/Provider/ImageSliderFormDataProvider.php b/src/Form/Provider/ImageSliderFormDataProvider.php index 80c69e4..458ccb9 100644 --- a/src/Form/Provider/ImageSliderFormDataProvider.php +++ b/src/Form/Provider/ImageSliderFormDataProvider.php @@ -6,6 +6,7 @@ use Doctrine\ORM\EntityRepository; use Oksydan\IsImageslider\Provider\ImageProviderInterface; +use Oksydan\IsImageslider\Repository\ImageSliderRepository; use PrestaShop\PrestaShop\Adapter\Shop\Context; use PrestaShop\PrestaShop\Core\Form\IdentifiableObject\DataProvider\FormDataProviderInterface; use PrestaShopBundle\Entity\Repository\LangRepository; @@ -13,9 +14,9 @@ class ImageSliderFormDataProvider implements FormDataProviderInterface { /** - * @var EntityRepository + * @var ImageSliderRepository */ - private $repository; + private ImageSliderRepository $repository; /** * @var ImageProviderInterface @@ -25,17 +26,17 @@ class ImageSliderFormDataProvider implements FormDataProviderInterface /** * @var LangRepository */ - private $langRepository; + private LangRepository $langRepository; /** * @var string */ - private $placeholderImage; + private string $placeholderImage; /** * @var Context */ - private $shopContext; + private Context $shopContext; /** * ImageSliderFormDataProvider constructor. @@ -43,7 +44,7 @@ class ImageSliderFormDataProvider implements FormDataProviderInterface * @param EntityRepository $repository */ public function __construct( - EntityRepository $repository, + ImageSliderRepository $repository, ImageProviderInterface $imagesliderImageThumbProvider, LangRepository $langRepository, string $placeholderImage, diff --git a/src/Grid/Data/Factory/ImageSliderGridDataFactory.php b/src/Grid/Data/Factory/ImageSliderGridDataFactory.php index d7ffb57..492634e 100644 --- a/src/Grid/Data/Factory/ImageSliderGridDataFactory.php +++ b/src/Grid/Data/Factory/ImageSliderGridDataFactory.php @@ -15,22 +15,22 @@ final class ImageSliderGridDataFactory implements GridDataFactoryInterface /** * @var GridDataFactoryInterface */ - private $doctrineImageSliderDataFactory; + private GridDataFactoryInterface $imageSliderDataFactory; /** * @var ImageProviderInterface */ - private $imagesliderImageThumbProvider; + private ImageProviderInterface $imagesliderImageThumbProvider; /** - * @param GridDataFactoryInterface $doctrineImageSliderDataFactory + * @param GridDataFactoryInterface $imageSliderDataFactory * @param ImageProviderInterface $imagesliderImageThumbProvider */ public function __construct( - GridDataFactoryInterface $doctrineImageSliderDataFactory, + GridDataFactoryInterface $imageSliderDataFactory, ImageProviderInterface $imagesliderImageThumbProvider ) { - $this->doctrineImageSliderDataFactory = $doctrineImageSliderDataFactory; + $this->imageSliderDataFactory = $imageSliderDataFactory; $this->imagesliderImageThumbProvider = $imagesliderImageThumbProvider; } @@ -39,7 +39,7 @@ public function __construct( */ public function getData(SearchCriteriaInterface $searchCriteria) { - $languageData = $this->doctrineImageSliderDataFactory->getData($searchCriteria); + $languageData = $this->imageSliderDataFactory->getData($searchCriteria); $modifiedRecords = $this->applyModification( $languageData->getRecords()->all() diff --git a/src/Grid/Query/ImageSliderQueryBuilder.php b/src/Grid/Query/ImageSliderQueryBuilder.php index 90c7d5f..1cac4d3 100644 --- a/src/Grid/Query/ImageSliderQueryBuilder.php +++ b/src/Grid/Query/ImageSliderQueryBuilder.php @@ -17,7 +17,7 @@ final class ImageSliderQueryBuilder extends AbstractDoctrineQueryBuilder */ private $shopContext; - private $contextLangId; + private $context; /** * ImageSliderQueryBuilder constructor. @@ -26,12 +26,16 @@ final class ImageSliderQueryBuilder extends AbstractDoctrineQueryBuilder * @param $dbPrefix * @param Context $shopContext */ - public function __construct(Connection $connection, $dbPrefix, Context $shopContext, $contextLangId) + public function __construct( + Connection $connection, + $dbPrefix, + Context $shopContext, + \Context $context) { parent::__construct($connection, $dbPrefix); $this->shopContext = $shopContext; - $this->contextLangId = $contextLangId; + $this->context = $context; } /** @@ -45,7 +49,7 @@ public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria): $qb->select('islide.id_slide, islidel.title, islidel.description, islidel.image, islide.active, islide.position') ->join('islide', $this->dbPrefix . 'image_slider_lang', 'islidel', 'islidel.id_slide = islide.id_slide') ->where('islidel.id_lang = :langId') - ->setParameter('langId', (int) $this->contextLangId); + ->setParameter('langId', (int) $this->context->language->id); if (!$this->shopContext->isAllShopContext()) { $qb->join('islide', $this->dbPrefix . 'image_slider_shop', 'islides', 'islides.id_slide = islide.id_slide') diff --git a/src/Handler/FileEraser.php b/src/Handler/FileEraser.php index 6b1c1eb..be60564 100644 --- a/src/Handler/FileEraser.php +++ b/src/Handler/FileEraser.php @@ -6,17 +6,17 @@ class FileEraser { - private $targetDirectory; + private string $imagesDir; - public function __construct($targetDirectory) + public function __construct(string $imagesDir) { - $this->targetDirectory = $targetDirectory; + $this->imagesDir = $imagesDir; } public function remove(string $fileName): bool { $result = true; - $fullFilePath = $this->targetDirectory . $fileName; + $fullFilePath = $this->imagesDir . $fileName; if (file_exists($fullFilePath)) { $result = unlink($fullFilePath); @@ -27,6 +27,6 @@ public function remove(string $fileName): bool public function getTargetDirectory() { - return $this->targetDirectory; + return $this->imagesDir; } } diff --git a/src/Handler/FileUploader.php b/src/Handler/FileUploader.php index bbbd89e..de3297d 100644 --- a/src/Handler/FileUploader.php +++ b/src/Handler/FileUploader.php @@ -9,11 +9,11 @@ class FileUploader { - private $targetDirectory; + private $imagesDir; - public function __construct($targetDirectory) + public function __construct($imagesDir) { - $this->targetDirectory = $targetDirectory; + $this->imagesDir = $imagesDir; } public function upload(UploadedFile $file) @@ -40,6 +40,6 @@ private function createUploadDirectoryIfNotExists() public function getTargetDirectory() { - return $this->targetDirectory; + return $this->imagesDir; } } diff --git a/src/Installer/DatabaseYamlParser.php b/src/Installer/DatabaseYamlParser.php index 92292b8..4c7c391 100644 --- a/src/Installer/DatabaseYamlParser.php +++ b/src/Installer/DatabaseYamlParser.php @@ -4,6 +4,7 @@ namespace Oksydan\IsImageslider\Installer; +use Oksydan\IsImageslider\Installer\Provider\DatabaseYamlProvider; use Symfony\Component\Yaml\Yaml; class DatabaseYamlParser @@ -11,14 +12,14 @@ class DatabaseYamlParser /** * @var DatabaseYamlProvider */ - protected $yamlProvider; + protected DatabaseYamlProvider $yamlProvider; /** * @var array */ private $parsedFileData = []; - public function __construct($yamlProvider) + public function __construct(DatabaseYamlProvider $yamlProvider) { $this->yamlProvider = $yamlProvider; } diff --git a/src/Presenter/ImageSlidePresenter.php b/src/Presenter/ImageSlidePresenter.php index 419a56e..3876fc6 100644 --- a/src/Presenter/ImageSlidePresenter.php +++ b/src/Presenter/ImageSlidePresenter.php @@ -9,17 +9,17 @@ class ImageSlidePresenter /** * @var string */ - private $imagesUri; + private string $imagesUri; /** * @var string */ - private $imagesDir; + private string $imagesDir; /** * @var \Context */ - private $context; + private \Context $context; public function __construct( string $imagesUri, diff --git a/src/Repository/HookModuleRepository.php b/src/Repository/HookModuleRepository.php index ecf38b1..0fff89b 100644 --- a/src/Repository/HookModuleRepository.php +++ b/src/Repository/HookModuleRepository.php @@ -14,27 +14,27 @@ class HookModuleRepository /** * @var Connection */ - private $connection; + private Connection $connection; /** * @var string */ - private $databasePrefix; + private string $dbPrefix; /** * @var string */ - private $table; + private string $table; /** * @param Connection $connection - * @param string $databasePrefix + * @param string $dbPrefix */ - public function __construct(Connection $connection, $databasePrefix) + public function __construct(Connection $connection, $dbPrefix) { $this->connection = $connection; - $this->databasePrefix = $databasePrefix; - $this->table = $this->databasePrefix . 'hook_module'; + $this->dbPrefix = $dbPrefix; + $this->table = $this->dbPrefix . 'hook_module'; } public function getAllHookRegisteredToModule($moduleId) @@ -43,7 +43,7 @@ public function getAllHookRegisteredToModule($moduleId) ->select('h.name') ->from($this->table, 'mh') ->where('mh.id_module = :id_module') - ->leftJoin('mh', $this->databasePrefix . 'hook', 'h', 'h.id_hook = mh.id_hook') + ->leftJoin('mh', $this->dbPrefix . 'hook', 'h', 'h.id_hook = mh.id_hook') ->setParameter('id_module', $moduleId); return $qb->execute()->fetchAll(); diff --git a/src/Repository/ImageSliderRepository.php b/src/Repository/ImageSliderRepository.php index c9000dc..b042889 100644 --- a/src/Repository/ImageSliderRepository.php +++ b/src/Repository/ImageSliderRepository.php @@ -4,11 +4,19 @@ namespace Oksydan\IsImageslider\Repository; -use Doctrine\ORM\EntityRepository; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; use Doctrine\ORM\QueryBuilder; +use Oksydan\IsImageslider\Entity\ImageSlider; -class ImageSliderRepository extends EntityRepository +class ImageSliderRepository extends ServiceEntityRepository { + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, ImageSlider::class); + } + + public function getAllIds(): array { /** @var QueryBuilder $qb */