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