public function visit(GuzzleCommandInterface $command, ResponseInterface $response, Parameter $param, &$result, array $context = array())
 {
     // Retrieving a single header by name
     $name = $param->getName();
     if ($header = $response->getHeader($param->getWireName())) {
         $result[$name] = $param->filter($header);
     }
 }
 public function visit(GuzzleCommandInterface $command, RequestInterface $request, Parameter $param, array $context)
 {
     $body = $request->getBody();
     if (!$body instanceof PostBodyInterface) {
         throw new \RuntimeException('Must be a POST body interface');
     }
     $value = $param->filter($command[$param->getName()]);
     if (!$value instanceof PostFileInterface) {
         $value = new PostFile($param->getWireName(), $value);
     }
     $body->addFile($value);
 }
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, array $context)
 {
     $name = urlencode($param->formName);
     $value = urlencode($command[$param->getName()]);
     $content = Stream::factory($param->filter($value));
     if ($request->getBody() === null) {
         $request->setBody(Stream::factory(""));
     }
     $queryChar = '&';
     if ($request->getBody()->__toString() == '') {
         $queryChar = '';
     }
     $request->getBody()->write($queryChar . $name . "=" . $content);
 }
 /**
  * Recursively process a parameter while applying filters
  *
  * @param Parameter $param API parameter being validated
  * @param mixed     $value Value to process.
  * @return mixed|null
  */
 private function recurse(Parameter $param, $value)
 {
     if (!is_array($value)) {
         return $param->filter($value);
     }
     $result = [];
     $type = $param->getType();
     if ($type == 'array') {
         $items = $param->getItems();
         foreach ($value as $val) {
             $result[] = $this->recurse($items, $val);
         }
     } elseif ($type == 'object' && !isset($value[0])) {
         // On the above line, we ensure that the array is associative and
         // not numerically indexed
         if ($properties = $param->getProperties()) {
             foreach ($properties as $property) {
                 $key = $property->getWireName();
                 if (array_key_exists($key, $value)) {
                     $result[$property->getName()] = $this->recurse($property, $value[$key]);
                     // Remove from the value so that AP can later be handled
                     unset($value[$key]);
                 }
             }
         }
         // Only check additional properties if everything wasn't already
         // handled
         if ($value) {
             $additional = $param->getAdditionalProperties();
             if ($additional === null || $additional === true) {
                 // Merge the JSON under the resulting array
                 $result += $value;
             } elseif ($additional instanceof Parameter) {
                 // Process all child elements according to the given schema
                 foreach ($value as $prop => $val) {
                     $result[$prop] = $this->recurse($additional, $val);
                 }
             }
         }
     }
     return $param->filter($result);
 }
 /**
  * Recursively prepare and filter nested values.
  *
  * @param array     $value Value to map
  * @param Parameter $param Parameter related to the current key.
  *
  * @return array Returns the mapped array
  */
 protected function resolveRecursively(array $value, Parameter $param)
 {
     foreach ($value as $name => &$v) {
         switch ($param->getType()) {
             case 'object':
                 if ($subParam = $param->getProperty($name)) {
                     $key = $subParam->getWireName();
                     $value[$key] = $this->prepareValue($v, $subParam);
                     if ($name != $key) {
                         unset($value[$name]);
                     }
                 } elseif ($param->getAdditionalProperties() instanceof Parameter) {
                     $v = $this->prepareValue($v, $param->getAdditionalProperties());
                 }
                 break;
             case 'array':
                 if ($items = $param->getItems()) {
                     $v = $this->prepareValue($v, $items);
                 }
                 break;
         }
     }
     return $param->filter($value);
 }
Beispiel #6
0
 public function visit(GuzzleCommandInterface $command, ResponseInterface $response, Parameter $param, &$result, array $context = [])
 {
     $result[$param->getName()] = $param->filter($response->getBody());
 }
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, array $context)
 {
     $value = $command[$param->getName()];
     $request->setBody(Stream::factory($param->filter($value)));
 }
 /**
  * Recursively build the XML body
  *
  * @param \XMLWriter $writer XML to modify
  * @param Parameter  $param     API Parameter
  * @param mixed      $value     Value to add
  */
 protected function addXml(\XMLWriter $writer, Parameter $param, $value)
 {
     $value = $param->filter($value);
     $type = $param->getType();
     $name = $param->getWireName();
     $prefix = null;
     $namespace = $param->getData('xmlNamespace');
     if (false !== strpos($name, ':')) {
         list($prefix, $name) = explode(':', $name, 2);
     }
     if ($type == 'object' || $type == 'array') {
         if (!$param->getData('xmlFlattened')) {
             if ($namespace) {
                 $writer->startElementNS(null, $name, $namespace);
             } else {
                 $writer->startElement($name);
             }
         }
         if ($param->getType() == 'array') {
             $this->addXmlArray($writer, $param, $value);
         } elseif ($param->getType() == 'object') {
             $this->addXmlObject($writer, $param, $value);
         }
         if (!$param->getData('xmlFlattened')) {
             $writer->endElement();
         }
         return;
     }
     if ($param->getData('xmlAttribute')) {
         $this->writeAttribute($writer, $prefix, $name, $namespace, $value);
     } else {
         $this->writeElement($writer, $prefix, $name, $namespace, $value);
     }
 }
Beispiel #9
0
 /**
  * @dataProvider dateTimeProvider
  */
 public function testAppliesFormat($d, $format, $result)
 {
     $p = new Parameter(['format' => $format], ['description' => new Description([])]);
     $this->assertEquals($format, $p->getFormat());
     $this->assertEquals($result, $p->filter($d));
 }
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, array $context)
 {
     $value = $command[$param->getName()];
     $request->setHeader($param->getWireName(), $param->filter($value));
 }