Skip to content

Commit

Permalink
[Task][PD-108] Introduce missing interfaces for services (#8)
Browse files Browse the repository at this point in the history
* add missing interfaces for services

* Apply php-cs-fixer changes

* fix: PHP Stan

* fix: PHP Stan

* merge 1.x

* Apply php-cs-fixer changes

* merge 1.x

* fix qodana

* rename variables

* add missing time service interface

---------

Co-authored-by: lukmzig <lukmzig@users.noreply.github.com>
  • Loading branch information
lukmzig and lukmzig authored Jan 30, 2024
1 parent f554df4 commit bd4210b
Show file tree
Hide file tree
Showing 43 changed files with 626 additions and 188 deletions.
4 changes: 2 additions & 2 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ services:
resource: '../src/MessageHandler'
tags: [ { name: messenger.message_handler, bus: messenger.bus.pimcore-generic-data-index } ]

Pimcore\Bundle\GenericDataIndexBundle\Service\TimeService: ~

Pimcore\Bundle\GenericDataIndexBundle\Service\ElementServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\ElementService

Pimcore\Bundle\GenericDataIndexBundle\Service\TimeServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\TimeService

Pimcore\Bundle\GenericDataIndexBundle\Scheduler\GenericDataIndexScheduleProvider: ~
Pimcore\Bundle\GenericDataIndexBundle\Installer:
Expand Down
30 changes: 22 additions & 8 deletions config/services/search/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,37 @@ services:
autoconfigure: true
public: false

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\LanguageService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexUpdateService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\LanguageServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\LanguageService

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexUpdateServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexUpdateService

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueService

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\QueueMessagesDispatcher: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\EnqueueService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\SearchIndexConfigService: ~

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\IndexService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\EnqueueServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\EnqueueService

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\SearchIndexConfigServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\SearchIndexConfigService

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\IndexServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\IndexService

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\ElementTypeAdapter\AdapterServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\ElementTypeAdapter\AdapterService

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\ElementTypeAdapter\ElementTypeAdapterService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\ElementTypeAdapter\AssetTypeAdapter: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\ElementTypeAdapter\DataObjectTypeAdapter: ~

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\IndexHandler\AssetIndexHandler: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\IndexHandler\DataObjectIndexHandler: ~

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionService:
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionService
arguments:
- '@pimcore.generic_data_index.object.search_index_field_definition_locator'

Expand Down
9 changes: 6 additions & 3 deletions config/services/search/open-search.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ services:
autoconfigure: true
public: false

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\OpenSearchService:
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\OpenSearchServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\OpenSearchService
arguments:
$openSearchClient: '@generic-data-index-bundle.opensearch-client'

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\BulkOperationService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\BulkOperationServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\BulkOperationService

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\PathService:
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\PathServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\PathService
arguments:
$openSearchClient: '@generic-data-index-bundle.opensearch-client'

Expand Down
3 changes: 2 additions & 1 deletion config/services/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ services:
autoconfigure: true
public: false

Pimcore\Bundle\GenericDataIndexBundle\Service\Workflow\WorkflowService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\Workflow\WorkflowServiceInterface:
class: Pimcore\Bundle\GenericDataIndexBundle\Service\Workflow\WorkflowService
12 changes: 6 additions & 6 deletions src/Command/Update/IndexUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use Exception;
use Pimcore\Bundle\GenericDataIndexBundle\Exception\CommandAlreadyRunningException;
use Pimcore\Bundle\GenericDataIndexBundle\Exception\IdNotFoundException;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\EnqueueService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexUpdateService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\EnqueueServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexUpdateServiceInterface;
use Pimcore\Console\AbstractCommand;
use Pimcore\Model\DataObject\ClassDefinition;
use Symfony\Component\Console\Command\LockableTrait;
Expand All @@ -39,18 +39,18 @@ final class IndexUpdateCommand extends AbstractCommand

private const OPTION_RECREATE_INDEX = 'recreate_index';

private IndexUpdateService $indexUpdateService;
private IndexUpdateServiceInterface $indexUpdateService;

private EnqueueService $enqueueService;
private EnqueueServiceInterface $enqueueService;

#[Required]
public function setIndexUpdateService(IndexUpdateService $indexUpdateService): void
public function setIndexUpdateService(IndexUpdateServiceInterface $indexUpdateService): void
{
$this->indexUpdateService = $indexUpdateService;
}

#[Required]
public function setEnqueueService(EnqueueService $enqueueService): void
public function setEnqueueService(EnqueueServiceInterface $enqueueService): void
{
$this->enqueueService = $enqueueService;
}
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/PimcoreGenericDataIndexExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Exception;
use InvalidArgumentException;
use Pimcore\Bundle\GenericDataIndexBundle\DependencyInjection\Factory\OpenSearchClientFactory;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\SearchIndexConfigService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\SearchIndexConfigServiceInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
Expand Down Expand Up @@ -67,7 +67,7 @@ public function prepend(ContainerBuilder $container): void

private function registerIndexServiceParams(ContainerBuilder $container, array $indexSettings): void
{
$definition = $container->getDefinition(SearchIndexConfigService::class);
$definition = $container->getDefinition(SearchIndexConfigServiceInterface::class);
$definition->setArgument('$indexPrefix', $indexSettings['client_params']['index_prefix']);
$definition->setArgument('$indexSettings', $indexSettings['index_settings']);
$definition->setArgument('$searchSettings', $indexSettings['search_settings']);
Expand Down
4 changes: 2 additions & 2 deletions src/EventSubscriber/AssetIndexUpdateSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\IndexQueueOperation;
use Pimcore\Bundle\GenericDataIndexBundle\Installer;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\QueueMessagesDispatcher;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueServiceInterface;
use Pimcore\Event\AssetEvents;
use Pimcore\Event\Model\AssetEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand All @@ -27,7 +27,7 @@
final class AssetIndexUpdateSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly IndexQueueService $indexQueueService,
private readonly IndexQueueServiceInterface $indexQueueService,
private readonly Installer $installer,
private readonly QueueMessagesDispatcher $queueMessagesDispatcher,
) {
Expand Down
8 changes: 4 additions & 4 deletions src/EventSubscriber/DataObjectIndexUpdateSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use Exception;
use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\IndexQueueOperation;
use Pimcore\Bundle\GenericDataIndexBundle\Installer;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\EnqueueService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\EnqueueServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\QueueMessagesDispatcher;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\IndexHandler\DataObjectIndexHandler;
use Pimcore\Bundle\GenericDataIndexBundle\Traits\LoggerAwareTrait;
use Pimcore\Event\DataObjectClassDefinitionEvents;
Expand All @@ -37,9 +37,9 @@ final class DataObjectIndexUpdateSubscriber implements EventSubscriberInterface

public function __construct(
private readonly Installer $installer,
private readonly IndexQueueService $indexQueueService,
private readonly IndexQueueServiceInterface $indexQueueService,
private readonly DataObjectIndexHandler $dataObjectMappingHandler,
private readonly EnqueueService $enqueueService,
private readonly EnqueueServiceInterface $enqueueService,
private readonly QueueMessagesDispatcher $queueMessagesDispatcher,
) {
}
Expand Down
8 changes: 4 additions & 4 deletions src/EventSubscriber/TagIndexUpdateSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use Doctrine\DBAL\Exception as DBALException;
use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\IndexQueueOperation;
use Pimcore\Bundle\GenericDataIndexBundle\Installer;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\EnqueueService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\EnqueueServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueue\QueueMessagesDispatcher;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueServiceInterface;
use Pimcore\Event\Model\TagEvent;
use Pimcore\Event\TagEvents;
use Pimcore\Model\Asset;
Expand All @@ -33,8 +33,8 @@ final class TagIndexUpdateSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly Installer $installer,
private readonly EnqueueService $enqueueService,
private readonly IndexQueueService $indexQueueService,
private readonly EnqueueServiceInterface $enqueueService,
private readonly IndexQueueServiceInterface $indexQueueService,
private readonly QueueMessagesDispatcher $queueMessagesDispatcher,
) {
}
Expand Down
4 changes: 2 additions & 2 deletions src/MessageHandler/IndexUpdateQueueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Pimcore\Bundle\GenericDataIndexBundle\Message\IndexUpdateQueueMessage;
use Pimcore\Bundle\GenericDataIndexBundle\Repository\IndexQueueRepository;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueServiceInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Serializer\Exception\ExceptionInterface;

Expand All @@ -26,7 +26,7 @@
final class IndexUpdateQueueHandler
{
public function __construct(
private readonly IndexQueueService $indexQueueService,
private readonly IndexQueueServiceInterface $indexQueueService,
private readonly IndexQueueRepository $indexQueueRepository,
) {
}
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/IndexQueueRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Doctrine\ORM\QueryBuilder;
use Exception;
use Pimcore\Bundle\GenericDataIndexBundle\Entity\IndexQueue;
use Pimcore\Bundle\GenericDataIndexBundle\Service\TimeService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\TimeServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Traits\LoggerAwareTrait;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
Expand All @@ -29,7 +29,7 @@ final class IndexQueueRepository
use LoggerAwareTrait;

public function __construct(
private readonly TimeService $timeService,
private readonly TimeServiceInterface $timeService,
private readonly Connection $connection,
private readonly DenormalizerInterface $denormalizer,
private readonly EntityManagerInterface $entityManager,
Expand Down
4 changes: 2 additions & 2 deletions src/Service/Normalizer/AssetNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\FieldCategory;
use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\FieldCategory\SystemField;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Workflow\WorkflowService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\Workflow\WorkflowServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Traits\ElementNormalizerTrait;
use Pimcore\Model\Asset;
use Pimcore\Model\Element\ElementInterface;
Expand All @@ -31,7 +31,7 @@ final class AssetNormalizer implements NormalizerInterface

public const NOT_LOCALIZED_KEY = 'default';

public function __construct(private readonly WorkflowService $workflowService)
public function __construct(private readonly WorkflowServiceInterface $workflowService)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

namespace Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter;

use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\SearchIndexConfigService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\SearchIndexConfigServiceInterface;
use Pimcore\Model\DataObject\ClassDefinition\Data;

abstract class AbstractAdapter implements AdapterInterface
{
private Data $fieldDefinition;

public function __construct(
protected readonly SearchIndexConfigService $searchIndexConfigService,
protected readonly SearchIndexConfigServiceInterface $searchIndexConfigService,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter;

use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\LanguageService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\LanguageServiceInterface;
use Pimcore\Model\DataObject\ClassDefinition\Data;
use Symfony\Contracts\Service\Attribute\Required;

Expand All @@ -23,9 +23,9 @@
*/
final class LocalizedFieldsAdapter extends AbstractAdapter
{
private FieldDefinitionService $fieldDefinitionService;
private FieldDefinitionServiceInterface $fieldDefinitionService;

private LanguageService $languageService;
private LanguageServiceInterface $languageService;

public function getOpenSearchMapping(): array
{
Expand Down Expand Up @@ -60,13 +60,13 @@ public function getOpenSearchMapping(): array
}

#[Required]
public function setFieldDefinitionService(FieldDefinitionService $fieldDefinitionService): void
public function setFieldDefinitionService(FieldDefinitionServiceInterface $fieldDefinitionService): void
{
$this->fieldDefinitionService = $fieldDefinitionService;
}

#[Required]
public function setLanguageService(LanguageService $languageService): void
public function setLanguageService(LanguageServiceInterface $languageService): void
{
$this->languageService = $languageService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* @internal
*/
final class FieldDefinitionService
final class FieldDefinitionService implements FieldDefinitionServiceInterface
{
public function __construct(
private readonly ServiceLocator $adapterLocator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under following license:
* - Pimcore Commercial License (PCL)
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license PCL
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject;

use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\AdapterInterface;
use Pimcore\Model\DataObject\ClassDefinition;

/**
* @internal
*/
interface FieldDefinitionServiceInterface
{
public function getFieldDefinitionAdapter(ClassDefinition\Data $fieldDefinition): ?AdapterInterface;
}
10 changes: 5 additions & 5 deletions src/Service/SearchIndex/IndexQueue/EnqueueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
use Pimcore\Bundle\GenericDataIndexBundle\Enum\SearchIndex\IndexQueueOperation;
use Pimcore\Bundle\GenericDataIndexBundle\Exception\EnqueueAssetsException;
use Pimcore\Bundle\GenericDataIndexBundle\Repository\IndexQueueRepository;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\ElementTypeAdapter\ElementTypeAdapterService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\TimeService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\ElementTypeAdapter\AdapterServiceInterface;
use Pimcore\Bundle\GenericDataIndexBundle\Service\TimeServiceInterface;
use Pimcore\Model\DataObject\ClassDefinition;
use Pimcore\Model\Element\ElementInterface;
use Pimcore\Model\Element\Tag;

/**
* @internal
*/
final class EnqueueService
final class EnqueueService implements EnqueueServiceInterface
{
public function __construct(
private readonly IndexQueueRepository $indexQueueRepository,
private readonly TimeService $timeService,
private readonly TimeServiceInterface $timeService,
private readonly QueueMessagesDispatcher $queueMessagesDispatcher,
private readonly ElementTypeAdapterService $typeAdapterService,
private readonly AdapterServiceInterface $typeAdapterService,
) {

}
Expand Down
Loading

0 comments on commit bd4210b

Please sign in to comment.