PluginProbe
Media Cloud Sync / 1.0.2
Media Cloud Sync v1.0.2
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 / Api / Parser / MetadataParserTrait.php

MetadataParserTrait.php in Media Cloud Sync 1.0.2, at includes/sdk/s3/Aws/Api/Parser/MetadataParserTrait.php

72 lines 2.5 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\Api\Parser;
4
5 use Dudlewebs\WPMCS\s3\Aws\Api\DateTimeResult;
6 use Dudlewebs\WPMCS\s3\Aws\Api\Shape;
7 use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface;
8 trait MetadataParserTrait
9 {
10 /**
11 * Extract a single header from the response into the result.
12 */
13 protected function extractHeader($name, Shape $shape, ResponseInterface $response, &$result)
14 {
15 $value = $response->getHeaderLine($shape['locationName'] ?: $name);
16 switch ($shape->getType()) {
17 case 'float':
18 case 'double':
19 $value = (float) $value;
20 break;
21 case 'long':
22 $value = (int) $value;
23 break;
24 case 'boolean':
25 $value = \filter_var($value, \FILTER_VALIDATE_BOOLEAN);
26 break;
27 case 'blob':
28 $value = \base64_decode($value);
29 break;
30 case 'timestamp':
31 try {
32 $value = DateTimeResult::fromTimestamp($value, !empty($shape['timestampFormat']) ? $shape['timestampFormat'] : null);
33 break;
34 } catch (\Exception $e) {
35 // If the value cannot be parsed, then do not add it to the
36 // output structure.
37 return;
38 }
39 case 'string':
40 if ($shape['jsonvalue']) {
41 $value = $this->parseJson(\base64_decode($value), $response);
42 }
43 break;
44 }
45 $result[$name] = $value;
46 }
47 /**
48 * Extract a map of headers with an optional prefix from the response.
49 */
50 protected function extractHeaders($name, Shape $shape, ResponseInterface $response, &$result)
51 {
52 // Check if the headers are prefixed by a location name
53 $result[$name] = [];
54 $prefix = $shape['locationName'];
55 $prefixLen = \strlen($prefix);
56 foreach ($response->getHeaders() as $k => $values) {
57 if (!$prefixLen) {
58 $result[$name][$k] = \implode(', ', $values);
59 } elseif (\stripos($k, $prefix) === 0) {
60 $result[$name][\substr($k, $prefixLen)] = \implode(', ', $values);
61 }
62 }
63 }
64 /**
65 * Places the status code of the response into the result array.
66 */
67 protected function extractStatus($name, ResponseInterface $response, array &$result)
68 {
69 $result[$name] = (int) $response->getStatusCode();
70 }
71 }
72