Skip to content

Commit

Permalink
Revert interface changes, mark implementation methods
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rdex committed Nov 6, 2024
1 parent b0ad41f commit 5012bc4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,65 +18,49 @@ interface Builder
* Appends new items to audience
*
* @param non-empty-string ...$audiences
*
* @pure
*/
public function permittedFor(string ...$audiences): Builder;

/**
* Configures the expiration time
*
* @pure
*/
public function expiresAt(DateTimeImmutable $expiration): Builder;

/**
* Configures the token id
*
* @param non-empty-string $id
*
* @pure
*/
public function identifiedBy(string $id): Builder;

/**
* Configures the time that the token was issued
*
* @pure
*/
public function issuedAt(DateTimeImmutable $issuedAt): Builder;

/**
* Configures the issuer
*
* @param non-empty-string $issuer
*
* @pure
*/
public function issuedBy(string $issuer): Builder;

/**
* Configures the time before which the token cannot be accepted
*
* @pure
*/
public function canOnlyBeUsedAfter(DateTimeImmutable $notBefore): Builder;

/**
* Configures the subject
*
* @param non-empty-string $subject
*
* @pure
*/
public function relatedTo(string $subject): Builder;

/**
* Configures a header item
*
* @param non-empty-string $name
*
* @pure
*/
public function withHeader(string $name, mixed $value): Builder;

Expand All @@ -86,8 +70,6 @@ public function withHeader(string $name, mixed $value): Builder;
* @param non-empty-string $name
*
* @throws RegisteredClaimGiven When trying to set a registered claim.
*
* @pure
*/
public function withClaim(string $name, mixed $value): Builder;

Expand Down
36 changes: 36 additions & 0 deletions src/Token/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function __construct(private readonly Encoder $encoder, private readonly
{
}

/**
* @inheritDoc
* @pure
*/
public function permittedFor(string ...$audiences): BuilderInterface
{
$configured = $this->claims[RegisteredClaims::AUDIENCE] ?? [];
Expand All @@ -37,36 +41,64 @@ public function permittedFor(string ...$audiences): BuilderInterface
return $this->setClaim(RegisteredClaims::AUDIENCE, array_merge($configured, $toAppend));
}

/**
* @inheritDoc
* @pure
*/
public function expiresAt(DateTimeImmutable $expiration): BuilderInterface
{
return $this->setClaim(RegisteredClaims::EXPIRATION_TIME, $expiration);
}

/**
* @inheritDoc
* @pure
*/
public function identifiedBy(string $id): BuilderInterface
{
return $this->setClaim(RegisteredClaims::ID, $id);
}

/**
* @inheritDoc
* @pure
*/
public function issuedAt(DateTimeImmutable $issuedAt): BuilderInterface
{
return $this->setClaim(RegisteredClaims::ISSUED_AT, $issuedAt);
}

/**
* @inheritDoc
* @pure
*/
public function issuedBy(string $issuer): BuilderInterface
{
return $this->setClaim(RegisteredClaims::ISSUER, $issuer);
}

/**
* @inheritDoc
* @pure
*/
public function canOnlyBeUsedAfter(DateTimeImmutable $notBefore): BuilderInterface
{
return $this->setClaim(RegisteredClaims::NOT_BEFORE, $notBefore);
}

/**
* @inheritDoc
* @pure
*/
public function relatedTo(string $subject): BuilderInterface
{
return $this->setClaim(RegisteredClaims::SUBJECT, $subject);
}

/**
* @inheritDoc
* @pure
*/
public function withHeader(string $name, mixed $value): BuilderInterface
{
$new = clone $this;
Expand All @@ -75,6 +107,10 @@ public function withHeader(string $name, mixed $value): BuilderInterface
return $new;
}

/**
* @inheritDoc
* @pure
*/
public function withClaim(string $name, mixed $value): BuilderInterface
{
if (in_array($name, RegisteredClaims::ALL, true)) {
Expand Down

0 comments on commit 5012bc4

Please sign in to comment.