Bristol SU Support Package
src
Authentication
AuthenticationResourceIdGenerator.php
Go to the documentation of this file.
1
<?php
2
3
namespace
BristolSU\Support\Authentication
;
4
5
use
BristolSU\Support\Authentication\Contracts\Authentication
;
6
use
BristolSU\Support\Authentication\Contracts\ResourceIdGenerator
;
7
11
class
AuthenticationResourceIdGenerator
implements
ResourceIdGenerator
12
{
13
19
private
$authentication
;
20
26
public
function
__construct
(
Authentication
$authentication
)
27
{
28
$this->authentication =
$authentication
;
29
}
30
41
public
function
fromString
(
string
$resourceType): int
42
{
43
if
($resourceType ===
'user'
) {
44
$model = $this->authentication->getUser();
45
} elseif ($resourceType ===
'group'
) {
46
$model = $this->authentication->getGroup();
47
} elseif ($resourceType ===
'role'
) {
48
$model = $this->authentication->getRole();
49
}
50
if
($model === null) {
51
throw
new \Exception(
'Not logged into correct model'
);
52
}
53
return
$model->id();
54
}
55
}
BristolSU\Support\Authentication
Definition:
ApiAuthentication.php:3
BristolSU\Support\Authentication\Contracts\Authentication
Definition:
Authentication.php:15
BristolSU\Support\Authentication\AuthenticationResourceIdGenerator
Definition:
AuthenticationResourceIdGenerator.php:11
BristolSU\Support\Authentication\Contracts\ResourceIdGenerator
Definition:
ResourceIdGenerator.php:8
ResourceIdGenerator
BristolSU\Support\Authentication\AuthenticationResourceIdGenerator\__construct
__construct(Authentication $authentication)
Definition:
AuthenticationResourceIdGenerator.php:26
BristolSU\Support\Authentication\AuthenticationResourceIdGenerator\fromString
fromString(string $resourceType)
Definition:
AuthenticationResourceIdGenerator.php:41
Authentication
BristolSU\Support\Authentication\AuthenticationResourceIdGenerator\$authentication
$authentication
Definition:
AuthenticationResourceIdGenerator.php:19
Generated by
1.8.13