Skip to content

Commit cdd9dc5

Browse files
committed
Set leeway on Datetime Claims creation
Copied from this PR: tymondesigns#2182
1 parent 44982a7 commit cdd9dc5

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/Claims/DatetimeTrait.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,27 @@ trait DatetimeTrait
2525
*/
2626
protected $leeway = 0;
2727

28+
/**
29+
* @param mixed $value
30+
* @param int $leeway
31+
*
32+
* @return void
33+
*/
34+
public function __construct($value, $leeway = 0)
35+
{
36+
$this->leeway = $leeway;
37+
38+
parent::__construct($value);
39+
}
40+
2841
/**
2942
* Set the claim value, and call a validate method.
3043
*
3144
* @param mixed $value
32-
* @return $this
3345
*
3446
* @throws \Tymon\JWTAuth\Exceptions\InvalidClaimException
47+
*
48+
* @return $this
3549
*/
3650
public function setValue($value)
3751
{
@@ -62,6 +76,7 @@ public function validateCreate($value)
6276
* Determine whether the value is in the future.
6377
*
6478
* @param mixed $value
79+
*
6580
* @return bool
6681
*/
6782
protected function isFuture($value)
@@ -73,6 +88,7 @@ protected function isFuture($value)
7388
* Determine whether the value is in the past.
7489
*
7590
* @param mixed $value
91+
*
7692
* @return bool
7793
*/
7894
protected function isPast($value)
@@ -84,6 +100,7 @@ protected function isPast($value)
84100
* Set the leeway in seconds.
85101
*
86102
* @param int $leeway
103+
*
87104
* @return $this
88105
*/
89106
public function setLeeway($leeway)

src/Claims/Factory.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Factory
5757
* Constructor.
5858
*
5959
* @param \Illuminate\Http\Request $request
60+
*
6061
* @return void
6162
*/
6263
public function __construct(Request $request)
@@ -69,16 +70,13 @@ public function __construct(Request $request)
6970
*
7071
* @param string $name
7172
* @param mixed $value
73+
*
7274
* @return \Tymon\JWTAuth\Claims\Claim
7375
*/
7476
public function get($name, $value)
7577
{
7678
if ($this->has($name)) {
77-
$claim = new $this->classMap[$name]($value);
78-
79-
return method_exists($claim, 'setLeeway') ?
80-
$claim->setLeeway($this->leeway) :
81-
$claim;
79+
return new $this->classMap[$name]($value, $this->leeway);
8280
}
8381

8482
return new Custom($name, $value);
@@ -88,6 +86,7 @@ public function get($name, $value)
8886
* Check whether the claim exists.
8987
*
9088
* @param string $name
89+
*
9190
* @return bool
9291
*/
9392
public function has($name)
@@ -99,6 +98,7 @@ public function has($name)
9998
* Generate the initial value and return the Claim instance.
10099
*
101100
* @param string $name
101+
*
102102
* @return \Tymon\JWTAuth\Claims\Claim
103103
*/
104104
public function make($name)
@@ -161,6 +161,7 @@ public function jti()
161161
*
162162
* @param string $name
163163
* @param string $classPath
164+
*
164165
* @return $this
165166
*/
166167
public function extend($name, $classPath)
@@ -174,6 +175,7 @@ public function extend($name, $classPath)
174175
* Set the request instance.
175176
*
176177
* @param \Illuminate\Http\Request $request
178+
*
177179
* @return $this
178180
*/
179181
public function setRequest(Request $request)
@@ -187,6 +189,7 @@ public function setRequest(Request $request)
187189
* Set the token ttl (in minutes).
188190
*
189191
* @param int $ttl
192+
*
190193
* @return $this
191194
*/
192195
public function setTTL($ttl)
@@ -210,6 +213,7 @@ public function getTTL()
210213
* Set the leeway in seconds.
211214
*
212215
* @param int $leeway
216+
*
213217
* @return $this
214218
*/
215219
public function setLeeway($leeway)

0 commit comments

Comments
 (0)