PluginProbe
Media Cloud Sync / 1.2.9
Media Cloud Sync v1.2.9
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 / TimestampShape.php

TimestampShape.php in Media Cloud Sync 1.2.9, at includes/sdk/s3/Aws/Api/TimestampShape.php

46 lines 1.4 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;
4
5 /**
6 * Represents a timestamp shape.
7 */
8 class TimestampShape extends Shape
9 {
10 public function __construct(array $definition, ShapeMap $shapeMap)
11 {
12 $definition['type'] = 'timestamp';
13 parent::__construct($definition, $shapeMap);
14 }
15 /**
16 * Formats a timestamp value for a service.
17 *
18 * @param mixed $value Value to format
19 * @param string $format Format used to serialize the value
20 *
21 * @return int|string
22 * @throws \UnexpectedValueException if the format is unknown.
23 * @throws \InvalidArgumentException if the value is an unsupported type.
24 */
25 public static function format($value, $format)
26 {
27 if ($value instanceof \DateTime) {
28 $value = $value->getTimestamp();
29 } elseif (\is_string($value)) {
30 $value = \strtotime($value);
31 } elseif (!\is_int($value)) {
32 throw new \InvalidArgumentException('Unable to handle the provided' . ' timestamp type: ' . \gettype($value));
33 }
34 switch ($format) {
35 case 'iso8601':
36 return \gmdate('Y-m-d\\TH:i:s\\Z', $value);
37 case 'rfc822':
38 return \gmdate('D, d M Y H:i:s \\G\\M\\T', $value);
39 case 'unixTimestamp':
40 return $value;
41 default:
42 throw new \UnexpectedValueException('Unknown timestamp format: ' . $format);
43 }
44 }
45 }
46