| 1 |
<?php |
| 2 |
|
| 3 |
declare( strict_types=1 ); |
| 4 |
|
| 5 |
namespace Packetery\Module\Log; |
| 6 |
|
| 7 |
class LogSizeLimiterState { |
| 8 |
|
| 9 |
/** @var array<int, string> */ |
| 10 |
private $recordQueue; |
| 11 |
|
| 12 |
/** @var int */ |
| 13 |
private $totalSize; |
| 14 |
|
| 15 |
/** @var array<int, string> */ |
| 16 |
private $currentRecordLines; |
| 17 |
|
| 18 |
/** @var int|null */ |
| 19 |
private $currentRecordTime; |
| 20 |
|
| 21 |
/** |
| 22 |
* @param array<int, string> $recordQueue |
| 23 |
* @param int $totalSize |
| 24 |
* @param array<int, string> $currentRecordLines |
| 25 |
* @param int|null $currentRecordTime |
| 26 |
*/ |
| 27 |
public function __construct( |
| 28 |
array $recordQueue, |
| 29 |
int $totalSize, |
| 30 |
array $currentRecordLines, |
| 31 |
?int $currentRecordTime |
| 32 |
) { |
| 33 |
$this->recordQueue = $recordQueue; |
| 34 |
$this->totalSize = $totalSize; |
| 35 |
$this->currentRecordLines = $currentRecordLines; |
| 36 |
$this->currentRecordTime = $currentRecordTime; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* @return array<int, string> |
| 41 |
*/ |
| 42 |
public function getRecordQueue(): array { |
| 43 |
return $this->recordQueue; |
| 44 |
} |
| 45 |
|
| 46 |
public function shiftRecordQueue(): ?string { |
| 47 |
return array_shift( $this->recordQueue ); |
| 48 |
} |
| 49 |
|
| 50 |
public function addRecordToQueue( string $recordContent ): void { |
| 51 |
$this->recordQueue[] = $recordContent; |
| 52 |
} |
| 53 |
|
| 54 |
public function getTotalSize(): int { |
| 55 |
return $this->totalSize; |
| 56 |
} |
| 57 |
|
| 58 |
public function addToTotalSize( int $size ): void { |
| 59 |
$this->totalSize += $size; |
| 60 |
} |
| 61 |
|
| 62 |
public function subtractFromTotalSize( int $size ): void { |
| 63 |
$this->totalSize -= $size; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* @return array<int, string> |
| 68 |
*/ |
| 69 |
public function getCurrentRecordLines(): array { |
| 70 |
return $this->currentRecordLines; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* @param array<int, string> $currentRecordLines |
| 75 |
*/ |
| 76 |
public function setCurrentRecordLines( array $currentRecordLines ): void { |
| 77 |
$this->currentRecordLines = $currentRecordLines; |
| 78 |
} |
| 79 |
|
| 80 |
public function addCurrentRecordLine( string $line ): void { |
| 81 |
$this->currentRecordLines[] = $line; |
| 82 |
} |
| 83 |
|
| 84 |
public function emptyCurrentRecordLines(): void { |
| 85 |
$this->currentRecordLines = []; |
| 86 |
} |
| 87 |
|
| 88 |
public function getCurrentRecordTime(): ?int { |
| 89 |
return $this->currentRecordTime; |
| 90 |
} |
| 91 |
|
| 92 |
public function setCurrentRecordTime( ?int $currentRecordTime ): void { |
| 93 |
$this->currentRecordTime = $currentRecordTime; |
| 94 |
} |
| 95 |
} |
| 96 |
|