Skip to content

Commit

Permalink
fix(bridge): Make sure the client config option is an array (#189)
Browse files Browse the repository at this point in the history
Refs: #187
  • Loading branch information
damienalexandre committed Jul 12, 2024
1 parent cd13b81 commit 1e9e4f1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,3 @@ parameters:
message: "#^Method JoliCode\\\\Elastically\\\\Index\\:\\:getClient\\(\\) should return JoliCode\\\\Elastically\\\\Client but returns Elastica\\\\Client\\.$#"
count: 1
path: src/Index.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpKernel\\\\Event\\\\ResponseEvent\\:\\:isMasterRequest\\(\\)\\.$#"
count: 1
path: src/Messenger/IndexationRequestSpoolSubscriber.php
4 changes: 3 additions & 1 deletion src/Bridge/Symfony/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ public function getConfigTreeBuilder(): TreeBuilder
->normalizeKeys(false)
->prototype('array')
->children()
->variableNode('client')
->arrayNode('client')
->info('All options for the Elastica client constructor')
->example([
'host' => '%env(ELASTICSEARCH_HOST)%',
'transport' => 'JoliCode\Elastically\Transport\HttpClientTransport',
])
->normalizeKeys(false)
->defaultValue([])
->prototype('variable')->end()
->end()
->scalarNode('mapping_directory')
->info('Path to the mapping directory (in YAML)')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function buildConnection(string $name, array $config, bool $isDefaultCon
if (\array_key_exists('client', $config) && \array_key_exists('transport', $config['client'])) {
$config['client']['transport'] = new Reference($config['client']['transport']);
}
$client->replaceArgument('$config', $config['client']);
$client->replaceArgument('$config', $config['client'] ?? []);
$client->replaceArgument('$resultSetBuilder', new Reference("elastically.{$name}.result_set_builder"));
$client->replaceArgument('$indexNameMapper', new Reference("elastically.{$name}.index_name_mapper"));
$container->setDefinition($id = "elastically.{$name}.client", $client);
Expand Down
3 changes: 2 additions & 1 deletion src/Messenger/IndexationRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ public function __construct(Client $client, MessageBusInterface $bus, DocumentEx
/**
* @throws ExceptionInterface
* @throws UnrecoverableMessageHandlingException
* @throws \Symfony\Component\Messenger\Exception\ExceptionInterface
*/
public function __invoke(IndexationRequestInterface $message)
public function __invoke(IndexationRequestInterface $message): void
{
$messages = [];
if ($message instanceof MultipleIndexationRequest) {
Expand Down
16 changes: 7 additions & 9 deletions src/Messenger/IndexationRequestSpoolSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Messenger\Exception\ExceptionInterface;
use Symfony\Component\Messenger\Exception\TransportException;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;
Expand All @@ -35,15 +36,16 @@ public function __construct(TransportInterface $singleTransport, MessageBusInter
$this->bus = $bus;
}

public function onException()
public function onException(): void
{
$this->wasExceptionThrown = true;
}

/**
* @throws TransportException
* @throws ExceptionInterface
*/
public function onTerminate()
public function onTerminate(): void
{
if ($this->wasExceptionThrown) {
return;
Expand All @@ -66,15 +68,11 @@ public function onTerminate()
}

/**
* @throws TransportException
* @throws TransportException|ExceptionInterface
*/
public function onResponse(ResponseEvent $event)
public function onResponse(ResponseEvent $event): void
{
if (method_exists($event, 'isMainRequest')) {
if (!$event->isMainRequest()) {
return;
}
} elseif (!$event->isMasterRequest()) {
if (!$event->isMainRequest()) {
return;
}

Expand Down

0 comments on commit 1e9e4f1

Please sign in to comment.