mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-12-06 11:22:41 +01:00
34 lines
No EOL
1.2 KiB
PHP
34 lines
No EOL
1.2 KiB
PHP
<?php
|
|
|
|
namespace OCA\OrganizationFolders\Model;
|
|
|
|
use OCP\IUserManager;
|
|
use OCP\IGroupManager;
|
|
|
|
use OCA\OrganizationFolders\Enum\PrincipalType;
|
|
use OCA\OrganizationFolders\OrganizationProvider\OrganizationProviderManager;
|
|
|
|
class PrincipalFactory {
|
|
public function __construct(
|
|
protected IUserManager $userManager,
|
|
protected IGroupManager $groupManager,
|
|
protected OrganizationProviderManager $organizationProviderManager,
|
|
) {
|
|
}
|
|
|
|
public function buildPrincipal(PrincipalType $type, string $id): Principal {
|
|
if($type === PrincipalType::USER) {
|
|
return new UserPrincipal($this->userManager, $id);
|
|
} else if ($type === PrincipalType::GROUP) {
|
|
return new GroupPrincipal($this->groupManager, $id);
|
|
} else if ($type === PrincipalType::ROLE) {
|
|
[$organizationProviderId, $roleId] = explode(":", $id, 2);
|
|
if(!(isset($organizationProviderId) && isset($roleId))) {
|
|
throw new \Exception("Invalid id format for principal of type role");
|
|
}
|
|
return new RolePrincipal($this->organizationProviderManager, $organizationProviderId, $roleId);
|
|
} else {
|
|
throw new \Exception("invalid PrincipalType");
|
|
}
|
|
}
|
|
} |