| 1 |
<?php |
| 2 |
|
| 3 |
namespace Aws\S3\S3Transfer\Progress; |
| 4 |
|
| 5 |
use Throwable; |
| 6 |
|
| 7 |
final class TransferProgressSnapshot |
| 8 |
{ |
| 9 |
|
| 10 |
private string $identifier; |
| 11 |
|
| 12 |
|
| 13 |
private int $transferredBytes; |
| 14 |
|
| 15 |
|
| 16 |
private int $totalBytes; |
| 17 |
|
| 18 |
|
| 19 |
private array|null $response; |
| 20 |
|
| 21 |
|
| 22 |
private Throwable|string|null $reason; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public function __construct( |
| 32 |
string $identifier, |
| 33 |
int $transferredBytes, |
| 34 |
int $totalBytes, |
| 35 |
?array $response = null, |
| 36 |
Throwable|string|null $reason = null, |
| 37 |
) { |
| 38 |
$this->identifier = $identifier; |
| 39 |
$this->transferredBytes = $transferredBytes; |
| 40 |
$this->totalBytes = $totalBytes; |
| 41 |
$this->response = $response; |
| 42 |
$this->reason = $reason; |
| 43 |
} |
| 44 |
|
| 45 |
public function getIdentifier(): string |
| 46 |
{ |
| 47 |
return $this->identifier; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public function getTransferredBytes(): int |
| 54 |
{ |
| 55 |
return $this->transferredBytes; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public function getTotalBytes(): int |
| 62 |
{ |
| 63 |
return $this->totalBytes; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public function getResponse(): array|null |
| 70 |
{ |
| 71 |
return $this->response; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public function ratioTransferred(): float |
| 78 |
{ |
| 79 |
if ($this->totalBytes === 0) { |
| 80 |
|
| 81 |
return 0; |
| 82 |
} |
| 83 |
|
| 84 |
return $this->transferredBytes / $this->totalBytes; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public function getReason(): Throwable|string|null |
| 91 |
{ |
| 92 |
return $this->reason; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
public function toArray(): array |
| 99 |
{ |
| 100 |
return [ |
| 101 |
'identifier' => $this->identifier, |
| 102 |
'transferredBytes' => $this->transferredBytes, |
| 103 |
'totalBytes' => $this->totalBytes, |
| 104 |
'reason' => $this->reason, |
| 105 |
'response' => $this->response, |
| 106 |
]; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
public function withResponse(array $response): TransferProgressSnapshot |
| 115 |
{ |
| 116 |
return new self( |
| 117 |
$this->identifier, |
| 118 |
$this->transferredBytes, |
| 119 |
$this->totalBytes, |
| 120 |
$response, |
| 121 |
); |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public static function fromArray(array $data): TransferProgressSnapshot |
| 130 |
{ |
| 131 |
return new self( |
| 132 |
$data['identifier'] ?? null, |
| 133 |
$data['transferredBytes'] ?? 0, |
| 134 |
$data['totalBytes'] ?? 0, |
| 135 |
$data['response'] ?? null, |
| 136 |
$data['reason'] ?? null |
| 137 |
); |
| 138 |
} |
| 139 |
} |