-
-
Notifications
You must be signed in to change notification settings - Fork 115
Support PSR-20 (clock) #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hi @tscni, Many thanks for this PR. I agree with the need to decouple from the platform and the use of the PSR-20 instead of direct calls to
//Example not tested
// Note that I do not care of the timezone as the library only needs the timestamp
use Psr\Clock\ClockInterface;
/**
* @internal
*/
final class InternalClock implements ClockInterface
{
public function now(): DateTimeImmutable
{
return DateTimeImmutable::createFromFormat('U.u', (string) microtime(true));
}
} |
89edbc5
to
c3cfc03
Compare
I've adjusted the implementation accordingly. It's not quite clear to me which locations you'd prefer for the clock, so I just put it in the Speaking towards the deprecation though. |
c3cfc03
to
315fc5b
Compare
315fc5b
to
129e959
Compare
As this is only used in the
I am not sure this is really complicated for the Symfony bundle. What about turning the |
In any case, this PR looks good to me. There is no need for chasing all green lights in this PR. |
That'd be an option, but then you'd still have to maintain |
Yes that's the idea for this branch and to avoid BC breaks. That's why it is marked as |
Hi @tscni, I have just pushed a commit where a new configuration option is present for the Checker configuration section. |
public function __construct( | ||
private readonly int $allowedTimeDrift = 0, | ||
private readonly bool $protectedHeaderOnly = false | ||
private readonly bool $protectedHeaderOnly = false, | ||
?ClockInterface $clock = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having this argument as the last one means that you cannot actually remove the nullable type in 4.0 as you cannot make it mandatory without making all other arguments mandatory as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi there
To simplify testing of systems that use the time based checkers (exp, iat, nbf), I'd like to introduce support for PSR-20 (psr/clock). This would remove the necessity for cumbersome
time()
-mocking.Depending on your preferences, I could adjust the implementation.
symfony/clock
as thepsr/clock
implementation, but we could just as well use another one, implement an internal one (it's trivial after all), or none (and default totime()
).The benefit of not adding an implementation dependency is that users wouldn't be forced to add one they might otherwise not use.
time()
usages inEncrypterTest
andJWSTest
that could also use a clock implementation for consistency, though it wouldn't have any value beyond that.