ErrorParser
11 months ago
Parser
11 months ago
Serializer
11 months ago
AbstractModel.php
11 months ago
ApiProvider.php
11 months ago
DateTimeResult.php
11 months ago
DocModel.php
11 months ago
ListShape.php
11 months ago
MapShape.php
11 months ago
Operation.php
11 months ago
Service.php
11 months ago
Shape.php
11 months ago
ShapeMap.php
11 months ago
StructureShape.php
11 months ago
TimestampShape.php
11 months ago
Validator.php
11 months ago
TimestampShape.php
49 lines
| 1 | <?php |
| 2 | namespace Aws\Api; |
| 3 | |
| 4 | /** |
| 5 | * Represents a timestamp shape. |
| 6 | */ |
| 7 | class TimestampShape extends Shape |
| 8 | { |
| 9 | public function __construct(array $definition, ShapeMap $shapeMap) |
| 10 | { |
| 11 | $definition['type'] = 'timestamp'; |
| 12 | parent::__construct($definition, $shapeMap); |
| 13 | } |
| 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 \DateTimeInterface) { |
| 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' |
| 33 | . ' timestamp type: ' . gettype($value)); |
| 34 | } |
| 35 | |
| 36 | switch ($format) { |
| 37 | case 'iso8601': |
| 38 | return gmdate('Y-m-d\TH:i:s\Z', $value); |
| 39 | case 'rfc822': |
| 40 | return gmdate('D, d M Y H:i:s \G\M\T', $value); |
| 41 | case 'unixTimestamp': |
| 42 | return $value; |
| 43 | default: |
| 44 | throw new \UnexpectedValueException('Unknown timestamp format: ' |
| 45 | . $format); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 |