mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-11-21 11:37:26 +01:00
added not found errors to be used by organization providers
This commit is contained in:
parent
38b1406d40
commit
2521a35b2a
6 changed files with 46 additions and 2 deletions
14
lib/Errors/NotFoundException.php
Normal file
14
lib/Errors/NotFoundException.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OrganizationFolders\Errors;
|
||||
|
||||
abstract class NotFoundException extends \RuntimeException {
|
||||
public function __construct($entity, array|string $criteria) {
|
||||
$message = sprintf(
|
||||
"Could not find %s with criteria %s",
|
||||
class_exists($entity) ? array_pop(explode('\\', $entity)) : $entity,
|
||||
is_string($criteria) ? $criteria : json_encode($criteria),
|
||||
);
|
||||
parent::__construct($message);
|
||||
}
|
||||
}
|
9
lib/Errors/OrganizationNotFound.php
Normal file
9
lib/Errors/OrganizationNotFound.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OrganizationFolders\Errors;
|
||||
|
||||
class OrganizationNotFound extends NotFoundException {
|
||||
public function __construct($provider, $id) {
|
||||
parent::__construct(OCA\OrganizationFolders\Model\Organization::class, ["provider" => $provider, "id" => $id]);
|
||||
}
|
||||
}
|
9
lib/Errors/OrganizationRoleNotFound.php
Normal file
9
lib/Errors/OrganizationRoleNotFound.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OrganizationFolders\Errors;
|
||||
|
||||
class OrganizationRoleNotFound extends NotFoundException {
|
||||
public function __construct($provider, $id) {
|
||||
parent::__construct(OCA\OrganizationFolders\Model\OrganizationRole::class, ["provider" => $provider, "id" => $id]);
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ namespace OCA\OrganizationFolders\Events;
|
|||
|
||||
use OCP\EventDispatcher\Event;
|
||||
|
||||
use OCA\OrganizationFolders\Transport\OrganizationProviderManager;
|
||||
use OCA\OrganizationFolders\OrganizationProvider\OrganizationProviderManager;
|
||||
|
||||
/**
|
||||
* This event is triggered during the initialization of Organization Folders.
|
|
@ -7,6 +7,9 @@ namespace OCA\OrganizationFolders\OrganizationProvider;
|
|||
use OCA\OrganizationFolders\Model\Organization;
|
||||
use OCA\OrganizationFolders\Model\OrganizationRole;
|
||||
|
||||
use OCA\OrganizationFolders\Errors\OrganizationNotFound;
|
||||
use OCA\OrganizationFolders\Errors\OrganizationRoleNotFound;
|
||||
|
||||
abstract class OrganizationProvider {
|
||||
protected $id;
|
||||
|
||||
|
@ -17,6 +20,7 @@ abstract class OrganizationProvider {
|
|||
/**
|
||||
* Get specific role by its id (unique within OrganizationProvider)
|
||||
* @return Organization
|
||||
* @throws OrganizationNotFound
|
||||
*/
|
||||
abstract public function getOrganization(int $id): Organization;
|
||||
|
||||
|
@ -56,9 +60,10 @@ abstract class OrganizationProvider {
|
|||
abstract public function getSubOrganizations(?int $parentOrganizationId): array;
|
||||
|
||||
/**
|
||||
* Get specific role by its id (unique within OrganizationProvider)
|
||||
* Get a specific role by its id (must be unique within organization provider, not just within parent organization)
|
||||
*
|
||||
* @return OrganizationRole
|
||||
* @throws OrganizationRoleNotFound
|
||||
*/
|
||||
abstract public function getRole(int $id): OrganizationRole;
|
||||
|
|
@ -26,6 +26,13 @@ class OrganizationProviderManager {
|
|||
return $this->organizationProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasOrganizationProvider($id): bool {
|
||||
return array_key_exists($id, $this->organizationProviders);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return OrganizationProvider
|
||||
*/
|
Loading…
Reference in a new issue