Ejemplo n.º 1
0
 protected function addXml(\XMLWriter $xmlWriter, Parameter $param, $value)
 {
     if ($value === null) {
         return;
     }
     $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')) {
             $xmlWriter->startElementNS(null, $name, $namespace);
         }
         if ($param->getType() == 'array') {
             $this->addXmlArray($xmlWriter, $param, $value);
         } elseif ($param->getType() == 'object') {
             $this->addXmlObject($xmlWriter, $param, $value);
         }
         if (!$param->getData('xmlFlattened')) {
             $xmlWriter->endElement();
         }
         return;
     }
     if ($param->getData('xmlAttribute')) {
         $this->writeAttribute($xmlWriter, $prefix, $name, $namespace, $value);
     } else {
         $this->writeElement($xmlWriter, $prefix, $name, $namespace, $value);
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
 {
     if ($value instanceof PostFileInterface) {
         $request->addPostFile($value);
     } else {
         $request->addPostFile($param->getWireName(), $value);
     }
 }
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
 {
     if (isset($this->data[$command])) {
         $json = $this->data[$command];
     } else {
         $json = array();
     }
     $json[$param->getWireName()] = $this->prepareValue($value, $param);
     $this->data[$command] = $json;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, Response $response, Parameter $param, &$value, $context = null)
 {
     // check if there's a link provided for the param's "wire" name
     $links = $this->get($command, 'links');
     if (!empty($links[$param->getWireName()])) {
         // create a command representing the link
         $linkCommand = $this->builder->createLinkCommand($command, $param, $links[$param->getWireName()]);
         // store the created link command in the results array
         $value[self::ELEMENT][$param->getName()] = $linkCommand;
     }
 }
Ejemplo n.º 5
0
 protected function processXmlAttribute(Parameter $property, array &$value)
 {
     $sentAs = $property->getWireName();
     if (isset($value['@attributes'][$sentAs])) {
         $value[$property->getName()] = $value['@attributes'][$sentAs];
         unset($value['@attributes'][$sentAs]);
         if (empty($value['@attributes'])) {
             unset($value['@attributes']);
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, Response $response, Parameter $param, &$value, $context = null)
 {
     // check if there's embedded resource data for the parameter
     $resourceData = $this->get($command, $this->getFieldName());
     if (!empty($resourceData[$param->getWireName()])) {
         // create the resource representing the embedded resource data
         $resource = $this->createResourceFromData($command, $param, $resourceData[$param->getWireName()]);
         // store the created embedded resource in the results array
         $value[$this->getOutputFieldName()][$param->getName()] = $resource;
     }
 }
Ejemplo n.º 7
0
 public function visit(CommandInterface $command, Response $response, Parameter $param, &$value, $context = null)
 {
     $name = $param->getName();
     $key = $param->getWireName();
     if (isset($value[$key])) {
         $this->recursiveProcess($param, $value[$key]);
         if ($key != $name) {
             $value[$name] = $value[$key];
             unset($value[$key]);
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, Response $response, Parameter $param, &$value, $context = null)
 {
     // check if there's an embedded resource for the parameter's
     // "wire" name
     $resources = $this->get($command, 'embedded');
     if (!empty($resources[$param->getWireName()])) {
         // create a model representing the embedded resource data
         $embeddedModel = $this->builder->createEmbeddedModel($command, $param, $resources[$param->getWireName()]);
         // store the created embedded model in the results array
         $value[self::ELEMENT][$param->getName()] = $embeddedModel;
     }
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, Response $response, Parameter $param, &$value, $context = null)
 {
     $sentAs = $param->getWireName();
     $name = $param->getName();
     if (isset($value[$sentAs])) {
         $this->recursiveProcess($param, $value[$sentAs]);
         if ($name != $sentAs) {
             $value[$name] = $value[$sentAs];
             unset($value[$sentAs]);
         }
     } elseif ($param->getType() == 'array') {
         // Use a default array when the value is missing
         $value[$name] = array();
     } elseif ($param->getType() == 'boolean') {
         // Use a default value of false when the value is missing
         $value[$name] = false;
     }
 }
Ejemplo n.º 10
0
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
 {
     $request->getQuery()->set($param->getWireName(), $this->prepareValue($value, $param));
 }
Ejemplo n.º 11
0
 public function testHasKeyMethod()
 {
     $p = new Parameter(array('name' => 'foo', 'sentAs' => 'bar'));
     $this->assertEquals('bar', $p->getWireName());
     $p->setSentAs(null);
     $this->assertEquals('foo', $p->getWireName());
 }
 /**
  * Recursively build the XML body
  *
  * @param \SimpleXMLElement $xml   XML to modify
  * @param Parameter         $param API Parameter
  * @param mixed             $value Value to add
  */
 protected function addXml(\SimpleXMLElement $xml, Parameter $param, $value)
 {
     if ($value === null) {
         return;
     }
     $value = $param->filter($value);
     $type = $param->getType();
     if ($type == 'object' || $type == 'array') {
         $ele = $param->getData('xmlFlattened') ? $xml : $xml->addChild($param->getWireName());
         if ($param->getType() == 'array') {
             $this->addXmlArray($ele, $param, $value, $param->getData('xmlNamespace'));
         } elseif ($param->getType() == 'object') {
             $this->addXmlObject($ele, $param, $value);
         }
     } elseif ($param->getData('xmlAttribute')) {
         $xml->addAttribute($param->getWireName(), $value, $param->getData('xmlNamespace'));
     } else {
         $xml->addChild($param->getWireName(), $value, $param->getData('xmlNamespace'));
     }
 }
Ejemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
 {
     $json = isset($this->data[$command]) ? $this->data[$command] : array();
     $json[$param->getWireName()] = $param && is_array($value) ? $this->resolveRecursively($value, $param) : $value;
     $this->data[$command] = $json;
 }
Ejemplo n.º 14
0
 /**
  * Recursively build the XML body
  *
  * @param \SimpleXMLElement $xml   XML to modify
  * @param Parameter         $param API Parameter
  * @param mixed             $value Value to add
  */
 protected function addXml(\SimpleXMLElement $xml, Parameter $param, $value)
 {
     // Determine the name of the element
     $node = $param->getWireName();
     // Check if this property has a particular namespace
     $namespace = $param->getData('xmlNamespace');
     // Filter the value
     $value = $param->filter($value);
     if ($param->getType() == 'array') {
         $this->addXmlArray($xml, $param, $value, $namespace);
     } elseif ($param->getType() == 'object') {
         $this->addXmlObject($xml, $param, $value);
     } elseif ($param->getData('xmlAttribute')) {
         $xml->addAttribute($node, $value, $namespace);
     } else {
         $xml->addChild($node, $value, $namespace);
     }
 }
Ejemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
 {
     $request->getQuery()->set($param->getWireName(), $param && is_array($value) ? $this->resolveRecursively($value, $param) : $value);
 }