1 | <?php |
||
15 | class JwtService |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | private $key; |
||
22 | |||
23 | /** |
||
24 | * @var ClaimManager |
||
25 | */ |
||
26 | protected $claimManager; |
||
27 | |||
28 | /** |
||
29 | * JwtService constructor |
||
30 | * |
||
31 | * @param ClaimManager $claimManager |
||
32 | */ |
||
33 | public function __construct(ClaimManager $claimManager) |
||
40 | |||
41 | /** |
||
42 | * getTokenForUser method |
||
43 | * |
||
44 | * @param Claim $claim |
||
45 | * @return string |
||
46 | */ |
||
47 | public function getTokenForClaim(Claim $claim) |
||
54 | |||
55 | /** |
||
56 | * getEntityFromToken method |
||
57 | * |
||
58 | * @param string $token |
||
59 | * @return mixed |
||
60 | * @throws InaccessibleException |
||
61 | * @throws MalformedException |
||
62 | * @throws TokenExpiredException |
||
63 | * @throws InvalidTokenException |
||
64 | */ |
||
65 | public function getClaimFromToken($token) |
||
73 | |||
74 | /** |
||
75 | * refreshToken method |
||
76 | * |
||
77 | * @param string $token |
||
78 | * @return string |
||
79 | * @throws MalformedException |
||
80 | * @throws TokenExpiredException |
||
81 | * @throws InvalidTokenException |
||
82 | * @throws UnRefreshableException |
||
83 | */ |
||
84 | public function refreshToken($token) |
||
102 | |||
103 | /** |
||
104 | * invalidateToken method |
||
105 | * |
||
106 | * @param string $token |
||
107 | * @throws MalformedException |
||
108 | * @throws TokenExpiredException |
||
109 | * @throws UnRefreshableException |
||
110 | */ |
||
111 | public function invalidateToken($token) |
||
117 | |||
118 | /** |
||
119 | * wipeUserTokens method |
||
120 | * |
||
121 | * @param Claim $claim |
||
122 | */ |
||
123 | public function wipeUserTokens(Claim $claim) |
||
127 | |||
128 | /** |
||
129 | * getValidClaimFromToken method |
||
130 | * |
||
131 | * @param $token |
||
132 | * @return Claim |
||
133 | * @throws MalformedException |
||
134 | * @throws TokenExpiredException |
||
135 | * @throws InvalidTokenException |
||
136 | */ |
||
137 | protected function getValidClaimFromToken($token) |
||
156 | |||
157 | } |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: