protected function createRootElement(Operation $operation) { static $defaultRoot = array('name' => 'Request'); $root = $operation->getData('xmlRoot') ?: $defaultRoot; $encoding = $operation->getData('xmlEncoding'); $xmlWriter = $this->startDocument($encoding); $xmlWriter->startElement($root['name']); if (!empty($root['namespaces'])) { foreach ((array) $root['namespaces'] as $prefix => $uri) { $nsLabel = 'xmlns'; if (!is_numeric($prefix)) { $nsLabel .= ':' . $prefix; } $xmlWriter->writeAttribute($nsLabel, $uri); } } return $xmlWriter; }
/** * Create the root XML element to use with a request * * @param Operation $operation Operation object * * @return \XMLWriter */ protected function createRootElement(Operation $operation) { static $defaultRoot = array('name' => 'Request'); // If no root element was specified, then just wrap the XML in 'Request' $root = $operation->getData('xmlRoot') ?: $defaultRoot; // Allow the XML declaration to be customized with xmlEncoding $encoding = $operation->getData('xmlEncoding'); $xmlWriter = $this->startDocument($encoding); $xmlWriter->startElement($root['name']); // Create the wrapping element with no namespaces if no namespaces were present if (!empty($root['namespaces'])) { // Create the wrapping element with an array of one or more namespaces foreach ((array) $root['namespaces'] as $prefix => $uri) { $nsLabel = 'xmlns'; if (!is_numeric($prefix)) { $nsLabel .= ':' . $prefix; } $xmlWriter->writeAttribute($nsLabel, $uri); } } return $xmlWriter; }
/** * Create the root XML element to use with a request * * @param Operation $operation Operation object * * @return \SimpleXMLElement */ protected function createRootElement(Operation $operation) { static $defaultRoot = array('name' => 'Request'); // If no root element was specified, then just wrap the XML in 'Request' $root = $operation->getData('xmlRoot') ?: $defaultRoot; // Allow the XML declaration to be customized with xmlEncoding $declaration = '<?xml version="1.0"'; if ($encoding = $operation->getData('xmlEncoding')) { $declaration .= ' encoding="' . $encoding . '"'; } $declaration .= "?>"; // Create the wrapping element with no namespaces if no namespaces were present if (empty($root['namespaces'])) { return new \SimpleXMLElement("{$declaration}\n<{$root['name']}/>"); } else { // Create the wrapping element with an array of one or more namespaces $xml = "{$declaration}\n<{$root['name']} "; foreach ((array) $root['namespaces'] as $prefix => $uri) { $xml .= is_numeric($prefix) ? "xmlns=\"{$uri}\" " : "xmlns:{$prefix}=\"{$uri}\" "; } return new \SimpleXMLElement($xml . "/>"); } }
/** * Create the root XML element to use with a request * * @param Operation $operation Operation object * * @return \SimpleXMLElement */ protected function createRootElement(Operation $operation) { static $defaultRoot = array('name' => 'Request'); // If no root element was specified, then just wrap the XML in 'Request' $root = $operation->getData('xmlRoot') ?: $defaultRoot; // Create the wrapping element with no namespaces if no namespaces were present if (empty($root['namespaces'])) { return new \SimpleXMLElement("<{$root['name']}/>"); } else { // Create the wrapping element with an array of one or more namespaces $xml = "<{$root['name']} "; foreach ((array) $root['namespaces'] as $prefix => $uri) { $xml .= is_numeric($prefix) ? "xmlns=\"{$uri}\" " : "xmlns:{$prefix}=\"{$uri}\" "; } return new \SimpleXMLElement($xml . "/>"); } }
public function testHasData() { $o = new Operation(array('data' => array('foo' => 'baz', 'bar' => 123))); $o->setData('test', false); $this->assertEquals('baz', $o->getData('foo')); $this->assertEquals(123, $o->getData('bar')); $this->assertNull($o->getData('wfefwe')); $this->assertEquals(array('parameters' => array(), 'class' => 'Guzzle\\Service\\Command\\OperationCommand', 'data' => array('foo' => 'baz', 'bar' => 123, 'test' => false), 'responseClass' => 'array', 'responseType' => 'primitive'), $o->toArray()); }