-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrincipal.php
More file actions
68 lines (60 loc) · 1.36 KB
/
Principal.php
File metadata and controls
68 lines (60 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*
* Opulence
*
* @link https://www.opulencephp.com
* @copyright Copyright (C) 2021 David Young
* @license https://github.com/opulencephp/Opulence/blob/1.2/LICENSE.md
*/
namespace Opulence\Authentication;
/**
* Defines a principal identity
*/
class Principal implements IPrincipal
{
/** @var string The type of principal this is */
protected $type = '';
/** @var mixed|null The identity of the principal */
protected $id = null;
/** @var array The list of roles this principal has */
protected $roles = [];
/**
* @param string $type The type of principal this is
* @param mixed $id The identity of the principal
* @param array $roles The list of roles this principal has
*/
public function __construct(string $type, $id, array $roles)
{
$this->type = $type;
$this->id = $id;
$this->roles = $roles;
}
/**
* @inheritdoc
*/
public function getId()
{
return $this->id;
}
/**
* @inheritdoc
*/
public function getRoles() : array
{
return $this->roles;
}
/**
* @inheritdoc
*/
public function getType() : string
{
return $this->type;
}
/**
* @inheritdoc
*/
public function hasRole(string $roleName) : bool
{
return in_array($roleName, $this->roles);
}
}