PluginProbe
Media Cloud Sync / 1.0.0
Media Cloud Sync v1.0.0
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Multipart / UploadState.php

UploadState.php in Media Cloud Sync 1.0.0, at includes/sdk/s3/Aws/Multipart/UploadState.php

131 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\Multipart;
4
5 /**
6 * Representation of the multipart upload.
7 *
8 * This object keeps track of the state of the upload, including the status and
9 * which parts have been uploaded.
10 */
11 class UploadState
12 {
13 const CREATED = 0;
14 const INITIATED = 1;
15 const COMPLETED = 2;
16 /** @var array Params used to identity the upload. */
17 private $id;
18 /** @var int Part size being used by the upload. */
19 private $partSize;
20 /** @var array Parts that have been uploaded. */
21 private $uploadedParts = [];
22 /** @var int Identifies the status the upload. */
23 private $status = self::CREATED;
24 /**
25 * @param array $id Params used to identity the upload.
26 */
27 public function __construct(array $id)
28 {
29 $this->id = $id;
30 }
31 /**
32 * Get the upload's ID, which is a tuple of parameters that can uniquely
33 * identify the upload.
34 *
35 * @return array
36 */
37 public function getId()
38 {
39 return $this->id;
40 }
41 /**
42 * Set's the "upload_id", or 3rd part of the upload's ID. This typically
43 * only needs to be done after initiating an upload.
44 *
45 * @param string $key The param key of the upload_id.
46 * @param string $value The param value of the upload_id.
47 */
48 public function setUploadId($key, $value)
49 {
50 $this->id[$key] = $value;
51 }
52 /**
53 * Get the part size.
54 *
55 * @return int
56 */
57 public function getPartSize()
58 {
59 return $this->partSize;
60 }
61 /**
62 * Set the part size.
63 *
64 * @param $partSize int Size of upload parts.
65 */
66 public function setPartSize($partSize)
67 {
68 $this->partSize = $partSize;
69 }
70 /**
71 * Marks a part as being uploaded.
72 *
73 * @param int $partNumber The part number.
74 * @param array $partData Data from the upload operation that needs to be
75 * recalled during the complete operation.
76 */
77 public function markPartAsUploaded($partNumber, array $partData = [])
78 {
79 $this->uploadedParts[$partNumber] = $partData;
80 }
81 /**
82 * Returns whether a part has been uploaded.
83 *
84 * @param int $partNumber The part number.
85 *
86 * @return bool
87 */
88 public function hasPartBeenUploaded($partNumber)
89 {
90 return isset($this->uploadedParts[$partNumber]);
91 }
92 /**
93 * Returns a sorted list of all the uploaded parts.
94 *
95 * @return array
96 */
97 public function getUploadedParts()
98 {
99 \ksort($this->uploadedParts);
100 return $this->uploadedParts;
101 }
102 /**
103 * Set the status of the upload.
104 *
105 * @param int $status Status is an integer code defined by the constants
106 * CREATED, INITIATED, and COMPLETED on this class.
107 */
108 public function setStatus($status)
109 {
110 $this->status = $status;
111 }
112 /**
113 * Determines whether the upload state is in the INITIATED status.
114 *
115 * @return bool
116 */
117 public function isInitiated()
118 {
119 return $this->status === self::INITIATED;
120 }
121 /**
122 * Determines whether the upload state is in the COMPLETED status.
123 *
124 * @return bool
125 */
126 public function isCompleted()
127 {
128 return $this->status === self::COMPLETED;
129 }
130 }
131