-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
387fc92
commit 13b76ed
Showing
2 changed files
with
86 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Aternos\Thanos\Pattern; | ||
|
||
use Aternos\Thanos\Chunk\ChunkInterface; | ||
|
||
class TimestampPattern implements ChunkPatternInterface | ||
{ | ||
/** | ||
* @param int $minTimestamp | ||
* @param bool $removeUnknownChunks | ||
*/ | ||
public function __construct( | ||
protected int $minTimestamp, | ||
protected bool $removeUnknownChunks, | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function matches(ChunkInterface $chunk): bool | ||
{ | ||
$time = $chunk->getTimestamp(); | ||
return $time > $this->minTimestamp || ($time === -1 && !$this->removeUnknownChunks); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getMinTimestamp(): int | ||
{ | ||
return $this->minTimestamp; | ||
} | ||
|
||
/** | ||
* @param int $minTimestamp | ||
* @return $this | ||
*/ | ||
public function setMinTimestamp(int $minTimestamp): TimestampPattern | ||
{ | ||
$this->minTimestamp = $minTimestamp; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function getRemoveUnknownChunks(): bool | ||
{ | ||
return $this->removeUnknownChunks; | ||
} | ||
|
||
/** | ||
* @param bool $removeUnknownChunks | ||
* @return $this | ||
*/ | ||
public function setRemoveUnknownChunks(bool $removeUnknownChunks): TimestampPattern | ||
{ | ||
$this->removeUnknownChunks = $removeUnknownChunks; | ||
return $this; | ||
} | ||
} |