@@ -13,6 +13,11 @@ class MultipartCopy extends AbstractUploadManager
1313 getInitiateParams as private traitGetInitiateParams;
1414 }
1515
16+ private const VALID_METADATA_DIRECTIVES = [
17+ 'COPY ' => true ,
18+ 'REPLACE ' => true ,
19+ ];
20+
1621 /**
1722 * Metadata fields that can be copied from the source object
1823 * to the destination during a multipart copy.
@@ -70,10 +75,10 @@ class MultipartCopy extends AbstractUploadManager
7075 * source object metadata to the destination. Set to 'COPY' to
7176 * automatically forward metadata fields (Metadata, CacheControl,
7277 * ContentDisposition, ContentEncoding, ContentLanguage, ContentType,
73- * Expires) from the source object. Set to 'REPLACE' to suppress automatic
74- * metadata copying (you must then provide your own metadata via the
75- * 'params' option). User-provided values in 'params' always take
76- * precedence over source metadata .
78+ * Expires) from the source object. When set to 'COPY', source metadata
79+ * takes precedence and any matching fields provided in 'params' are
80+ * ignored. Set to 'REPLACE' to suppress automatic metadata copying and
81+ * use your own values via the 'params' option .
7782 * - source_metadata: (Aws\ResultInterface) The result of a HeadObject call
7883 * on the copy source. If not provided, the SDK makes a HeadObject request
7984 * to obtain the source object's size and metadata. Providing this avoids
@@ -211,7 +216,7 @@ protected function getInitiateParams()
211216
212217 $ directive = strtoupper ($ this ->config ['metadata_directive ' ] ?? 'COPY ' );
213218
214- if (!in_array ( $ directive, [ ' COPY ' , ' REPLACE ' ], true )) {
219+ if (!isset ( self :: VALID_METADATA_DIRECTIVES [ $ directive] )) {
215220 throw new \InvalidArgumentException (
216221 "Invalid metadata_directive value ' $ directive'. "
217222 . " Must be 'COPY' or 'REPLACE'. "
@@ -221,7 +226,7 @@ protected function getInitiateParams()
221226 if ($ directive === 'COPY ' ) {
222227 $ sourceMetadata = $ this ->getSourceMetadata ();
223228 foreach (self ::$ copyMetadataFields as $ field ) {
224- if (!isset ( $ params [ $ field ]) && ! empty ($ sourceMetadata [$ field ])) {
229+ if (!empty ($ sourceMetadata [$ field ])) {
225230 $ params [$ field ] = $ sourceMetadata [$ field ];
226231 }
227232 }
0 commit comments