0 follower

Final Class Yiisoft\HttpMiddleware\HttpCache\LastModifiedProvider\PredefinedLastModifiedProvider

InheritanceYiisoft\HttpMiddleware\HttpCache\LastModifiedProvider\PredefinedLastModifiedProvider
ImplementsYiisoft\HttpMiddleware\HttpCache\LastModifiedProvider\LastModifiedProviderInterface

Provides dates from a predefined collection. Useful for testing purposes.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( iterable $dates )
$dates iterable

Predefined dates to be returned by the provider.

                public function __construct(iterable $dates)
{
    $this->iterator = $this->createIterator($dates);
}

            
get() public method

public DateTimeImmutable get ( \Psr\Http\Message\ServerRequestInterface $request )
$request \Psr\Http\Message\ServerRequestInterface

                public function get(ServerRequestInterface $request): DateTimeImmutable
{
    if (!$this->iterator->valid()) {
        throw new OutOfBoundsException('No more dates available.');
    }
    /** @var DateTimeImmutable $date */
    $date = $this->iterator->current();
    $this->iterator->next();
    return $date;
}