/**
  * 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;
 }
Exemplo n.º 2
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);
     }
 }
Exemplo n.º 3
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;
 }