forked from PedroEscudero/search-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApisearchPluginsBundle.php
104 lines (92 loc) · 3.17 KB
/
ApisearchPluginsBundle.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/*
* This file is part of the Apisearch Server
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <[email protected]>
*/
declare(strict_types=1);
namespace Apisearch\Server;
use Apisearch\Plugin\Callbacks\Domain\Callbacks;
use Apisearch\Plugin\Elastica\ElasticaPluginBundle;
use Apisearch\Plugin\ELK\ELKPluginBundle;
use Apisearch\Plugin\MostRelevantWords\MostRelevantWordsPluginBundle;
use Apisearch\Plugin\Multilanguage\MultilanguagePluginBundle;
use Apisearch\Plugin\NewRelic\NewRelicPluginBundle;
use Apisearch\Plugin\RedisMetadataFields\RedisMetadataFieldsPluginBundle;
use Apisearch\Plugin\RedisStorage\RedisStoragePluginBundle;
use Apisearch\Plugin\RSQueue\RSQueuePluginBundle;
use Apisearch\Plugin\StaticTokens\StaticTokensPluginBundle;
use Apisearch\Server\Domain\Plugin\Plugin;
use Mmoreram\BaseBundle\BaseBundle;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Class ApisearchPluginsBundle.
*/
class ApisearchPluginsBundle extends BaseBundle
{
/**
* Return all bundle dependencies.
*
* Values can be a simple bundle namespace or its instance
*
* @return array
*/
public static function getBundleDependencies(KernelInterface $kernel): array
{
$pluginsAsString = $_ENV['APISEARCH_ENABLED_PLUGINS'] ?? '';
$pluginsAsArray = explode(',', $pluginsAsString);
$pluginsAsArray = array_map('trim', $pluginsAsArray);
$pluginsAsArray = self::resolveAliases($pluginsAsArray);
$pluginsAsArray = array_filter($pluginsAsArray, function (string $pluginNamespace) {
if (
empty($pluginNamespace) ||
!class_exists($pluginNamespace)
) {
return false;
}
$reflectionClass = new \ReflectionClass($pluginNamespace);
return $reflectionClass->implementsInterface(Plugin::class);
});
return $pluginsAsArray;
}
/**
* Resolve aliases.
*
* @param array $bundles
*
* @return array
*/
private static function resolveAliases(array $bundles): array
{
$aliases = [
'callbacks' => Callbacks::class,
'elastica' => ElasticaPluginBundle::class,
'elk' => ELKPluginBundle::class,
'most_relevant_words' => MostRelevantWordsPluginBundle::class,
'multilanguage' => MultilanguagePluginBundle::class,
'newrelic' => NewRelicPluginBundle::class,
'redis_metadata_fields' => RedisMetadataFieldsPluginBundle::class,
'redis_storage' => RedisStoragePluginBundle::class,
'rsqueue' => RSQueuePluginBundle::class,
'static_tokens' => StaticTokensPluginBundle::class,
];
$combined = array_combine(
array_values($bundles),
array_values($bundles)
);
return array_values(
array_replace(
$combined,
array_intersect_key(
$aliases,
$combined
)
)
);
}
}