Skip to content

Commit

Permalink
Merge pull request #203 from fox-john/fix/revert-autowire
Browse files Browse the repository at this point in the history
fix: revert autowire service declarations
  • Loading branch information
lartist committed Apr 4, 2023
2 parents f8aba4e + 63e771e commit 47fe51a
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 67 deletions.
18 changes: 18 additions & 0 deletions config/controllers.yml
@@ -0,0 +1,18 @@
services:
_defaults:
public: false

PrestaShop\Module\Psgdpr\Controller\Admin\CustomerController:
class: 'PrestaShop\Module\Psgdpr\Controller\Admin\CustomerController'
public: true
arguments:
- "@prestashop.core.query_bus"
- '@PrestaShop\Module\Psgdpr\Repository\OrderInvoiceRepository'
- "@router"
- '@PrestaShop\Module\Psgdpr\Service\BackResponder\BackResponderFactory'

PrestaShop\Module\Psgdpr\Controller\Admin\DownloadCustomerInvoicesController:
class: 'PrestaShop\Module\Psgdpr\Controller\Admin\DownloadCustomerInvoicesController'
public: true
arguments:
- '@PrestaShop\Module\Psgdpr\Repository\OrderInvoiceRepository'
40 changes: 40 additions & 0 deletions config/repositories.yml
@@ -0,0 +1,40 @@
services:
_defaults:
public: false

PrestaShop\Module\Psgdpr\Repository\LoggerRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\LoggerRepository'
public: true
arguments:
- "@Doctrine\\Persistence\\ManagerRegistry"

PrestaShop\Module\Psgdpr\Repository\CartRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\CartRepository'
arguments:
- "@doctrine.dbal.default_connection"

PrestaShop\Module\Psgdpr\Repository\CartRuleRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\CartRuleRepository'
arguments:
- "@doctrine.dbal.default_connection"

PrestaShop\Module\Psgdpr\Repository\CustomerRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\CustomerRepository'
arguments:
- "@doctrine.dbal.default_connection"

PrestaShop\Module\Psgdpr\Repository\OrderRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\OrderRepository'
arguments:
- "@doctrine.dbal.default_connection"

PrestaShop\Module\Psgdpr\Repository\OrderInvoiceRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\OrderInvoiceRepository'
arguments:
- "@doctrine.dbal.default_connection"

PrestaShop\Module\Psgdpr\Repository\ConsentRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\ConsentRepository'
public: true
arguments:
- "@Doctrine\\Persistence\\ManagerRegistry"
105 changes: 49 additions & 56 deletions config/services.yml
@@ -1,76 +1,62 @@
## Issue with autowiring of services ##
# Automatic service resolution via "resource" parameter currently does not work, so we have to use intermediate way.
# it will work when we PrestaShop 8.1 will be released
# more informations here: https://symfony.com/doc/current/service_container/import.html
imports:
- { resource: ./controllers.yml }
- { resource: ./repositories.yml }

services:
_defaults:
public: false
autowire: true
autoconfigure: true
bind:
$context: '@=service("prestashop.adapter.legacy.context").getContext()'
$commandBus: "@prestashop.core.command_bus"
$queryBus: "@prestashop.core.query_bus"
$translator: '@=service("Psgdpr").getTranslator()'
$defaultGroupProvider: "@prestashop.adapter.group.provider.default_groups_provider"
$hashing: "@hashing"

## SERVICES ##
Psgdpr:
class: "Psgdpr"
factory: ["Module", "getInstanceByName"]
arguments:
- "psgdpr"

PrestaShop\Module\Psgdpr\Service\LoggerService:
class: 'PrestaShop\Module\Psgdpr\Service\LoggerService'
arguments:
- "@PrestaShop\\Module\\Psgdpr\\Repository\\LoggerRepository"
- "@PrestaShop\\Module\\Psgdpr\\Repository\\CustomerRepository"

PrestaShop\Module\Psgdpr\Service\ExportService:
class: 'PrestaShop\Module\Psgdpr\Service\ExportService'
arguments:
- '@=service("prestashop.adapter.legacy.context").getContext()'
- '@=service("Psgdpr").getTranslator()'

PrestaShop\Module\Psgdpr\Service\CustomerService:
class: 'PrestaShop\Module\Psgdpr\Service\CustomerService'

## REPOSITORIES ##
PrestaShop\Module\Psgdpr\Repository\LoggerRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\LoggerRepository'

PrestaShop\Module\Psgdpr\Repository\CartRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\CartRepository'

PrestaShop\Module\Psgdpr\Repository\CartRuleRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\CartRuleRepository'

PrestaShop\Module\Psgdpr\Repository\CustomerRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\CustomerRepository'

PrestaShop\Module\Psgdpr\Repository\OrderRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\OrderRepository'

PrestaShop\Module\Psgdpr\Repository\OrderInvoiceRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\OrderInvoiceRepository'

PrestaShop\Module\Psgdpr\Repository\ConsentRepository:
class: 'PrestaShop\Module\Psgdpr\Repository\ConsentRepository'

## CONTROLLERS ##
PrestaShop\Module\Psgdpr\Controller\Admin\CustomerController:
class: 'PrestaShop\Module\Psgdpr\Controller\Admin\CustomerController'
public: true

PrestaShop\Module\Psgdpr\Controller\Admin\DownloadCustomerInvoicesController:
class: 'PrestaShop\Module\Psgdpr\Controller\Admin\DownloadCustomerInvoicesController'
public: true
arguments:
- "@Psgdpr"
- '@=service("prestashop.adapter.legacy.context").getContext()'
- '@PrestaShop\Module\Psgdpr\Repository\CartRepository'
- '@PrestaShop\Module\Psgdpr\Repository\CartRuleRepository'
- '@PrestaShop\Module\Psgdpr\Repository\CustomerRepository'
- "@prestashop.core.command_bus"
- "@prestashop.core.query_bus"
- "@prestashop.adapter.group.provider.default_groups_provider"
- "@hashing"

PrestaShop\Module\Psgdpr\Service\Export\Strategy\ExportToCsv:
class: 'PrestaShop\Module\Psgdpr\Service\Export\Strategy\ExportToCsv'
tags: ["psgdpr.export.customerData"]
arguments:
- '@=service("prestashop.adapter.legacy.context").getContext()'
- '@PrestaShop\Module\Psgdpr\Service\LoggerService'

PrestaShop\Module\Psgdpr\Service\Export\Strategy\ExportToPdf:
class: 'PrestaShop\Module\Psgdpr\Service\Export\Strategy\ExportToPdf'
tags: ["psgdpr.export.customerData"]
arguments:
- '@=service("prestashop.adapter.legacy.context").getContext()'
- '@PrestaShop\Module\Psgdpr\Service\LoggerService'

PrestaShop\Module\Psgdpr\Service\Export\Strategy\ExportToJson:
class: 'PrestaShop\Module\Psgdpr\Service\Export\Strategy\ExportToJson'
tags: ["psgdpr.export.customerData"]
arguments:
- '@=service("prestashop.adapter.legacy.context").getContext()'
- '@PrestaShop\Module\Psgdpr\Service\LoggerService'

PrestaShop\Module\Psgdpr\Service\Export\ExportFactory:
class: 'PrestaShop\Module\Psgdpr\Service\Export\ExportFactory'
Expand All @@ -80,27 +66,34 @@ services:
PrestaShop\Module\Psgdpr\Service\BackResponder\Strategy\BackResponderByCustomerId:
class: 'PrestaShop\Module\Psgdpr\Service\BackResponder\Strategy\BackResponderByCustomerId'
tags: ["psgdpr.export.backResponder"]
arguments:
- '@PrestaShop\Module\Psgdpr\Service\Export\ExportFactory'
- '@PrestaShop\Module\Psgdpr\Repository\CustomerRepository'
- '@PrestaShop\Module\Psgdpr\Service\CustomerService'
- '@PrestaShop\Module\Psgdpr\Service\LoggerService'
- '@PrestaShop\Module\Psgdpr\Service\ExportService'

PrestaShop\Module\Psgdpr\Service\BackResponder\Strategy\BackResponderByEmail:
class: 'PrestaShop\Module\Psgdpr\Service\BackResponder\Strategy\BackResponderByEmail'
tags: ["psgdpr.export.backResponder"]
arguments:
- '@PrestaShop\Module\Psgdpr\Service\Export\ExportFactory'
- '@PrestaShop\Module\Psgdpr\Repository\CustomerRepository'
- '@PrestaShop\Module\Psgdpr\Service\CustomerService'
- '@PrestaShop\Module\Psgdpr\Service\LoggerService'
- '@PrestaShop\Module\Psgdpr\Service\ExportService'

PrestaShop\Module\Psgdpr\Service\BackResponder\Strategy\BackResponderByPhone:
class: 'PrestaShop\Module\Psgdpr\Service\BackResponder\Strategy\BackResponderByPhone'
tags: ["psgdpr.export.backResponder"]
arguments:
- '@PrestaShop\Module\Psgdpr\Service\Export\ExportFactory'
- '@PrestaShop\Module\Psgdpr\Repository\CustomerRepository'
- '@PrestaShop\Module\Psgdpr\Service\CustomerService'
- '@PrestaShop\Module\Psgdpr\Service\LoggerService'
- '@PrestaShop\Module\Psgdpr\Service\ExportService'

PrestaShop\Module\Psgdpr\Service\BackResponder\BackResponderFactory:
class: 'PrestaShop\Module\Psgdpr\Service\BackResponder\BackResponderFactory'
arguments:
- !tagged_iterator psgdpr.export.backResponder

## old binding with this->get() ##
psgdpr.repository.consent:
alias: 'PrestaShop\Module\Psgdpr\Repository\ConsentRepository'
public: true
deprecated: ~

psgdpr.repository.logger:
alias: 'PrestaShop\Module\Psgdpr\Repository\LoggerRepository'
public: true
deprecated: ~
8 changes: 4 additions & 4 deletions psgdpr.php
Expand Up @@ -262,7 +262,7 @@ public function getContent()
$router = $this->get('router');

/** @var LoggerRepository $loggerRepository */
$loggerRepository = $this->get('psgdpr.repository.logger');
$loggerRepository = $this->get('PrestaShop\Module\Psgdpr\Repository\LoggerRepository');

$moduleAdminLink = $this->context->link->getAdminLink('AdminModules', true, [], ['configure' => $this->name]);

Expand Down Expand Up @@ -434,7 +434,7 @@ public function postProcess()
private function submitDataConsent()
{
/** @var ConsentRepository $consentRepository */
$consentRepository = $this->get('psgdpr.repository.consent');
$consentRepository = $this->get('PrestaShop\Module\Psgdpr\Repository\ConsentRepository');

if (Tools::isSubmit('submitDataConsent')) {
/** @var LangRepository $langRepository */
Expand Down Expand Up @@ -489,7 +489,7 @@ private function submitDataConsent()
private function loadRegisteredModules(): array
{
/** @var ConsentRepository $consentRepository */
$consentRepository = $this->get('psgdpr.repository.consent');
$consentRepository = $this->get('PrestaShop\Module\Psgdpr\Repository\ConsentRepository');

$languages = Language::getLanguages(false);
$moduleList = $consentRepository->findAllRegisteredModules();
Expand Down Expand Up @@ -554,7 +554,7 @@ private function addModuleConsent(array $module): void
$langRepository = $this->get('prestashop.core.admin.lang.repository');

/** @var ConsentRepository $consentRepository */
$consentRepository = $this->get('psgdpr.repository.consent');
$consentRepository = $this->get('PrestaShop\Module\Psgdpr\Repository\ConsentRepository');

$languages = $langRepository->findAll();
$shopId = $this->context->shop->id;
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/OrderInvoiceRepository.php
Expand Up @@ -59,7 +59,7 @@ public function findIfInvoicesExistByCustomerId(CustomerId $customerId): bool

$result = $query->execute();

if ($result->fetchOne() === 0) {
if ($result->fetchOne() == 0) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Service/BackResponder/BackResponderContext.php
Expand Up @@ -51,19 +51,19 @@ abstract class BackResponderContext
/**
* @var ExportService
*/
protected $exportCustomerDataService;
protected $exportService;

public function __construct(
ExportFactory $exportFactory,
CustomerRepository $customerRepository,
CustomerService $customerService,
LoggerService $loggerService,
ExportService $exportCustomerDataService
ExportService $exportService
) {
$this->exportFactory = $exportFactory;
$this->customerRepository = $customerRepository;
$this->customerService = $customerService;
$this->loggerService = $loggerService;
$this->exportCustomerDataService = $exportCustomerDataService;
$this->exportService = $exportService;
}
}
Expand Up @@ -45,7 +45,7 @@ public function export(string $data): Response

$exportStrategy = $this->exportFactory->getStrategyByType(ExportToJson::TYPE);

$result = $this->exportCustomerDataService->exportCustomerData($customerId, $exportStrategy);
$result = $this->exportService->exportCustomerData($customerId, $exportStrategy);

return new JsonResponse(json_decode($result));
}
Expand Down
Expand Up @@ -39,7 +39,7 @@ class BackResponderByEmail extends BackResponderContext implements BackResponder
*/
public function export(string $data): Response
{
$result = $this->exportCustomerDataService->getThirdPartyModulesInformations(['email' => $data]);
$result = $this->exportService->getThirdPartyModulesInformations(['email' => $data]);

return new JsonResponse($result);
}
Expand Down
Expand Up @@ -39,7 +39,7 @@ class BackResponderByPhone extends BackResponderContext implements BackResponder
*/
public function export(string $data): Response
{
$result = $this->exportCustomerDataService->getThirdPartyModulesInformations(['phone' => $data]);
$result = $this->exportService->getThirdPartyModulesInformations(['phone' => $data]);

return new JsonResponse($result);
}
Expand Down

0 comments on commit 47fe51a

Please sign in to comment.