2022-04-16 18:42:24 +02:00
|
|
|
<?php
|
2025-03-29 10:50:03 +00:00
|
|
|
|
2022-04-16 18:42:24 +02:00
|
|
|
/**
|
2024-03-09 03:19:55 -08:00
|
|
|
* Integrations class.
|
2022-04-16 18:42:24 +02:00
|
|
|
*
|
|
|
|
|
* @package NamelessMC\Integrations
|
|
|
|
|
* @author Partydragen
|
|
|
|
|
* @version 2.0.0-pr13
|
|
|
|
|
* @license MIT
|
|
|
|
|
*/
|
2024-03-09 03:19:55 -08:00
|
|
|
class Integrations extends Instanceable
|
|
|
|
|
{
|
2022-04-17 15:12:57 -07:00
|
|
|
/**
|
2024-03-09 03:19:55 -08:00
|
|
|
* @var IntegrationBase[] The array of integrations
|
2022-04-17 15:12:57 -07:00
|
|
|
*/
|
2022-04-16 18:42:24 +02:00
|
|
|
private array $_integrations = [];
|
|
|
|
|
|
|
|
|
|
/**
|
2022-04-17 15:12:57 -07:00
|
|
|
* Register an integration to the integration list.
|
2022-04-16 18:42:24 +02:00
|
|
|
*
|
|
|
|
|
* @param IntegrationBase $integration Instance of intagration to register.
|
|
|
|
|
*/
|
2024-03-09 03:19:55 -08:00
|
|
|
public function registerIntegration(IntegrationBase $integration): void
|
|
|
|
|
{
|
2022-04-16 18:42:24 +02:00
|
|
|
$this->_integrations[$integration->getName()] = $integration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a integration by name.
|
|
|
|
|
*
|
|
|
|
|
* @param string $name Name of integration to get.
|
|
|
|
|
*
|
|
|
|
|
* @return IntegrationBase|null Instance of integration with same name, null if it doesnt exist.
|
|
|
|
|
*/
|
2024-03-09 03:19:55 -08:00
|
|
|
public function getIntegration(string $name): ?IntegrationBase
|
|
|
|
|
{
|
2022-04-16 18:42:24 +02:00
|
|
|
foreach ($this->_integrations as $integration) {
|
|
|
|
|
if (strcasecmp($name, $integration->getName()) == 0) {
|
|
|
|
|
return $integration;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List all integrations, sorted by their order.
|
|
|
|
|
*
|
|
|
|
|
* @return IntegrationBase[] List of integrations.
|
|
|
|
|
*/
|
2024-03-09 03:19:55 -08:00
|
|
|
public function getAll(): iterable
|
|
|
|
|
{
|
2022-04-16 18:42:24 +02:00
|
|
|
$integrations = $this->_integrations;
|
|
|
|
|
|
2022-04-17 15:12:57 -07:00
|
|
|
uasort($integrations, static function (IntegrationBase $a, IntegrationBase $b) {
|
2022-04-16 18:42:24 +02:00
|
|
|
return $a->getOrder() - $b->getOrder();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return $integrations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List all enabled integrations, sorted by their order.
|
|
|
|
|
*
|
|
|
|
|
* @return IntegrationBase[] List of integrations.
|
|
|
|
|
*/
|
2024-03-09 03:19:55 -08:00
|
|
|
public function getEnabledIntegrations(): iterable
|
|
|
|
|
{
|
2022-04-16 18:42:24 +02:00
|
|
|
$integrations = $this->_integrations;
|
2022-04-17 15:12:57 -07:00
|
|
|
|
2022-04-16 18:42:24 +02:00
|
|
|
$enabled_integrations = [];
|
|
|
|
|
foreach ($integrations as $integration) {
|
|
|
|
|
if ($integration->isEnabled()) {
|
|
|
|
|
$enabled_integrations[] = $integration;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uasort($enabled_integrations, static function ($a, $b) {
|
|
|
|
|
return $a->getOrder() - $b->getOrder();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return $enabled_integrations;
|
|
|
|
|
}
|
2022-04-17 15:12:57 -07:00
|
|
|
}
|