Skip to content

Commit

Permalink
Sync implementation with http-structured-field package update
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Nov 24, 2024
1 parent 49a45fe commit 8cc045c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/Forward.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ public function toStructuredField(): Parameters
{
return Parameters::new()
->append(Properties::Forward->value, $this->reason->toToken())
->append(Properties::ForwardStatusCode->value, $this->statusCode)
->append(Properties::Stored->value, $this->stored)
->append(Properties::Collapsed->value, $this->collapsed)
->filter(fn (array $pair): bool => false !== $pair[1]->value());
->when(null !== $this->statusCode, fn (Parameters $parameters) => $parameters->append(Properties::ForwardStatusCode->value, $this->statusCode)) /* @phpstan-ignore-line */
->when(true === $this->stored, fn (Parameters $parameters) => $parameters->append(Properties::Stored->value, $this->stored))
->when(true === $this->collapsed, fn (Parameters $parameters) => $parameters->append(Properties::Collapsed->value, $this->collapsed));
}

public function equals(mixed $other): bool
Expand Down
15 changes: 5 additions & 10 deletions src/HandledRequestCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Bakame\Http\CacheStatus;

use Bakame\Http\StructuredFields\Item;
use Bakame\Http\StructuredFields\Parameters;
use Bakame\Http\StructuredFields\StructuredFieldProvider;
use Bakame\Http\StructuredFields\Token;
use Bakame\Http\StructuredFields\Type;
Expand Down Expand Up @@ -136,15 +135,11 @@ private static function validator(): ItemValidator
public function toStructuredField(): Item
{
return Item::new($this->servedBy)
->withParameters(
Parameters::new()
->append(Properties::Hit->value, $this->hit)
->mergePairs($this->forward ?? [])
->append(Properties::TimeToLive->value, $this->ttl)
->append(Properties::Key->value, $this->key)
->append(Properties::Detail->value, $this->detail)
->filter(fn (array $pair): bool => false !== $pair[1]->value()),
);
->when(true === $this->hit, fn (Item $item) => $item->appendParameter(Properties::Hit->value, $this->hit))
->when(null !== $this->forward, fn (Item $item) => $item->mergeParametersByPairs($this->forward)) /* @phpstan-ignore-line */
->when(null !== $this->ttl, fn (Item $item) => $item->appendParameter(Properties::TimeToLive->value, $this->ttl)) /* @phpstan-ignore-line */
->when(null !== $this->key, fn (Item $item) => $item->appendParameter(Properties::Key->value, $this->key)) /* @phpstan-ignore-line */
->when(null !== $this->detail, fn (Item $item) => $item->appendParameter(Properties::Detail->value, $this->detail)); /* @phpstan-ignore-line */
}

/**
Expand Down

0 comments on commit 8cc045c

Please sign in to comment.