Пример #1
0
 private function memberKey(Shape $shape, $name)
 {
     if ($shape instanceof ListShape && $shape['flattened']) {
         return $shape->getMember()['locationName'] ?: $name;
     }
     return $shape['locationName'] ?: $name;
 }
Пример #2
0
 private function format(Shape $shape, $value)
 {
     switch ($shape['type']) {
         case 'structure':
             $data = [];
             foreach ($value as $k => $v) {
                 if ($v !== null && $shape->hasMember($k)) {
                     $data[$shape['locationName'] ?: $k] = $this->format($shape->getMember($k), $v);
                 }
             }
             return $data;
         case 'list':
             $items = $shape->getMember();
             foreach ($value as &$v) {
                 $v = $this->format($items, $v);
             }
             return $value;
         case 'map':
             if (empty($value)) {
                 return new \stdClass();
             }
             $values = $shape->getValue();
             foreach ($value as &$v) {
                 $v = $this->format($values, $v);
             }
             return $value;
         case 'blob':
             return base64_encode($value);
         case 'timestamp':
             return TimestampShape::format($value, 'unixTimestamp');
         default:
             return $value;
     }
 }
Пример #3
0
 public function parse(Shape $shape, $value)
 {
     switch ($shape['type']) {
         case 'structure':
             $target = [];
             foreach ($shape->getMembers() as $name => $member) {
                 $name = $member['locationName'] ?: $name;
                 if (isset($value[$name])) {
                     $target[$name] = $this->parse($member, $value[$name]);
                 }
             }
             return $target;
         case 'list':
             $member = $shape->getMember();
             $target = [];
             foreach ($value as $v) {
                 $target[] = $this->parse($member, $v);
             }
             return $target;
         case 'map':
             $values = $shape->getValue();
             $target = [];
             foreach ($value as $k => $v) {
                 $target[$k] = $this->parse($values, $v);
             }
             return $target;
         case 'blob':
             return base64_decode($value);
         default:
             return $value;
     }
 }
Пример #4
0
 /**
  * Extract a single header from the response into the result.
  */
 private function extractHeader($name, Shape $shape, ResponseInterface $response, &$result)
 {
     $value = $response->getHeaderLine($shape['locationName'] ?: $name);
     switch ($shape->getType()) {
         case 'float':
         case 'double':
             $value = (double) $value;
             break;
         case 'long':
             $value = (int) $value;
             break;
         case 'boolean':
             $value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
             break;
         case 'blob':
             $value = base64_decode($value);
             break;
         case 'timestamp':
             try {
                 $value = new DateTimeResult($value);
                 break;
             } catch (\Exception $e) {
                 // If the value cannot be parsed, then do not add it to the
                 // output structure.
                 return;
             }
     }
     $result[$name] = $value;
 }
Пример #5
0
 private function dispatch(Shape $shape, $value)
 {
     static $methods = ['structure' => 'check_structure', 'list' => 'check_list', 'map' => 'check_map', 'blob' => 'check_blob', 'boolean' => 'check_boolean', 'integer' => 'check_numeric', 'float' => 'check_numeric', 'long' => 'check_numeric', 'string' => 'check_string', 'byte' => 'check_string', 'char' => 'check_string'];
     $type = $shape->getType();
     if (isset($methods[$type])) {
         $this->{$methods[$type]}($shape, $value);
     }
 }
 /**
  * Extract a single header from the response into the result.
  */
 private function extractHeader($name, Shape $shape, ResponseInterface $response, &$result)
 {
     $value = $response->getHeaderLine($shape['locationName'] ?: $name);
     $type = $shape->getType();
     if ($type === 'blob') {
         $value = base64_decode($value);
     } elseif ($type === 'timestamp') {
         try {
             $value = new DateTimeResult($value);
         } catch (\Exception $e) {
             // If the value cannot be parsed, then do not add it to the
             // output structure.
             return;
         }
     }
     $result[$name] = $value;
 }
Пример #7
0
 public function parse(Shape $shape, $value)
 {
     if ($value === null) {
         return $value;
     }
     switch ($shape['type']) {
         case 'structure':
             $target = [];
             foreach ($shape->getMembers() as $name => $member) {
                 $locationName = $member['locationName'] ?: $name;
                 if (isset($value[$locationName])) {
                     $target[$name] = $this->parse($member, $value[$locationName]);
                 }
             }
             return $target;
         case 'list':
             $member = $shape->getMember();
             $target = [];
             foreach ($value as $v) {
                 $target[] = $this->parse($member, $v);
             }
             return $target;
         case 'map':
             $values = $shape->getValue();
             $target = [];
             foreach ($value as $k => $v) {
                 $target[$k] = $this->parse($values, $v);
             }
             return $target;
         case 'timestamp':
             // The Unix epoch (or Unix time or POSIX time or Unix
             // timestamp) is the number of seconds that have elapsed since
             // January 1, 1970 (midnight UTC/GMT).
             return DateTimeResult::fromEpoch($value);
         case 'blob':
             return base64_decode($value);
         default:
             return $value;
     }
 }
 private function applyQuery($name, Shape $member, $value, array &$opts)
 {
     if ($member instanceof MapShape) {
         $opts['query'] = isset($opts['query']) && is_array($opts['query']) ? $opts['query'] + $value : $value;
     } elseif ($value !== null) {
         if ($member->getType() === 'boolean') {
             $value = $value ? 'true' : 'false';
         }
         $opts['query'][$member['locationName'] ?: $name] = $value;
     }
 }
Пример #9
0
 private function applyHeader(RequestInterface $request, $name, Shape $member, $value)
 {
     if ($member->getType() == 'timestamp') {
         $value = TimestampShape::format($value, 'rfc822');
     }
     $request->setHeader($member['locationName'] ?: $name, $value);
 }
Пример #10
0
 protected function shapeFor(array $definition)
 {
     return isset($definition['shape']) ? $this->shapeMap->resolve($definition) : Shape::create($definition, $this->shapeMap);
 }
Пример #11
0
 private function applyHeader($name, Shape $member, $value, array &$opts)
 {
     if ($member->getType() == 'timestamp') {
         $value = TimestampShape::format($value, 'rfc822');
     }
     $opts['headers'][$member['locationName'] ?: $name] = $value;
 }