-
Notifications
You must be signed in to change notification settings - Fork 3
/
ConfigurationRepository.php
65 lines (54 loc) · 1.96 KB
/
ConfigurationRepository.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
declare(strict_types=1);
namespace Valantic\ElasticaBridgeBundle\Repository;
use Pimcore\Event\Model\AssetEvent;
use Pimcore\Event\Model\DataObjectEvent;
use Pimcore\Event\Model\DocumentEvent;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
/**
* @internal
*/
class ConfigurationRepository
{
public const SHOULD_HANDLE_AUTO_SAVE = 'auto_save';
public const SHOULD_HANDLE_VERSION_ONLY = 'version_only';
public function __construct(
private readonly ContainerBagInterface $containerBag,
) {}
public function getClientDsn(): string
{
return $this->containerBag->get('valantic_elastica_bridge')['client']['dsn'];
}
public function shouldAddSentryBreadcrumbs(): bool
{
return $this->containerBag->get('valantic_elastica_bridge')['client']['should_add_sentry_breadcrumbs'];
}
public function getIndexingLockTimeout(): int
{
return $this->containerBag->get('valantic_elastica_bridge')['indexing']['lock_timeout'];
}
public function shouldSkipFailingDocuments(): bool
{
return $this->containerBag->get('valantic_elastica_bridge')['indexing']['should_skip_failing_documents'];
}
/**
* @param AssetEvent|DataObjectEvent|DocumentEvent $event
* @param self::SHOULD_* $argument
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*
* @return bool
*/
public function shouldHandleVersion(AssetEvent|DataObjectEvent|DocumentEvent $event, string $argument): bool
{
$eventName = match (true) {
$event instanceof AssetEvent => 'asset',
$event instanceof DataObjectEvent => 'data_object',
$event instanceof DocumentEvent => 'document',
};
return $this->containerBag->get('valantic_elastica_bridge')['events'][$argument][$eventName];
}
}