-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginListProvider.php
More file actions
73 lines (59 loc) · 1.81 KB
/
PluginListProvider.php
File metadata and controls
73 lines (59 loc) · 1.81 KB
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
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
declare(strict_types=1);
namespace Piwik\Plugins\OpenApiDocs\Generation;
use Piwik\Piwik;
use Piwik\Plugin\Manager;
class PluginListProvider
{
/**
* @var Manager
*/
private $pluginManager;
public function __construct(?Manager $pluginManager = null)
{
$this->pluginManager = $pluginManager ?? Manager::getInstance();
}
/**
* @return string[]
*/
public function getAllowedPlugins(): array
{
$pluginNames = array_values($this->pluginManager->getActivatedPlugins());
$this->dispatchUpdatePluginListEvent($pluginNames);
$pluginNames = array_values(array_unique($pluginNames));
return array_values(array_filter($pluginNames, function ($pluginName): bool {
return is_string($pluginName) && $this->shouldIncludeEventProvidedPlugin($pluginName);
}));
}
private function shouldIncludeEventProvidedPlugin(string $pluginName): bool
{
if (!$this->pluginManager->isPluginInFilesystem($pluginName)) {
return false;
}
return $this->pluginHasApiFile($pluginName);
}
protected function pluginHasApiFile(string $pluginName): bool
{
return is_file(Manager::getPluginDirectory($pluginName) . '/API.php');
}
/**
* @param string[] $pluginNames
*/
private function dispatchUpdatePluginListEvent(array &$pluginNames): void
{
$this->postEvent('OpenApiDocs.updatePluginList', [&$pluginNames]);
}
/**
* @param array<int, mixed> $params
*/
protected function postEvent(string $eventName, array $params): void
{
Piwik::postEvent($eventName, $params);
}
}