/**
  * Custom handling for objects
  *
  * @param Parameter $param  Parameter for the object
  * @param array     $value  Value that is set for this parameter
  * @param string    $prefix Prefix for the resulting key
  * @param array     $query  Query string array passed by reference
  */
 protected function resolveObject(Parameter $param, array $value, $prefix, array &$query)
 {
     // Maps are implemented using additional properties
     $hasAdditionalProperties = $param->getAdditionalProperties() instanceof Parameter;
     $additionalPropertyCount = 0;
     foreach ($value as $name => $v) {
         if ($subParam = $param->getProperty($name)) {
             // if the parameter was found by name as a regular property
             $key = $prefix . '.' . $subParam->getWireName();
             $this->customResolver($v, $subParam, $query, $key);
         } elseif ($hasAdditionalProperties) {
             // Handle map cases like &Attribute.1.Name=<name>&Attribute.1.Value=<value>
             $additionalPropertyCount++;
             $data = $param->getData();
             $keyName = isset($data['keyName']) ? $data['keyName'] : 'key';
             $valueName = isset($data['valueName']) ? $data['valueName'] : 'value';
             $query["{$prefix}.{$additionalPropertyCount}.{$keyName}"] = $name;
             $newPrefix = "{$prefix}.{$additionalPropertyCount}.{$valueName}";
             if (is_array($v)) {
                 $this->customResolver($v, $param->getAdditionalProperties(), $query, $newPrefix);
             } else {
                 $query[$newPrefix] = $param->filter($v);
             }
         }
     }
 }
 /**
  * Map nested parameters into the location_key based parameters
  *
  * @param array     $value Value to map
  * @param Parameter $param Parameter that holds information about 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);
 }
Esempio n. 3
0
 /**
  * Add an object to the XML
  */
 protected function addXmlObject(\XMLWriter $xmlWriter, Parameter $param, &$value)
 {
     $noAttributes = array();
     // add values which have attributes
     foreach ($value as $name => $v) {
         if ($property = $param->getProperty($name)) {
             if ($property->getData('xmlAttribute')) {
                 $this->addXml($xmlWriter, $property, $v);
             } else {
                 $noAttributes[] = array('value' => $v, 'property' => $property);
             }
         }
     }
     // now add values with no attributes
     foreach ($noAttributes as $element) {
         $this->addXml($xmlWriter, $element['property'], $element['value']);
     }
 }
Esempio n. 4
0
 protected function visitAdditionalProperties(Parameter $model, CommandInterface $command, Response $response, Parameter $additional, &$result, array &$foundVisitors)
 {
     // Only visit when a location is specified
     if ($location = $additional->getLocation()) {
         if (!isset($foundVisitors[$location])) {
             $foundVisitors[$location] = $this->factory->getResponseVisitor($location);
             $foundVisitors[$location]->before($command, $result);
         }
         // Only traverse if an array was parsed from the before() visitors
         if (is_array($result)) {
             // Find each additional property
             foreach (array_keys($result) as $key) {
                 // Check if the model actually knows this property. If so, then it is not additional
                 if (!$model->getProperty($key)) {
                     // Set the name to the key so that we can parse it with each visitor
                     $additional->setName($key);
                     $foundVisitors[$location]->visit($command, $response, $additional, $result);
                 }
             }
             // Reset the additionalProperties name to null
             $additional->setName(null);
         }
     }
 }