mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-11-21 20:28:11 +01:00
implemented organization provider registration
This commit is contained in:
parent
c0e2ec9d2e
commit
02bb8a330f
3 changed files with 82 additions and 0 deletions
27
lib/Events/RegisterOrganisationProviderEvent.php
Normal file
27
lib/Events/RegisterOrganisationProviderEvent.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\OrganizationFolders\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
|
||||
use OCA\OrganizationFolders\Transport\OrganisationProviderManager;
|
||||
|
||||
/**
|
||||
* This event is triggered during the initialization of Organisation Folders.
|
||||
*/
|
||||
class RegisterOrganisationProviderEvent extends Event {
|
||||
|
||||
/** @var OrganisationProviderManager */
|
||||
private $organisationProviderManager;
|
||||
|
||||
public function __construct(OrganisationProviderManager $organisationProviderManager) {
|
||||
parent::__construct();
|
||||
$this->organisationProviderManager = $organisationProviderManager;
|
||||
}
|
||||
|
||||
public function getOrganisationProviderManager(): OrganisationProviderManager {
|
||||
return $this->organisationProviderManager;
|
||||
}
|
||||
}
|
15
lib/OrganisationProvider/OrganisationProvider.php
Normal file
15
lib/OrganisationProvider/OrganisationProvider.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\OrganizationFolders\OrganisationProvider;
|
||||
|
||||
abstract class OrganisationProvider {
|
||||
protected $id;
|
||||
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
// TODO: functions to access organisation structure
|
||||
}
|
40
lib/OrganisationProvider/OrganisationProviderManager.php
Normal file
40
lib/OrganisationProvider/OrganisationProviderManager.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\OrganizationFolders\OrganisationProvider;
|
||||
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Server;
|
||||
|
||||
use OCA\OrganizationFolders\Events\RegisterOrganisationProviderEvent;
|
||||
|
||||
class OrganisationProviderManager {
|
||||
private array $organisationProviders = [];
|
||||
|
||||
public function __construct(
|
||||
IEventDispatcher $dispatcher,
|
||||
) {
|
||||
$event = new RegisterOrganisationProviderEvent($this);
|
||||
$dispatcher->dispatchTyped($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OrganisationProvider[]
|
||||
*/
|
||||
public function getOrganisationProviders(): array {
|
||||
return $this->organisationProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OrganisationProvider
|
||||
*/
|
||||
public function getOrganisationProvider($id): ?OrganisationProvider {
|
||||
return $this->organisationProviders[$id];
|
||||
}
|
||||
|
||||
public function registerOrganisationProvider(OrganisationProvider $organisationProvider): self {
|
||||
$this->organisationProviders[$organisationProvider->getId()] = $organisationProvider;
|
||||
return $this;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue