2024-08-20 15:06:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2024-08-22 14:19:42 +02:00
|
|
|
namespace OCA\OrganizationFolders\OrganizationProvider;
|
2024-08-20 15:06:57 +02:00
|
|
|
|
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
|
|
|
|
2024-11-18 18:04:40 +01:00
|
|
|
use OCA\OrganizationFolders\Errors\OrganizationProviderNotFound;
|
2024-08-22 14:19:42 +02:00
|
|
|
use OCA\OrganizationFolders\Events\RegisterOrganizationProviderEvent;
|
2024-08-20 15:06:57 +02:00
|
|
|
|
2024-08-22 14:19:42 +02:00
|
|
|
class OrganizationProviderManager {
|
|
|
|
private array $organizationProviders = [];
|
2024-08-20 15:06:57 +02:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
IEventDispatcher $dispatcher,
|
|
|
|
) {
|
2024-08-22 14:19:42 +02:00
|
|
|
$event = new RegisterOrganizationProviderEvent($this);
|
2024-08-20 15:06:57 +02:00
|
|
|
$dispatcher->dispatchTyped($event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-08-22 14:19:42 +02:00
|
|
|
* @return OrganizationProvider[]
|
2024-08-20 15:06:57 +02:00
|
|
|
*/
|
2024-08-22 14:19:42 +02:00
|
|
|
public function getOrganizationProviders(): array {
|
|
|
|
return $this->organizationProviders;
|
2024-08-20 15:06:57 +02:00
|
|
|
}
|
|
|
|
|
2024-10-13 23:04:20 +02:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasOrganizationProvider($id): bool {
|
|
|
|
return array_key_exists($id, $this->organizationProviders);
|
|
|
|
}
|
|
|
|
|
2024-08-20 15:06:57 +02:00
|
|
|
/**
|
2024-08-22 14:19:42 +02:00
|
|
|
* @return OrganizationProvider
|
2024-11-18 18:04:40 +01:00
|
|
|
* @throws OrganizationProviderNotFound
|
2024-08-20 15:06:57 +02:00
|
|
|
*/
|
2024-11-18 18:04:40 +01:00
|
|
|
public function getOrganizationProvider($id): OrganizationProvider {
|
|
|
|
$organizationProvider = $this->organizationProviders[$id];
|
|
|
|
if(isset($organizationProvider)) {
|
|
|
|
return $organizationProvider;
|
|
|
|
} else {
|
|
|
|
throw new OrganizationProviderNotFound($id);
|
|
|
|
}
|
2024-08-20 15:06:57 +02:00
|
|
|
}
|
|
|
|
|
2024-08-22 14:19:42 +02:00
|
|
|
public function registerOrganizationProvider(OrganizationProvider $organizationProvider): self {
|
|
|
|
$this->organizationProviders[$organizationProvider->getId()] = $organizationProvider;
|
2024-08-20 15:06:57 +02:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|