Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Bridge/Elasticsearch/ElasticsearchClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Elasticsearch\Client;
use Elasticsearch\ClientBuilder;

final class ElasticsearchClient
final class ElasticsearchClient implements ElasticsearchClientInterface
{
public function __construct(private readonly string $activityLogElasticHost)
{
Expand Down
10 changes: 10 additions & 0 deletions src/Bridge/Elasticsearch/ElasticsearchClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Locastic\Loggastic\Bridge\Elasticsearch;

use Elasticsearch\Client;

interface ElasticsearchClientInterface
{
public function getClient(): Client;
}
9 changes: 6 additions & 3 deletions src/Bridge/Elasticsearch/ElasticsearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

final class ElasticsearchService
final class ElasticsearchService implements ElasticsearchServiceInterface
{
use ElasticNormalizationContextTrait;

public function __construct(private readonly ElasticsearchClient $elasticsearchClient, private readonly NormalizerInterface $normalizer, private readonly DenormalizerInterface $denormalizer)
{
public function __construct(
private readonly ElasticsearchClientInterface $elasticsearchClient,
private readonly NormalizerInterface $normalizer,
private readonly DenormalizerInterface $denormalizer
) {
}

public function createItem($item, string $index, array $groups = []): void
Expand Down
18 changes: 18 additions & 0 deletions src/Bridge/Elasticsearch/ElasticsearchServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Locastic\Loggastic\Bridge\Elasticsearch;

interface ElasticsearchServiceInterface
{
public function createItem($item, string $index, array $groups = []): void;

public function bulkCreate(array $items, string $index, array $groups = []): void;

public function getItemById($id, string $index, string $denormalizeToClass): mixed;

public function getItemByQuery(string $index, string $denormalizeToClass, array $body = []): mixed;

public function updateItem($id, $item, string $index, array $groups = []): void;

public function getCollection(string $index, string $denormalizeToClass, array $body = [], $limit = 20, $offset = 0): array;
}
9 changes: 6 additions & 3 deletions src/Bridge/Elasticsearch/Index/ElasticsearchIndexFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
namespace Locastic\Loggastic\Bridge\Elasticsearch\Index;

use Locastic\Loggastic\Bridge\Elasticsearch\Context\ElasticsearchContextFactoryInterface;
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchClient;
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchClientInterface;

final class ElasticsearchIndexFactory implements ElasticsearchIndexFactoryInterface
{
public function __construct(private readonly ElasticsearchClient $elasticsearchClient, private readonly ElasticsearchContextFactoryInterface $elasticsearchContextFactory, private readonly ElasticsearchIndexConfigurationInterface $elasticsearchIndexConfiguration)
{
public function __construct(
private readonly ElasticsearchClientInterface $elasticsearchClient,
private readonly ElasticsearchContextFactoryInterface $elasticsearchContextFactory,
private readonly ElasticsearchIndexConfigurationInterface $elasticsearchIndexConfiguration
) {
}

public function recreateActivityLogIndex(string $className): void
Expand Down
4 changes: 2 additions & 2 deletions src/DataProcessor/ActivityLogProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Locastic\Loggastic\Bridge\Elasticsearch\Context\ElasticsearchContextFactoryInterface;
use Locastic\Loggastic\Bridge\Elasticsearch\Context\Traits\ElasticNormalizationContextTrait;
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchService;
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchServiceInterface;
use Locastic\Loggastic\Factory\ActivityLogInputFactoryInterface;
use Locastic\Loggastic\Factory\CurrentDataTrackerInputFactoryInterface;
use Locastic\Loggastic\Message\CreateActivityLogMessageInterface;
Expand All @@ -22,7 +22,7 @@ final class ActivityLogProcessor implements ActivityLogProcessorInterface
public function __construct(
private readonly ElasticsearchContextFactoryInterface $elasticsearchContextFactory,
private readonly NormalizerInterface $objectNormalizer,
private readonly ElasticsearchService $elasticService,
private readonly ElasticsearchServiceInterface $elasticService,
private readonly ActivityLogInputFactoryInterface $activityLogInputFactory,
private readonly CurrentDataTrackerInputFactoryInterface $currentDataTrackerInputFactory,
private readonly LoggableContextFactoryInterface $loggableContextFactory
Expand Down
4 changes: 2 additions & 2 deletions src/DataProvider/ActivityLogProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace Locastic\Loggastic\DataProvider;

use Locastic\Loggastic\Bridge\Elasticsearch\Context\ElasticsearchContextFactoryInterface;
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchService;
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchServiceInterface;
use Locastic\Loggastic\Model\Output\ActivityLog;
use Locastic\Loggastic\Model\Output\CurrentDataTracker;

final class ActivityLogProvider implements ActivityLogProviderInterface
{
public function __construct(
private readonly ElasticsearchService $elasticsearchService,
private readonly ElasticsearchServiceInterface $elasticsearchService,
private readonly ElasticsearchContextFactoryInterface $elasticsearchContextFactory
) { }

Expand Down
8 changes: 5 additions & 3 deletions src/DataProvider/CurrentDataTrackerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
namespace Locastic\Loggastic\DataProvider;

use Locastic\Loggastic\Bridge\Elasticsearch\Context\ElasticsearchContextFactoryInterface;
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchService;
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchServiceInterface;
use Locastic\Loggastic\Model\Output\CurrentDataTracker;
use Locastic\Loggastic\Model\Output\CurrentDataTrackerInterface;

final class CurrentDataTrackerProvider implements CurrentDataTrackerProviderInterface
{
public function __construct(private readonly ElasticsearchService $elasticsearchService, private readonly ElasticsearchContextFactoryInterface $elasticsearchContextFactory)
{
public function __construct(
private readonly ElasticsearchServiceInterface $elasticsearchService,
private readonly ElasticsearchContextFactoryInterface $elasticsearchContextFactory
) {
}

public function getCurrentDataTrackerByClassAndId(string $className, $objectId): ?CurrentDataTrackerInterface
Expand Down
11 changes: 8 additions & 3 deletions src/MessageHandler/PopulateCurrentDataTrackersHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Doctrine\Persistence\ManagerRegistry;
use Locastic\Loggastic\Bridge\Elasticsearch\Context\ElasticsearchContextFactoryInterface;
use Locastic\Loggastic\Bridge\Elasticsearch\Context\Traits\ElasticNormalizationContextTrait;
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchService;
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchServiceInterface;
use Locastic\Loggastic\Factory\CurrentDataTrackerInputFactoryInterface;
use Locastic\Loggastic\Message\PopulateCurrentDataTrackersMessage;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
Expand All @@ -16,8 +16,13 @@ final class PopulateCurrentDataTrackersHandler
{
use ElasticNormalizationContextTrait;

public function __construct(private readonly ManagerRegistry $managerRegistry, private readonly CurrentDataTrackerInputFactoryInterface $currentDataTrackerInputFactory, private readonly NormalizerInterface $objectNormalizer, private readonly ElasticsearchService $elasticService, private readonly ElasticsearchContextFactoryInterface $elasticsearchContextFactory)
{
public function __construct(
private readonly ManagerRegistry $managerRegistry,
private readonly CurrentDataTrackerInputFactoryInterface $currentDataTrackerInputFactory,
private readonly NormalizerInterface $objectNormalizer,
private readonly ElasticsearchServiceInterface $elasticService,
private readonly ElasticsearchContextFactoryInterface $elasticsearchContextFactory
) {
}

public function __invoke(PopulateCurrentDataTrackersMessage $message): void
Expand Down
8 changes: 7 additions & 1 deletion src/Resources/config/elastic.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
services:
Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchClientInterface:
alias: 'Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchClient'

Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchClient:
arguments:
$activityLogElasticHost: '%locastic_activity_log.elasticsearch_host%'

Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchServiceInterface:
alias: 'Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchService'

Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchService:
arguments:
- '@Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchClient'
- '@Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchClientInterface'
- '@serializer.normalizer.object'
- '@serializer'

Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/logger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
arguments:
- '@Locastic\Loggastic\Bridge\Elasticsearch\Context\ElasticsearchContextFactoryInterface'
- '@serializer.normalizer.object'
- '@Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchService'
- '@Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchServiceInterface'
- '@Locastic\Loggastic\Factory\ActivityLogInputFactoryInterface'
- '@Locastic\Loggastic\Factory\CurrentDataTrackerInputFactoryInterface'
- '@Locastic\Loggastic\Metadata\LoggableContext\Factory\LoggableContextFactoryInterface'
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/message_handlers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
- '@Doctrine\Persistence\ManagerRegistry'
- '@Locastic\Loggastic\Factory\CurrentDataTrackerInputFactoryInterface'
- '@serializer.normalizer.object'
- '@Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchService'
- '@Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchServiceInterface'
- '@Locastic\Loggastic\Bridge\Elasticsearch\Context\ElasticsearchContextFactoryInterface'
tags:
- { name: messenger.message_handler }