You've already forked php-flasher
mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-04-05 20:42:56 +01:00
50 lines
988 B
PHP
50 lines
988 B
PHP
<?php
|
|
|
|
namespace Flasher\Prime\Filter\Specification;
|
|
|
|
use DateTime;
|
|
use Flasher\Prime\Envelope;
|
|
|
|
final class TimeSpecification implements SpecificationInterface
|
|
{
|
|
/**
|
|
* @var int
|
|
*/
|
|
private $minTime;
|
|
|
|
/**
|
|
* @var int|null
|
|
*/
|
|
private $maxTime;
|
|
|
|
/**
|
|
* @param DateTime $minTime
|
|
* @param DateTime|null $maxTime
|
|
*/
|
|
public function __construct(DateTime $minTime, DateTime $maxTime = null)
|
|
{
|
|
$this->minTime = $minTime;
|
|
$this->maxTime = $maxTime;
|
|
}
|
|
|
|
/**
|
|
* @param Envelope $envelope
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function isSatisfiedBy(Envelope $envelope)
|
|
{
|
|
$stamp = $envelope->get('Flasher\Prime\Stamp\CreatedAtStamp');
|
|
|
|
if (null === $stamp) {
|
|
return false;
|
|
}
|
|
|
|
if (null !== $this->maxTime && $stamp->getCreatedAt() > $this->maxTime) {
|
|
return false;
|
|
}
|
|
|
|
return $stamp->getCreatedAt() >= $this->minTime;
|
|
}
|
|
}
|