Skip to content

Commit

Permalink
Merge pull request #47 from Oksydan/autowire-autoconfigure
Browse files Browse the repository at this point in the history
Module code refactorization
  • Loading branch information
Oksydan authored Jan 5, 2024
2 parents 51a0be7 + 2211eff commit e3ce6f1
Show file tree
Hide file tree
Showing 33 changed files with 600 additions and 480 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: PHP tests

on: [push, pull_request]
on: [pull_request]

jobs:
php-linter:
Expand Down
43 changes: 43 additions & 0 deletions config/admin/form.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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_handler:
class: 'PrestaShop\PrestaShop\Core\Form\Handler'
arguments:
- '@form.factory'
- '@prestashop.core.hook.dispatcher'
- '@Oksydan\IsImageslider\Form\Provider\ImageSliderConfigurationFormDataProvider'
- 'Oksydan\IsImageslider\Form\ImageSliderConfigurationType'
- 'ConfigurationForm'


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.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\IsImageslider\Form\Provider\ImageSliderFormDataProvider'

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\IsImageslider\Form\DataHandler\ImageSliderFormDataHandler'
24 changes: 24 additions & 0 deletions config/admin/grid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
services:

oksydan.is_imageslider.grid.image_slider_grid_factory:
class: 'PrestaShop\PrestaShop\Core\Grid\GridFactory'
arguments:
- '@Oksydan\IsImageslider\Grid\Definition\Factory\ImageSliderGridDefinitionFactory'
- '@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\IsImageslider\Grid\Query\ImageSliderQueryBuilder'
- '@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'
220 changes: 37 additions & 183 deletions config/admin/services.yml
Original file line number Diff line number Diff line change
@@ -1,191 +1,45 @@
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'

Oksydan\IsImageslider\Controller\ImagesliderController:
class: Oksydan\IsImageslider\Controller\ImagesliderController
arguments:
$imagsliderGridFactory: '@oksydan.is_imageslider.grid.image_slider_grid_factory'
$imagesliderConfigurationFormHandler: '@oksydan.is_imageslider.image_slider_configuration.form_handler'
$imagesliderFormBuilder: '@oksydan.is_imageslider.form.identifiable_object.builder.image_slider_form_builder'
$imagesliderFormHandler: '@oksydan.is_imageslider.form.identifiable_object.handler.image_slider_form_handler'
$gridPresenter: '@prestashop.core.grid.presenter.grid_presenter'

# 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%'
81 changes: 4 additions & 77 deletions config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,14 @@ parameters:
is_imageslider_placeholder_img: '/modules/is_imageslider/views/img/placeholder.jpeg'

services:
_defaults:
public: true

oksydan.is_imageslider.module:
class: Is_imageslider
factory: [ 'Module', 'getInstanceByName' ]
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 ]
Loading

0 comments on commit e3ce6f1

Please sign in to comment.