|
4 | 4 | * @copyright Copyright (C) Ibexa AS. All rights reserved. |
5 | 5 | * @license For full copyright and license information view LICENSE file distributed with this source code. |
6 | 6 | */ |
| 7 | +declare(strict_types=1); |
7 | 8 |
|
8 | 9 | namespace Ibexa\Bundle\Core\ApiLoader; |
9 | 10 |
|
10 | | -use Ibexa\Bundle\Core\ApiLoader\Exception\InvalidRepositoryException; |
11 | | -use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; |
| 11 | +use Ibexa\Contracts\Core\Container\ApiLoader\RepositoryConfigurationProviderInterface; |
12 | 12 |
|
13 | 13 | /** |
14 | | - * The repository configuration provider. |
| 14 | + * @deprecated 5.0.0 The "\Ibexa\Bundle\Core\ApiLoader\RepositoryConfigurationProvider" class is deprecated, will be removed in 6.0.0. |
| 15 | + * Inject {@see \Ibexa\Contracts\Core\Container\ApiLoader\RepositoryConfigurationProviderInterface} from Dependency Injection Container instead. |
15 | 16 | */ |
16 | | -class RepositoryConfigurationProvider |
| 17 | +final readonly class RepositoryConfigurationProvider implements RepositoryConfigurationProviderInterface |
17 | 18 | { |
18 | | - private const REPOSITORY_STORAGE = 'storage'; |
19 | | - private const REPOSITORY_CONNECTION = 'connection'; |
20 | | - private const DEFAULT_CONNECTION_NAME = 'default'; |
21 | | - |
22 | | - /** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */ |
23 | | - private $configResolver; |
24 | | - |
25 | | - /** @var array */ |
26 | | - private $repositories; |
27 | | - |
28 | | - public function __construct(ConfigResolverInterface $configResolver, array $repositories) |
| 19 | + public function __construct(private RepositoryConfigurationProviderInterface $configurationProvider) |
29 | 20 | { |
30 | | - $this->configResolver = $configResolver; |
31 | | - $this->repositories = $repositories; |
32 | 21 | } |
33 | 22 |
|
34 | | - /** |
35 | | - * @return array |
36 | | - * |
37 | | - * @throws \Ibexa\Bundle\Core\ApiLoader\Exception\InvalidRepositoryException |
38 | | - */ |
39 | | - public function getRepositoryConfig() |
| 23 | + public function getRepositoryConfig(): array |
40 | 24 | { |
41 | | - // Takes configured repository as the reference, if it exists. |
42 | | - // If not, the first configured repository is considered instead. |
43 | | - $repositoryAlias = $this->configResolver->getParameter('repository'); |
44 | | - $repositoryAlias = $repositoryAlias ?: $this->getDefaultRepositoryAlias(); |
45 | | - |
46 | | - if (empty($repositoryAlias) || !isset($this->repositories[$repositoryAlias])) { |
47 | | - throw new InvalidRepositoryException( |
48 | | - "Undefined Repository '$repositoryAlias'. Check if the Repository is configured in your project's ibexa.yaml." |
49 | | - ); |
50 | | - } |
51 | | - |
52 | | - return ['alias' => $repositoryAlias] + $this->repositories[$repositoryAlias]; |
| 25 | + return $this->configurationProvider->getRepositoryConfig(); |
53 | 26 | } |
54 | 27 |
|
55 | 28 | public function getCurrentRepositoryAlias(): string |
56 | 29 | { |
57 | | - return $this->getRepositoryConfig()['alias']; |
| 30 | + return $this->configurationProvider->getCurrentRepositoryAlias(); |
58 | 31 | } |
59 | 32 |
|
60 | 33 | public function getDefaultRepositoryAlias(): ?string |
61 | 34 | { |
62 | | - $aliases = array_keys($this->repositories); |
63 | | - |
64 | | - return array_shift($aliases); |
| 35 | + return $this->configurationProvider->getDefaultRepositoryAlias(); |
65 | 36 | } |
66 | 37 |
|
67 | 38 | public function getStorageConnectionName(): string |
68 | 39 | { |
69 | | - $repositoryConfig = $this->getRepositoryConfig(); |
70 | | - |
71 | | - return $repositoryConfig[self::REPOSITORY_STORAGE][self::REPOSITORY_CONNECTION] |
72 | | - ? $repositoryConfig[self::REPOSITORY_STORAGE][self::REPOSITORY_CONNECTION] |
73 | | - : self::DEFAULT_CONNECTION_NAME; |
| 40 | + return $this->configurationProvider->getStorageConnectionName(); |
74 | 41 | } |
75 | 42 | } |
0 commit comments