/** * 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); }
/** * Add an object to the XML */ protected function addXmlObject(\XMLWriter $writer, 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($writer, $property, $v); } else { $noAttributes[] = array('value' => $v, 'property' => $property); } } } // now add values with no attributes foreach ($noAttributes as $element) { $this->addXml($writer, $element['property'], $element['value']); } }
public function testHasProperties() { $data = ['type' => 'object', 'properties' => ['foo' => ['type' => 'string'], 'bar' => ['type' => 'string']]]; $p = new Parameter($data); $this->assertInstanceOf('GuzzleHttp\\Command\\Guzzle\\Parameter', $p->getProperty('foo')); $this->assertSame($p->getProperty('foo'), $p->getProperty('foo')); $this->assertNull($p->getProperty('wefwe')); $properties = $p->getProperties(); $this->assertInternalType('array', $properties); foreach ($properties as $prop) { $this->assertInstanceOf('GuzzleHttp\\Command\\Guzzle\\Parameter', $prop); } $this->assertEquals($data, $p->toArray()); }