/
ClaimFactory.php
58 lines (51 loc) · 1.41 KB
/
ClaimFactory.php
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
<?php
/*
* This file is part of the Spira framework.
*
* @link https://github.com/spira/spira
*
* For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
*/
namespace App\Extensions\JWTAuth;
use Tymon\JWTAuth\Claims\Custom;
use Tymon\JWTAuth\Claims\Factory;
class ClaimFactory extends Factory
{
/**
* @var array
*/
private static $classMap = [
'aud' => 'Tymon\JWTAuth\Claims\Audience',
'exp' => 'Tymon\JWTAuth\Claims\Expiration',
'iat' => 'Tymon\JWTAuth\Claims\IssuedAt',
'iss' => 'Tymon\JWTAuth\Claims\Issuer',
'jti' => 'Tymon\JWTAuth\Claims\JwtId',
'nbf' => 'Tymon\JWTAuth\Claims\NotBefore',
'sub' => 'Tymon\JWTAuth\Claims\Subject',
'_user' => 'App\Extensions\JWTAuth\UserClaim',
];
/**
* Get the instance of the claim when passing the name and value.
*
* @param string $name
* @param mixed $value
* @return \Tymon\JWTAuth\Claims\Claim
*/
public function get($name, $value)
{
if ($this->has($name)) {
return new self::$classMap[$name]($value);
}
return new Custom($name, $value);
}
/**
* Check whether the claim exists.
*
* @param string $name
* @return bool
*/
public function has($name)
{
return array_key_exists($name, self::$classMap);
}
}