/**
  * 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 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;
     }
 }