PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
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
← All changes | includes/sdk/google/google/cloud-storage/src/StorageObject.php +211 -36 1.0.11.4.1 View file →
@@ -14,18 +14,18 @@
14 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 15 * See the License for the specific language governing permissions and
16 16 * limitations under the License.
17 17 */
18 -namespace Dudlewebs\WPMCS\Google\Cloud\Storage;
18 +namespace Dudlewebs\WPMCS\GCP\Google\Cloud\Storage;
19 19
20 -use Dudlewebs\WPMCS\Google\Cloud\Core\ArrayTrait;
21 -use Dudlewebs\WPMCS\Google\Cloud\Core\Exception\NotFoundException;
22 -use Dudlewebs\WPMCS\Google\Cloud\Core\Timestamp;
23 -use Dudlewebs\WPMCS\Google\Cloud\Core\Upload\SignedUrlUploader;
24 -use Dudlewebs\WPMCS\Google\Cloud\Storage\Connection\ConnectionInterface;
25 -use Dudlewebs\WPMCS\GuzzleHttp\Promise\PromiseInterface;
26 -use Dudlewebs\WPMCS\GuzzleHttp\Psr7\Utils;
27 -use Dudlewebs\WPMCS\Psr\Http\Message\StreamInterface;
20 +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\ArrayTrait;
21 +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\Exception\NotFoundException;
22 +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\Timestamp;
23 +use Dudlewebs\WPMCS\GCP\Google\Cloud\Core\Upload\SignedUrlUploader;
24 +use Dudlewebs\WPMCS\GCP\Google\Cloud\Storage\Connection\ConnectionInterface;
25 +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Promise\PromiseInterface;
26 +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Psr7\Utils;
27 +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\StreamInterface;
28 28 /**
29 29 * Objects are the individual pieces of data that you store in Google Cloud
30 30 * Storage.
31 31 *
@@ -156,9 +156,9 @@
156 156 * @return void
157 157 */
158 158 public function delete(array $options = [])
159 159 {
160 - $this->connection->deleteObject($options + array_filter($this->identity));
160 + $this->connection->deleteObject($options + \array_filter($this->identity));
161 161 }
162 162 /**
163 163 * Update the object. Upon receiving a result the local object's data will
164 164 * be updated.
@@ -221,9 +221,9 @@
221 221 // can only set predefinedAcl or acl
222 222 if (isset($options['predefinedAcl'])) {
223 223 $options['acl'] = null;
224 224 }
225 - return $this->info = $this->connection->patchObject($options + array_filter($this->identity));
225 + return $this->info = $this->connection->patchObject($options + \array_filter($this->identity));
226 226 }
227 227 /**
228 228 * Copy the object to a destination bucket.
229 229 *
@@ -421,8 +421,67 @@
421 421 } while ($options['rewriteToken']);
422 422 return new StorageObject($this->connection, $response['resource']['name'], $response['resource']['bucket'], $response['resource']['generation'], $response['resource'] + ['requesterProjectId' => $this->identity['userProject']], $destinationKey, $destinationKeySHA256);
423 423 }
424 424 /**
425 + * Move an object within a bucket.
426 + *
427 + * This method copies data using multiple requests so large objects can be
428 + * copied with a normal length timeout per request rather than one very long
429 + * timeout for a single request.
430 + *
431 + * Example:
432 + * ```
433 + * // Provide your destination object as a string.
434 + * $moveObject = $object->move('newObject.txt');
435 + * ```
436 + *
437 + * @see https://cloud.google.com/storage/docs/json_api/v1/objects/move Objects move API documentation.
438 + *
439 + * @param string $destinationObject The destination object.
440 + * @param array $options [optional]
441 + * Configuration options.
442 + *
443 + * @type string $ifGenerationMatch Makes the operation conditional on
444 + * whether the destination object's current generation matches the
445 + * given value.
446 + * @type string $ifGenerationNotMatch Makes the operation conditional on
447 + * whether the destination object's current generation does not
448 + * match the given value.
449 + * @type string $ifMetagenerationMatch Makes the operation conditional
450 + * on whether the destination object's current metageneration
451 + * matches the given value.
452 + * @type string $ifMetagenerationNotMatch Makes the operation
453 + * conditional on whether the destination object's current
454 + * metageneration does not match the given value.
455 + * @type string $ifSourceGenerationMatch Makes the operation conditional
456 + * on whether the source object's current generation matches the
457 + * given value.
458 + * @type string $ifSourceGenerationNotMatch Makes the operation
459 + * conditional on whether the source object's current generation
460 + * does not match the given value.
461 + * @type string $ifSourceMetagenerationMatch Makes the operation
462 + * conditional on whether the source object's current
463 + * metageneration matches the given value.
464 + * @type string $ifSourceMetagenerationNotMatch Makes the operation
465 + * conditional on whether the source object's current
466 + * metageneration does not match the given value.
467 + *
468 + * @return StorageObject
469 + * @throws \InvalidArgumentException
470 + */
471 + public function move($destinationObject, array $options = [])
472 + {
473 + if (!\is_string($destinationObject)) {
474 + throw new \InvalidArgumentException('$destinationObject must be a string.');
475 + }
476 + $options['bucket'] = $this->identity['bucket'];
477 + $options['sourceObject'] = $this->identity['object'];
478 + $options['destinationObject'] = $destinationObject;
479 + $options['userProject'] = $this->identity['userProject'];
480 + $response = $this->connection->moveObject($options);
481 + return new StorageObject($this->connection, $response['name'], $response['bucket'], $response['generation'], $response + ['requesterProjectId' => $this->identity['userProject']]);
482 + }
483 + /**
425 484 * Renames the object.
426 485 *
427 486 * Please note that there is no atomic rename provided by the Storage API.
428 487 * This method is for convenience and is a set of sequential calls to copy
@@ -484,9 +543,9 @@
484 543 {
485 544 $destinationBucket = $options['destinationBucket'] ?? $this->identity['bucket'];
486 545 unset($options['destinationBucket']);
487 546 $copiedObject = $this->copy($destinationBucket, ['name' => $name] + $options);
488 - $this->delete(array_intersect_key($options, ['restOptions' => null, 'retries' => null]));
547 + $this->delete(\array_intersect_key($options, ['restOptions' => null, 'retries' => null]));
489 548 $this->info = [];
490 549 return $copiedObject;
491 550 }
492 551 /**
@@ -553,9 +612,9 @@
553 612 */
554 613 public function downloadToFile($path, array $options = [])
555 614 {
556 615 $source = $this->downloadAsStream($options);
557 - $destination = Utils::streamFor(fopen($path, 'w'));
616 + $destination = Utils::streamFor(\fopen($path, 'w'));
558 617 Utils::copyToStream($source, $destination);
559 618 $destination->seek(0);
560 619 return $destination;
561 620 }
@@ -609,9 +668,9 @@
609 668 * @return StreamInterface
610 669 */
611 670 public function downloadAsStream(array $options = [])
612 671 {
613 - return $this->connection->downloadObject($this->formatEncryptionHeaders($options + $this->encryptionData + array_filter($this->identity)));
672 + return $this->connection->downloadObject($this->formatEncryptionHeaders($options + $this->encryptionData + \array_filter($this->identity)));
614 673 }
615 674 /**
616 675 * Asynchronously download an object as a stream.
617 676 *
@@ -670,9 +729,9 @@
670 729 * upgrading.
671 730 */
672 731 public function downloadAsStreamAsync(array $options = [])
673 732 {
674 - return $this->connection->downloadObjectAsync($this->formatEncryptionHeaders($options + $this->encryptionData + array_filter($this->identity)));
733 + return $this->connection->downloadObjectAsync($this->formatEncryptionHeaders($options + $this->encryptionData + \array_filter($this->identity)));
675 734 }
676 735 /**
677 736 * Create a Signed URL for this object.
678 737 *
@@ -765,13 +824,52 @@
765 824 * multiple spaces within values will be collapsed to a single
766 825 * space, and line breaks will be replaced by an empty string.
767 826 * V2 Signed URLs may not provide `x-goog-encryption-key` or
768 827 * `x-goog-encryption-key-sha256` headers.
769 - * @type array $keyFile Keyfile data to use in place of the keyfile with
770 - * which the client was constructed. If `$options.keyFilePath` is
771 - * set, this option is ignored.
772 - * @type string $keyFilePath A path to a valid Keyfile to use in place
773 - * of the keyfile with which the client was constructed.
828 + * @type FetchAuthTokenInterface $credentialsFetcher A credentials
829 + * fetcher instance.
830 + * @type array $keyFile [DEPRECATED]
831 + * This option is being deprecated because of a potential security risk.
832 + * This option does not validate the credential configuration. The security
833 + * risk occurs when a credential configuration is accepted from a source
834 + * that is not under your control and used without validation on your side.
835 + * If you know that you will be loading credential configurations of a
836 + * specific type, it is recommended to create the credentials directly and
837 + * configure them using the `credentialsFetcher` option instead.
838 + * ```
839 + * use Google\Auth\Credentials\ServiceAccountCredentials;
840 + * $credentialsFetcher = new ServiceAccountCredentials($scopes, $json);
841 + * ```
842 + * This will ensure that an unexpected credential type with potential for
843 + * malicious intent is not loaded unintentionally. You might still have to do
844 + * validation for certain credential types.
845 + * If you are loading your credential configuration from an untrusted source and have
846 + * not mitigated the risks (e.g. by validating the configuration yourself), make
847 + * these changes as soon as possible to prevent security risks to your environment.
848 + * Regardless of the method used, it is always your responsibility to validate
849 + * configurations received from external sources.
850 + * @see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials
851 + * @type string $keyFilePath [DEPRECATED]
852 + * This option is being deprecated because of a potential security risk.
853 + * This option does not validate the credential configuration. The security
854 + * risk occurs when a credential configuration is accepted from a source
855 + * that is not under your control and used without validation on your side.
856 + * If you know that you will be loading credential configurations of a
857 + * specific type, it is recommended to create the credentials directly and
858 + * configure them using the `credentialsFetcher` option instead.
859 + * ```
860 + * use Google\Auth\Credentials\ServiceAccountCredentials;
861 + * $credentialsFetcher = new ServiceAccountCredentials($scopes, $json);
862 + * ```
863 + * This will ensure that an unexpected credential type with potential for
864 + * malicious intent is not loaded unintentionally. You might still have to do
865 + * validation for certain credential types.
866 + * If you are loading your credential configuration from an untrusted source and have
867 + * not mitigated the risks (e.g. by validating the configuration yourself), make
868 + * these changes as soon as possible to prevent security risks to your environment.
869 + * Regardless of the method used, it is always your responsibility to validate
870 + * configurations received from external sources.
871 + * @see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials
774 872 * @type string $method One of `GET`, `PUT` or `DELETE`.
775 873 * **Defaults to** `GET`.
776 874 * @type string $responseDisposition The
777 875 * [`response-content-disposition`](http://www.iana.org/assignments/cont-disp/cont-disp.xhtml)
@@ -808,9 +906,9 @@
808 906 public function signedUrl($expires, array $options = [])
809 907 {
810 908 // May be overridden for testing.
811 909 $signingHelper = $this->pluck('helper', $options, \false) ?: SigningHelper::getHelper();
812 - $resource = sprintf('/%s/%s', $this->identity['bucket'], $this->identity['object']);
910 + $resource = \sprintf('/%s/%s', $this->identity['bucket'], $this->identity['object']);
813 911 return $signingHelper->sign($this->connection, $expires, $resource, $this->identity['generation'], $options);
814 912 }
815 913 /**
816 914 * Create a Signed Upload URL for this object.
@@ -869,13 +967,52 @@
869 967 * multiple spaces within values will be collapsed to a single
870 968 * space, and line breaks will be replaced by an empty string.
871 969 * V2 Signed URLs may not provide `x-goog-encryption-key` or
872 970 * `x-goog-encryption-key-sha256` headers.
873 - * @type array $keyFile Keyfile data to use in place of the keyfile with
874 - * which the client was constructed. If `$options.keyFilePath` is
875 - * set, this option is ignored.
876 - * @type string $keyFilePath A path to a valid Keyfile to use in place
877 - * of the keyfile with which the client was constructed.
971 + * @type FetchAuthTokenInterface $credentialsFetcher A credentials
972 + * fetcher instance.
973 + * @type array $keyFile [DEPRECATED]
974 + * This option is being deprecated because of a potential security risk.
975 + * This option does not validate the credential configuration. The security
976 + * risk occurs when a credential configuration is accepted from a source
977 + * that is not under your control and used without validation on your side.
978 + * If you know that you will be loading credential configurations of a
979 + * specific type, it is recommended to create the credentials directly and
980 + * configure them using the `credentialsFetcher` option instead.
981 + * ```
982 + * use Google\Auth\Credentials\ServiceAccountCredentials;
983 + * $credentialsFetcher = new ServiceAccountCredentials($scopes, $json);
984 + * ```
985 + * This will ensure that an unexpected credential type with potential for
986 + * malicious intent is not loaded unintentionally. You might still have to do
987 + * validation for certain credential types.
988 + * If you are loading your credential configuration from an untrusted source and have
989 + * not mitigated the risks (e.g. by validating the configuration yourself), make
990 + * these changes as soon as possible to prevent security risks to your environment.
991 + * Regardless of the method used, it is always your responsibility to validate
992 + * configurations received from external sources.
993 + * @see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials
994 + * @type string $keyFilePath [DEPRECATED]
995 + * This option is being deprecated because of a potential security risk.
996 + * This option does not validate the credential configuration. The security
997 + * risk occurs when a credential configuration is accepted from a source
998 + * that is not under your control and used without validation on your side.
999 + * If you know that you will be loading credential configurations of a
1000 + * specific type, it is recommended to create the credentials directly and
1001 + * configure them using the `credentialsFetcher` option instead.
1002 + * ```
1003 + * use Google\Auth\Credentials\ServiceAccountCredentials;
1004 + * $credentialsFetcher = new ServiceAccountCredentials($scopes, $json);
1005 + * ```
1006 + * This will ensure that an unexpected credential type with potential for
1007 + * malicious intent is not loaded unintentionally. You might still have to do
1008 + * validation for certain credential types.
1009 + * If you are loading your credential configuration from an untrusted source and have
1010 + * not mitigated the risks (e.g. by validating the configuration yourself), make
1011 + * these changes as soon as possible to prevent security risks to your environment.
1012 + * Regardless of the method used, it is always your responsibility to validate
1013 + * configurations received from external sources.
1014 + * @see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials
878 1015 * @type string $responseDisposition The
879 1016 * [`response-content-disposition`](http://www.iana.org/assignments/cont-disp/cont-disp.xhtml)
880 1017 * parameter of the signed url.
881 1018 * @type string $responseType The `response-content-type` parameter of the
@@ -952,14 +1089,52 @@
952 1089 * multiple spaces within values will be collapsed to a single
953 1090 * space, and line breaks will be replaced by an empty string.
954 1091 * V2 Signed URLs may not provide `x-goog-encryption-key` or
955 1092 * `x-goog-encryption-key-sha256` headers.
956 - * @type array $keyFile Keyfile data to use in place of the keyfile with
957 - * which the client was constructed. If `$options.keyFilePath` is
958 - * set, this option is ignored.
959 - * @type string $keyFilePath A path to a valid Keyfile to use in place
960 - * of the keyfile with which the client was constructed.
961 - * @type string $origin Value of CORS header
1093 + * @type FetchAuthTokenInterface $credentialsFetcher A credentials
1094 + * fetcher instance.
1095 + * @type array $keyFile [DEPRECATED]
1096 + * This option is being deprecated because of a potential security risk.
1097 + * This option does not validate the credential configuration. The security
1098 + * risk occurs when a credential configuration is accepted from a source
1099 + * that is not under your control and used without validation on your side.
1100 + * If you know that you will be loading credential configurations of a
1101 + * specific type, it is recommended to create the credentials directly and
1102 + * configure them using the `credentialsFetcher` option instead.
1103 + * ```
1104 + * use Google\Auth\Credentials\ServiceAccountCredentials;
1105 + * $credentialsFetcher = new ServiceAccountCredentials($scopes, $json);
1106 + * ```
1107 + * This will ensure that an unexpected credential type with potential for
1108 + * malicious intent is not loaded unintentionally. You might still have to do
1109 + * validation for certain credential types.
1110 + * If you are loading your credential configuration from an untrusted source and have
1111 + * not mitigated the risks (e.g. by validating the configuration yourself), make
1112 + * these changes as soon as possible to prevent security risks to your environment.
1113 + * Regardless of the method used, it is always your responsibility to validate
1114 + * configurations received from external sources.
1115 + * @see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials
1116 + * @type string $keyFilePath [DEPRECATED]
1117 + * This option is being deprecated because of a potential security risk.
1118 + * This option does not validate the credential configuration. The security
1119 + * risk occurs when a credential configuration is accepted from a source
1120 + * that is not under your control and used without validation on your side.
1121 + * If you know that you will be loading credential configurations of a
1122 + * specific type, it is recommended to create the credentials directly and
1123 + * configure them using the `credentialsFetcher` option instead.
1124 + * ```
1125 + * use Google\Auth\Credentials\ServiceAccountCredentials;
1126 + * $credentialsFetcher = new ServiceAccountCredentials($scopes, $json);
1127 + * ```
1128 + * This will ensure that an unexpected credential type with potential for
1129 + * malicious intent is not loaded unintentionally. You might still have to do
1130 + * validation for certain credential types.
1131 + * If you are loading your credential configuration from an untrusted source and have
1132 + * not mitigated the risks (e.g. by validating the configuration yourself), make
1133 + * these changes as soon as possible to prevent security risks to your environment.
1134 + * Regardless of the method used, it is always your responsibility to validate
1135 + * configurations received from external sources.
1136 + * @see https://cloud.google.com/docs/authentication/external/externally-sourced-credentials
962 1137 * "Access-Control-Allow-Origin". **Defaults to** `"*"`.
963 1138 * @type string|array $scopes One or more authentication scopes to be
964 1139 * used with a key file. This option is ignored unless
965 1140 * `$options.keyFile` or `$options.keyFilePath` is set.
@@ -1068,9 +1243,9 @@
1068 1243 * @return array
1069 1244 */
1070 1245 public function reload(array $options = [])
1071 1246 {
1072 - return $this->info = $this->connection->getObject($this->formatEncryptionHeaders($options + $this->encryptionData + array_filter($this->identity)));
1247 + return $this->info = $this->connection->getObject($this->formatEncryptionHeaders($options + $this->encryptionData + \array_filter($this->identity)));
1073 1248 }
1074 1249 /**
1075 1250 * Retrieves the object's name.
1076 1251 *
@@ -1111,9 +1286,9 @@
1111 1286 * @return string
1112 1287 */
1113 1288 public function gcsUri()
1114 1289 {
1115 - return sprintf('gs://%s/%s', $this->identity['bucket'], $this->identity['object']);
1290 + return \sprintf('gs://%s/%s', $this->identity['bucket'], $this->identity['object']);
1116 1291 }
1117 1292 /**
1118 1293 * Formats a destination based request, such as copy or rewrite.
1119 1294 *
@@ -1122,9 +1297,9 @@
1122 1297 * @return array
1123 1298 */
1124 1299 private function formatDestinationRequest($destination, array $options)
1125 1300 {
1126 - if (!is_string($destination) && !$destination instanceof Bucket) {
1301 + if (!\is_string($destination) && !$destination instanceof Bucket) {
1127 1302 throw new \InvalidArgumentException('$destination must be either a string or an instance of Bucket.');
1128 1303 }
1129 1304 $destAcl = $options['predefinedAcl'] ?? null;
1130 1305 $destObject = $options['name'] ?? $this->identity['object'];
@@ -1129,7 +1304,7 @@
1129 1304 $destAcl = $options['predefinedAcl'] ?? null;
1130 1305 $destObject = $options['name'] ?? $this->identity['object'];
1131 1306 unset($options['name']);
1132 1307 unset($options['predefinedAcl']);
1133 - return array_filter(['destinationBucket' => $destination instanceof Bucket ? $destination->name() : $destination, 'destinationObject' => $destObject, 'destinationPredefinedAcl' => $destAcl, 'sourceBucket' => $this->identity['bucket'], 'sourceObject' => $this->identity['object'], 'sourceGeneration' => $this->identity['generation'], 'userProject' => $this->identity['userProject']]) + $this->formatEncryptionHeaders($options + $this->encryptionData);
1308 + return \array_filter(['destinationBucket' => $destination instanceof Bucket ? $destination->name() : $destination, 'destinationObject' => $destObject, 'destinationPredefinedAcl' => $destAcl, 'sourceBucket' => $this->identity['bucket'], 'sourceObject' => $this->identity['object'], 'sourceGeneration' => $this->identity['generation'], 'userProject' => $this->identity['userProject']]) + $this->formatEncryptionHeaders($options + $this->encryptionData);
1134 1309 }
1135 1310 }