summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor')
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/AbstractRequestVisitor.php69
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/BodyVisitor.php58
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/HeaderVisitor.php44
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/JsonVisitor.php63
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/PostFieldVisitor.php18
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/PostFileVisitor.php24
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/QueryVisitor.php18
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/RequestVisitorInterface.php31
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/ResponseBodyVisitor.php18
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/XmlVisitor.php252
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/AbstractResponseVisitor.php26
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/BodyVisitor.php23
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/HeaderVisitor.php50
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/JsonVisitor.php93
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/ReasonPhraseVisitor.php23
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/ResponseVisitorInterface.php46
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/StatusCodeVisitor.php23
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php151
-rw-r--r--vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/VisitorFlyweight.php138
19 files changed, 1168 insertions, 0 deletions
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/AbstractRequestVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/AbstractRequestVisitor.php
new file mode 100644
index 0000000..adcfca1
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/AbstractRequestVisitor.php
@@ -0,0 +1,69 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Service\Command\CommandInterface;
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Service\Description\Parameter;
+
+abstract class AbstractRequestVisitor implements RequestVisitorInterface
+{
+ /**
+ * @codeCoverageIgnore
+ */
+ public function after(CommandInterface $command, RequestInterface $request) {}
+
+ /**
+ * @codeCoverageIgnore
+ */
+ public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value) {}
+
+ /**
+ * Prepare (filter and set desired name for request item) the value for request.
+ *
+ * @param mixed $value
+ * @param \Guzzle\Service\Description\Parameter $param
+ *
+ * @return array|mixed
+ */
+ protected function prepareValue($value, Parameter $param)
+ {
+ return is_array($value)
+ ? $this->resolveRecursively($value, $param)
+ : $param->filter($value);
+ }
+
+ /**
+ * 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);
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/BodyVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/BodyVisitor.php
new file mode 100644
index 0000000..168d780
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/BodyVisitor.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Http\EntityBody;
+use Guzzle\Http\Message\EntityEnclosingRequestInterface;
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Http\EntityBodyInterface;
+use Guzzle\Service\Command\CommandInterface;
+use Guzzle\Service\Description\Parameter;
+
+/**
+ * Visitor used to apply a body to a request
+ *
+ * This visitor can use a data parameter of 'expect' to control the Expect header. Set the expect data parameter to
+ * false to disable the expect header, or set the value to an integer so that the expect 100-continue header is only
+ * added if the Content-Length of the entity body is greater than the value.
+ */
+class BodyVisitor extends AbstractRequestVisitor
+{
+ public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
+ {
+ $value = $param->filter($value);
+ $entityBody = EntityBody::factory($value);
+ $request->setBody($entityBody);
+ $this->addExpectHeader($request, $entityBody, $param->getData('expect_header'));
+ // Add the Content-Encoding header if one is set on the EntityBody
+ if ($encoding = $entityBody->getContentEncoding()) {
+ $request->setHeader('Content-Encoding', $encoding);
+ }
+ }
+
+ /**
+ * Add the appropriate expect header to a request
+ *
+ * @param EntityEnclosingRequestInterface $request Request to update
+ * @param EntityBodyInterface $body Entity body of the request
+ * @param string|int $expect Expect header setting
+ */
+ protected function addExpectHeader(EntityEnclosingRequestInterface $request, EntityBodyInterface $body, $expect)
+ {
+ // Allow the `expect` data parameter to be set to remove the Expect header from the request
+ if ($expect === false) {
+ $request->removeHeader('Expect');
+ } elseif ($expect !== true) {
+ // Default to using a MB as the point in which to start using the expect header
+ $expect = $expect ?: 1048576;
+ // If the expect_header value is numeric then only add if the size is greater than the cutoff
+ if (is_numeric($expect) && $body->getSize()) {
+ if ($body->getSize() < $expect) {
+ $request->removeHeader('Expect');
+ } else {
+ $request->setHeader('Expect', '100-Continue');
+ }
+ }
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/HeaderVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/HeaderVisitor.php
new file mode 100644
index 0000000..2a53754
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/HeaderVisitor.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Common\Exception\InvalidArgumentException;
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Service\Command\CommandInterface;
+use Guzzle\Service\Description\Parameter;
+
+/**
+ * Visitor used to apply a parameter to a header value
+ */
+class HeaderVisitor extends AbstractRequestVisitor
+{
+ public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
+ {
+ $value = $param->filter($value);
+ if ($param->getType() == 'object' && $param->getAdditionalProperties() instanceof Parameter) {
+ $this->addPrefixedHeaders($request, $param, $value);
+ } else {
+ $request->setHeader($param->getWireName(), $value);
+ }
+ }
+
+ /**
+ * Add a prefixed array of headers to the request
+ *
+ * @param RequestInterface $request Request to update
+ * @param Parameter $param Parameter object
+ * @param array $value Header array to add
+ *
+ * @throws InvalidArgumentException
+ */
+ protected function addPrefixedHeaders(RequestInterface $request, Parameter $param, $value)
+ {
+ if (!is_array($value)) {
+ throw new InvalidArgumentException('An array of mapped headers expected, but received a single value');
+ }
+ $prefix = $param->getSentAs();
+ foreach ($value as $headerName => $headerValue) {
+ $request->setHeader($prefix . $headerName, $headerValue);
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/JsonVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/JsonVisitor.php
new file mode 100644
index 0000000..757e1c5
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/JsonVisitor.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Service\Command\CommandInterface;
+use Guzzle\Service\Description\Parameter;
+
+/**
+ * Visitor used to apply a parameter to an array that will be serialized as a top level key-value pair in a JSON body
+ */
+class JsonVisitor extends AbstractRequestVisitor
+{
+ /** @var bool Whether or not to add a Content-Type header when JSON is found */
+ protected $jsonContentType = 'application/json';
+
+ /** @var \SplObjectStorage Data object for persisting JSON data */
+ protected $data;
+
+ public function __construct()
+ {
+ $this->data = new \SplObjectStorage();
+ }
+
+ /**
+ * Set the Content-Type header to add to the request if JSON is added to the body. This visitor does not add a
+ * Content-Type header unless you specify one here.
+ *
+ * @param string $header Header to set when JSON is added (e.g. application/json)
+ *
+ * @return self
+ */
+ public function setContentTypeHeader($header = 'application/json')
+ {
+ $this->jsonContentType = $header;
+
+ return $this;
+ }
+
+ 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;
+ }
+
+ public function after(CommandInterface $command, RequestInterface $request)
+ {
+ if (isset($this->data[$command])) {
+ // Don't overwrite the Content-Type if one is set
+ if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
+ $request->setHeader('Content-Type', $this->jsonContentType);
+ }
+
+ $request->setBody(json_encode($this->data[$command]));
+ unset($this->data[$command]);
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/PostFieldVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/PostFieldVisitor.php
new file mode 100644
index 0000000..975850b
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/PostFieldVisitor.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Service\Command\CommandInterface;
+use Guzzle\Service\Description\Parameter;
+
+/**
+ * Visitor used to apply a parameter to a POST field
+ */
+class PostFieldVisitor extends AbstractRequestVisitor
+{
+ public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
+ {
+ $request->setPostField($param->getWireName(), $this->prepareValue($value, $param));
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/PostFileVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/PostFileVisitor.php
new file mode 100644
index 0000000..0853ebe
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/PostFileVisitor.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Http\Message\PostFileInterface;
+use Guzzle\Service\Command\CommandInterface;
+use Guzzle\Service\Description\Parameter;
+
+/**
+ * Visitor used to apply a parameter to a POST file
+ */
+class PostFileVisitor extends AbstractRequestVisitor
+{
+ public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
+ {
+ $value = $param->filter($value);
+ if ($value instanceof PostFileInterface) {
+ $request->addPostFile($value);
+ } else {
+ $request->addPostFile($param->getWireName(), $value);
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/QueryVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/QueryVisitor.php
new file mode 100644
index 0000000..315877a
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/QueryVisitor.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Service\Command\CommandInterface;
+use Guzzle\Service\Description\Parameter;
+
+/**
+ * Visitor used to apply a parameter to a request's query string
+ */
+class QueryVisitor extends AbstractRequestVisitor
+{
+ public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
+ {
+ $request->getQuery()->set($param->getWireName(), $this->prepareValue($value, $param));
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/RequestVisitorInterface.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/RequestVisitorInterface.php
new file mode 100644
index 0000000..14e0b2d
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/RequestVisitorInterface.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Service\Command\CommandInterface;
+
+/**
+ * Location visitor used to add values to different locations in a request with different behaviors as needed
+ */
+interface RequestVisitorInterface
+{
+ /**
+ * Called after visiting all parameters
+ *
+ * @param CommandInterface $command Command being visited
+ * @param RequestInterface $request Request being visited
+ */
+ public function after(CommandInterface $command, RequestInterface $request);
+
+ /**
+ * Called once for each parameter being visited that matches the location type
+ *
+ * @param CommandInterface $command Command being visited
+ * @param RequestInterface $request Request being visited
+ * @param Parameter $param Parameter being visited
+ * @param mixed $value Value to set
+ */
+ public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value);
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/ResponseBodyVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/ResponseBodyVisitor.php
new file mode 100644
index 0000000..09f35f8
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/ResponseBodyVisitor.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Service\Command\CommandInterface;
+use Guzzle\Service\Description\Parameter;
+
+/**
+ * Visitor used to change the location in which a response body is saved
+ */
+class ResponseBodyVisitor extends AbstractRequestVisitor
+{
+ public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
+ {
+ $request->setResponseBody($value);
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/XmlVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/XmlVisitor.php
new file mode 100644
index 0000000..5b71487
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/XmlVisitor.php
@@ -0,0 +1,252 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Http\Message\RequestInterface;
+use Guzzle\Service\Command\CommandInterface;
+use Guzzle\Service\Description\Operation;
+use Guzzle\Service\Description\Parameter;
+
+/**
+ * Location visitor used to serialize XML bodies
+ */
+class XmlVisitor extends AbstractRequestVisitor
+{
+ /** @var \SplObjectStorage Data object for persisting XML data */
+ protected $data;
+
+ /** @var bool Content-Type header added when XML is found */
+ protected $contentType = 'application/xml';
+
+ public function __construct()
+ {
+ $this->data = new \SplObjectStorage();
+ }
+
+ /**
+ * Change the content-type header that is added when XML is found
+ *
+ * @param string $header Header to set when XML is found
+ *
+ * @return self
+ */
+ public function setContentTypeHeader($header)
+ {
+ $this->contentType = $header;
+
+ return $this;
+ }
+
+ public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
+ {
+ $xml = isset($this->data[$command])
+ ? $this->data[$command]
+ : $this->createRootElement($param->getParent());
+ $this->addXml($xml, $param, $value);
+
+ $this->data[$command] = $xml;
+ }
+
+ public function after(CommandInterface $command, RequestInterface $request)
+ {
+ $xml = null;
+
+ // If data was found that needs to be serialized, then do so
+ if (isset($this->data[$command])) {
+ $xml = $this->finishDocument($this->data[$command]);
+ unset($this->data[$command]);
+ } else {
+ // Check if XML should always be sent for the command
+ $operation = $command->getOperation();
+ if ($operation->getData('xmlAllowEmpty')) {
+ $xmlWriter = $this->createRootElement($operation);
+ $xml = $this->finishDocument($xmlWriter);
+ }
+ }
+
+ if ($xml) {
+ // Don't overwrite the Content-Type if one is set
+ if ($this->contentType && !$request->hasHeader('Content-Type')) {
+ $request->setHeader('Content-Type', $this->contentType);
+ }
+ $request->setBody($xml);
+ }
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Recursively build the XML body
+ *
+ * @param \XMLWriter $xmlWriter XML to modify
+ * @param Parameter $param API Parameter
+ * @param mixed $value Value to add
+ */
+ 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);
+ }
+ }
+
+ /**
+ * Write an attribute with namespace if used
+ *
+ * @param \XMLWriter $xmlWriter XMLWriter instance
+ * @param string $prefix Namespace prefix if any
+ * @param string $name Attribute name
+ * @param string $namespace The uri of the namespace
+ * @param string $value The attribute content
+ */
+ protected function writeAttribute($xmlWriter, $prefix, $name, $namespace, $value)
+ {
+ if (empty($namespace)) {
+ $xmlWriter->writeAttribute($name, $value);
+ } else {
+ $xmlWriter->writeAttributeNS($prefix, $name, $namespace, $value);
+ }
+ }
+
+ /**
+ * Write an element with namespace if used
+ *
+ * @param \XMLWriter $xmlWriter XML writer resource
+ * @param string $prefix Namespace prefix if any
+ * @param string $name Element name
+ * @param string $namespace The uri of the namespace
+ * @param string $value The element content
+ */
+ protected function writeElement(\XMLWriter $xmlWriter, $prefix, $name, $namespace, $value)
+ {
+ $xmlWriter->startElementNS($prefix, $name, $namespace);
+ if (strpbrk($value, '<>&')) {
+ $xmlWriter->writeCData($value);
+ } else {
+ $xmlWriter->writeRaw($value);
+ }
+ $xmlWriter->endElement();
+ }
+
+ /**
+ * Create a new xml writer and start a document
+ *
+ * @param string $encoding document encoding
+ *
+ * @return \XMLWriter the writer resource
+ */
+ protected function startDocument($encoding)
+ {
+ $xmlWriter = new \XMLWriter();
+ $xmlWriter->openMemory();
+ $xmlWriter->startDocument('1.0', $encoding);
+
+ return $xmlWriter;
+ }
+
+ /**
+ * End the document and return the output
+ *
+ * @param \XMLWriter $xmlWriter
+ *
+ * @return \string the writer resource
+ */
+ protected function finishDocument($xmlWriter)
+ {
+ $xmlWriter->endDocument();
+
+ return $xmlWriter->outputMemory();
+ }
+
+ /**
+ * Add an array to the XML
+ */
+ protected function addXmlArray(\XMLWriter $xmlWriter, Parameter $param, &$value)
+ {
+ if ($items = $param->getItems()) {
+ foreach ($value as $v) {
+ $this->addXml($xmlWriter, $items, $v);
+ }
+ }
+ }
+
+ /**
+ * 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']);
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/AbstractResponseVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/AbstractResponseVisitor.php
new file mode 100644
index 0000000..d87eeb9
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/AbstractResponseVisitor.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Service\Command\CommandInterface;
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Description\Parameter;
+
+/**
+ * {@inheritdoc}
+ * @codeCoverageIgnore
+ */
+abstract class AbstractResponseVisitor implements ResponseVisitorInterface
+{
+ public function before(CommandInterface $command, array &$result) {}
+
+ public function after(CommandInterface $command) {}
+
+ public function visit(
+ CommandInterface $command,
+ Response $response,
+ Parameter $param,
+ &$value,
+ $context = null
+ ) {}
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/BodyVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/BodyVisitor.php
new file mode 100644
index 0000000..f70b727
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/BodyVisitor.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Service\Command\CommandInterface;
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Description\Parameter;
+
+/**
+ * Visitor used to add the body of a response to a particular key
+ */
+class BodyVisitor extends AbstractResponseVisitor
+{
+ public function visit(
+ CommandInterface $command,
+ Response $response,
+ Parameter $param,
+ &$value,
+ $context = null
+ ) {
+ $value[$param->getName()] = $param->filter($response->getBody());
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/HeaderVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/HeaderVisitor.php
new file mode 100644
index 0000000..0f8737c
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/HeaderVisitor.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Service\Command\CommandInterface;
+
+/**
+ * Location visitor used to add a particular header of a response to a key in the result
+ */
+class HeaderVisitor extends AbstractResponseVisitor
+{
+ public function visit(
+ CommandInterface $command,
+ Response $response,
+ Parameter $param,
+ &$value,
+ $context = null
+ ) {
+ if ($param->getType() == 'object' && $param->getAdditionalProperties() instanceof Parameter) {
+ $this->processPrefixedHeaders($response, $param, $value);
+ } else {
+ $value[$param->getName()] = $param->filter((string) $response->getHeader($param->getWireName()));
+ }
+ }
+
+ /**
+ * Process a prefixed header array
+ *
+ * @param Response $response Response that contains the headers
+ * @param Parameter $param Parameter object
+ * @param array $value Value response array to modify
+ */
+ protected function processPrefixedHeaders(Response $response, Parameter $param, &$value)
+ {
+ // Grab prefixed headers that should be placed into an array with the prefix stripped
+ if ($prefix = $param->getSentAs()) {
+ $container = $param->getName();
+ $len = strlen($prefix);
+ // Find all matching headers and place them into the containing element
+ foreach ($response->getHeaders()->toArray() as $key => $header) {
+ if (stripos($key, $prefix) === 0) {
+ // Account for multi-value headers
+ $value[$container][substr($key, $len)] = count($header) == 1 ? end($header) : $header;
+ }
+ }
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/JsonVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/JsonVisitor.php
new file mode 100644
index 0000000..a609ebd
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/JsonVisitor.php
@@ -0,0 +1,93 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Service\Command\CommandInterface;
+
+/**
+ * Location visitor used to marshal JSON response data into a formatted array.
+ *
+ * Allows top level JSON parameters to be inserted into the result of a command. The top level attributes are grabbed
+ * from the response's JSON data using the name value by default. Filters can be applied to parameters as they are
+ * traversed. This allows data to be normalized before returning it to users (for example converting timestamps to
+ * DateTime objects).
+ */
+class JsonVisitor extends AbstractResponseVisitor
+{
+ public function before(CommandInterface $command, array &$result)
+ {
+ // Ensure that the result of the command is always rooted with the parsed JSON data
+ $result = $command->getResponse()->json();
+ }
+
+ 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]);
+ }
+ }
+ }
+
+ /**
+ * Recursively process a parameter while applying filters
+ *
+ * @param Parameter $param API parameter being validated
+ * @param mixed $value Value to validate and process. The value may change during this process.
+ */
+ protected function recursiveProcess(Parameter $param, &$value)
+ {
+ if ($value === null) {
+ return;
+ }
+
+ if (is_array($value)) {
+ $type = $param->getType();
+ if ($type == 'array') {
+ foreach ($value as &$item) {
+ $this->recursiveProcess($param->getItems(), $item);
+ }
+ } elseif ($type == 'object' && !isset($value[0])) {
+ // On the above line, we ensure that the array is associative and not numerically indexed
+ $knownProperties = array();
+ if ($properties = $param->getProperties()) {
+ foreach ($properties as $property) {
+ $name = $property->getName();
+ $key = $property->getWireName();
+ $knownProperties[$name] = 1;
+ if (isset($value[$key])) {
+ $this->recursiveProcess($property, $value[$key]);
+ if ($key != $name) {
+ $value[$name] = $value[$key];
+ unset($value[$key]);
+ }
+ }
+ }
+ }
+
+ // Remove any unknown and potentially unsafe properties
+ if ($param->getAdditionalProperties() === false) {
+ $value = array_intersect_key($value, $knownProperties);
+ } elseif (($additional = $param->getAdditionalProperties()) !== true) {
+ // Validate and filter additional properties
+ foreach ($value as &$v) {
+ $this->recursiveProcess($additional, $v);
+ }
+ }
+ }
+ }
+
+ $value = $param->filter($value);
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/ReasonPhraseVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/ReasonPhraseVisitor.php
new file mode 100644
index 0000000..1b10ebc
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/ReasonPhraseVisitor.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Service\Command\CommandInterface;
+
+/**
+ * Location visitor used to add the reason phrase of a response to a key in the result
+ */
+class ReasonPhraseVisitor extends AbstractResponseVisitor
+{
+ public function visit(
+ CommandInterface $command,
+ Response $response,
+ Parameter $param,
+ &$value,
+ $context = null
+ ) {
+ $value[$param->getName()] = $response->getReasonPhrase();
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/ResponseVisitorInterface.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/ResponseVisitorInterface.php
new file mode 100644
index 0000000..033f40c
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/ResponseVisitorInterface.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Service\Command\CommandInterface;
+
+/**
+ * Location visitor used to parse values out of a response into an associative array
+ */
+interface ResponseVisitorInterface
+{
+ /**
+ * Called before visiting all parameters. This can be used for seeding the result of a command with default
+ * data (e.g. populating with JSON data in the response then adding to the parsed data).
+ *
+ * @param CommandInterface $command Command being visited
+ * @param array $result Result value to update if needed (e.g. parsing XML or JSON)
+ */
+ public function before(CommandInterface $command, array &$result);
+
+ /**
+ * Called after visiting all parameters
+ *
+ * @param CommandInterface $command Command being visited
+ */
+ public function after(CommandInterface $command);
+
+ /**
+ * Called once for each parameter being visited that matches the location type
+ *
+ * @param CommandInterface $command Command being visited
+ * @param Response $response Response being visited
+ * @param Parameter $param Parameter being visited
+ * @param mixed $value Result associative array value being updated by reference
+ * @param mixed $context Parsing context
+ */
+ public function visit(
+ CommandInterface $command,
+ Response $response,
+ Parameter $param,
+ &$value,
+ $context = null
+ );
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/StatusCodeVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/StatusCodeVisitor.php
new file mode 100644
index 0000000..00c5ce0
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/StatusCodeVisitor.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Service\Command\CommandInterface;
+
+/**
+ * Location visitor used to add the status code of a response to a key in the result
+ */
+class StatusCodeVisitor extends AbstractResponseVisitor
+{
+ public function visit(
+ CommandInterface $command,
+ Response $response,
+ Parameter $param,
+ &$value,
+ $context = null
+ ) {
+ $value[$param->getName()] = $response->getStatusCode();
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php
new file mode 100644
index 0000000..bb7124b
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php
@@ -0,0 +1,151 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Service\Command\CommandInterface;
+
+/**
+ * Location visitor used to marshal XML response data into a formatted array
+ */
+class XmlVisitor extends AbstractResponseVisitor
+{
+ public function before(CommandInterface $command, array &$result)
+ {
+ // Set the result of the command to the array conversion of the XML body
+ $result = json_decode(json_encode($command->getResponse()->xml()), true);
+ }
+
+ 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]);
+ }
+ }
+ }
+
+ /**
+ * Recursively process a parameter while applying filters
+ *
+ * @param Parameter $param API parameter being processed
+ * @param mixed $value Value to validate and process. The value may change during this process.
+ */
+ protected function recursiveProcess(Parameter $param, &$value)
+ {
+ $type = $param->getType();
+
+ if (!is_array($value)) {
+ if ($type == 'array') {
+ // Cast to an array if the value was a string, but should be an array
+ $this->recursiveProcess($param->getItems(), $value);
+ $value = array($value);
+ }
+ } elseif ($type == 'object') {
+ $this->processObject($param, $value);
+ } elseif ($type == 'array') {
+ $this->processArray($param, $value);
+ } elseif ($type == 'string' && gettype($value) == 'array') {
+ $value = '';
+ }
+
+ if ($value !== null) {
+ $value = $param->filter($value);
+ }
+ }
+
+ /**
+ * Process an array
+ *
+ * @param Parameter $param API parameter being parsed
+ * @param mixed $value Value to process
+ */
+ protected function processArray(Parameter $param, &$value)
+ {
+ // Convert the node if it was meant to be an array
+ if (!isset($value[0])) {
+ // Collections fo nodes are sometimes wrapped in an additional array. For example:
+ // <Items><Item><a>1</a></Item><Item><a>2</a></Item></Items> should become:
+ // array('Items' => array(array('a' => 1), array('a' => 2))
+ // Some nodes are not wrapped. For example: <Foo><a>1</a></Foo><Foo><a>2</a></Foo>
+ // should become array('Foo' => array(array('a' => 1), array('a' => 2))
+ if ($param->getItems() && isset($value[$param->getItems()->getWireName()])) {
+ // Account for the case of a collection wrapping wrapped nodes: Items => Item[]
+ $value = $value[$param->getItems()->getWireName()];
+ // If the wrapped node only had one value, then make it an array of nodes
+ if (!isset($value[0]) || !is_array($value)) {
+ $value = array($value);
+ }
+ } elseif (!empty($value)) {
+ // Account for repeated nodes that must be an array: Foo => Baz, Foo => Baz, but only if the
+ // value is set and not empty
+ $value = array($value);
+ }
+ }
+
+ foreach ($value as &$item) {
+ $this->recursiveProcess($param->getItems(), $item);
+ }
+ }
+
+ /**
+ * Process an object
+ *
+ * @param Parameter $param API parameter being parsed
+ * @param mixed $value Value to process
+ */
+ protected function processObject(Parameter $param, &$value)
+ {
+ // Ensure that the array is associative and not numerically indexed
+ if (!isset($value[0]) && ($properties = $param->getProperties())) {
+ $knownProperties = array();
+ foreach ($properties as $property) {
+ $name = $property->getName();
+ $sentAs = $property->getWireName();
+ $knownProperties[$name] = 1;
+ if ($property->getData('xmlAttribute')) {
+ $this->processXmlAttribute($property, $value);
+ } elseif (isset($value[$sentAs])) {
+ $this->recursiveProcess($property, $value[$sentAs]);
+ if ($name != $sentAs) {
+ $value[$name] = $value[$sentAs];
+ unset($value[$sentAs]);
+ }
+ }
+ }
+
+ // Remove any unknown and potentially unsafe properties
+ if ($param->getAdditionalProperties() === false) {
+ $value = array_intersect_key($value, $knownProperties);
+ }
+ }
+ }
+
+ /**
+ * Process an XML attribute property
+ *
+ * @param Parameter $property Property to process
+ * @param array $value Value to process and update
+ */
+ 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']);
+ }
+ }
+ }
+}
diff --git a/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/VisitorFlyweight.php b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/VisitorFlyweight.php
new file mode 100644
index 0000000..74cb628
--- /dev/null
+++ b/vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/VisitorFlyweight.php
@@ -0,0 +1,138 @@
+<?php
+
+namespace Guzzle\Service\Command\LocationVisitor;
+
+use Guzzle\Common\Exception\InvalidArgumentException;
+use Guzzle\Service\Command\LocationVisitor\Request\RequestVisitorInterface;
+use Guzzle\Service\Command\LocationVisitor\Response\ResponseVisitorInterface;
+
+/**
+ * Flyweight factory used to instantiate request and response visitors
+ */
+class VisitorFlyweight
+{
+ /** @var self Singleton instance of self */
+ protected static $instance;
+
+ /** @var array Default array of mappings of location names to classes */
+ protected static $defaultMappings = array(
+ 'request.body' => 'Guzzle\Service\Command\LocationVisitor\Request\BodyVisitor',
+ 'request.header' => 'Guzzle\Service\Command\LocationVisitor\Request\HeaderVisitor',
+ 'request.json' => 'Guzzle\Service\Command\LocationVisitor\Request\JsonVisitor',
+ 'request.postField' => 'Guzzle\Service\Command\LocationVisitor\Request\PostFieldVisitor',
+ 'request.postFile' => 'Guzzle\Service\Command\LocationVisitor\Request\PostFileVisitor',
+ 'request.query' => 'Guzzle\Service\Command\LocationVisitor\Request\QueryVisitor',
+ 'request.response_body' => 'Guzzle\Service\Command\LocationVisitor\Request\ResponseBodyVisitor',
+ 'request.responseBody' => 'Guzzle\Service\Command\LocationVisitor\Request\ResponseBodyVisitor',
+ 'request.xml' => 'Guzzle\Service\Command\LocationVisitor\Request\XmlVisitor',
+ 'response.body' => 'Guzzle\Service\Command\LocationVisitor\Response\BodyVisitor',
+ 'response.header' => 'Guzzle\Service\Command\LocationVisitor\Response\HeaderVisitor',
+ 'response.json' => 'Guzzle\Service\Command\LocationVisitor\Response\JsonVisitor',
+ 'response.reasonPhrase' => 'Guzzle\Service\Command\LocationVisitor\Response\ReasonPhraseVisitor',
+ 'response.statusCode' => 'Guzzle\Service\Command\LocationVisitor\Response\StatusCodeVisitor',
+ 'response.xml' => 'Guzzle\Service\Command\LocationVisitor\Response\XmlVisitor'
+ );
+
+ /** @var array Array of mappings of location names to classes */
+ protected $mappings;
+
+ /** @var array Cache of instantiated visitors */
+ protected $cache = array();
+
+ /**
+ * @return self
+ * @codeCoverageIgnore
+ */
+ public static function getInstance()
+ {
+ if (!self::$instance) {
+ self::$instance = new self();
+ }
+
+ return self::$instance;
+ }
+
+ /**
+ * @param array $mappings Array mapping request.name and response.name to location visitor classes. Leave null to
+ * use the default values.
+ */
+ public function __construct(array $mappings = null)
+ {
+ $this->mappings = $mappings === null ? self::$defaultMappings : $mappings;
+ }
+
+ /**
+ * Get an instance of a request visitor by location name
+ *
+ * @param string $visitor Visitor name
+ *
+ * @return RequestVisitorInterface
+ */
+ public function getRequestVisitor($visitor)
+ {
+ return $this->getKey('request.' . $visitor);
+ }
+
+ /**
+ * Get an instance of a response visitor by location name
+ *
+ * @param string $visitor Visitor name
+ *
+ * @return ResponseVisitorInterface
+ */
+ public function getResponseVisitor($visitor)
+ {
+ return $this->getKey('response.' . $visitor);
+ }
+
+ /**
+ * Add a response visitor to the factory by name
+ *
+ * @param string $name Name of the visitor
+ * @param RequestVisitorInterface $visitor Visitor to add
+ *
+ * @return self
+ */
+ public function addRequestVisitor($name, RequestVisitorInterface $visitor)
+ {
+ $this->cache['request.' . $name] = $visitor;
+
+ return $this;
+ }
+
+ /**
+ * Add a response visitor to the factory by name
+ *
+ * @param string $name Name of the visitor
+ * @param ResponseVisitorInterface $visitor Visitor to add
+ *
+ * @return self
+ */
+ public function addResponseVisitor($name, ResponseVisitorInterface $visitor)
+ {
+ $this->cache['response.' . $name] = $visitor;
+
+ return $this;
+ }
+
+ /**
+ * Get a visitor by key value name
+ *
+ * @param string $key Key name to retrieve
+ *
+ * @return mixed
+ * @throws InvalidArgumentException
+ */
+ private function getKey($key)
+ {
+ if (!isset($this->cache[$key])) {
+ if (!isset($this->mappings[$key])) {
+ list($type, $name) = explode('.', $key);
+ throw new InvalidArgumentException("No {$type} visitor has been mapped for {$name}");
+ }
+ $this->cache[$key] = new $this->mappings[$key];
+ }
+
+ return $this->cache[$key];
+ }
+}