Ejemplo n.º 1
0
 /**
  * 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);
     }
 }
Ejemplo n.º 2
0
 protected function processPrefixedHeaders(Response $response, Parameter $param, &$value)
 {
     if ($prefix = $param->getSentAs()) {
         $container = $param->getName();
         $len = strlen($prefix);
         foreach ($response->getHeaders()->toArray() as $key => $header) {
             if (stripos($key, $prefix) === 0) {
                 $value[$container][substr($key, $len)] = count($header) == 1 ? end($header) : $header;
             }
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * 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() as $key => $header) {
             if (stripos($key, $prefix) === 0) {
                 // Account for multi-value headers
                 $value[$container][substr($key, $len)] = count($header) == 1 ? end($header) : $header;
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
 {
     $filteredValue = $param->filter($value);
     if (null !== $this->serializer && (is_object($filteredValue) || is_array($filteredValue))) {
         switch ($param->getSentAs()) {
             case 'json':
                 $request->setHeader('Content-Type', 'application/json');
                 $contentType = 'json';
                 break;
             case 'yml':
             case 'yaml':
                 $request->setHeader('Content-Type', 'application/yaml');
                 $contentType = 'yml';
                 break;
             default:
                 $request->setHeader('Content-Type', 'application/xml');
                 $contentType = 'xml';
                 break;
         }
         $context = SerializationContext::create();
         if (null !== ($groups = $param->getData('jms_serializer.groups'))) {
             $context->setGroups($groups);
         }
         if (null !== ($version = $param->getData('jms_serializer.version'))) {
             $context->setVersion($version);
         }
         if (null !== ($nulls = $param->getData('jms_serializer.serialize_nulls'))) {
             $context->setSerializeNull($nulls);
         }
         if (true === $param->getData('jms_serializer.max_depth_checks')) {
             $context->enableMaxDepthChecks();
         }
         $value = $this->serializer->serialize($filteredValue, $contentType, $context);
     }
     parent::visit($command, $request, $param, $value);
 }
Ejemplo n.º 5
0
 /**
  * Prepares and stores the description for a link parameter
  *
  * Prepares and stores the data describing a link parameter, to be
  * later used by getLinksParameter() to describe all the links.
  *
  * @param \Guzzle\Service\Command\CommandInterface $command
  * @param \Guzzle\Service\Description\Parameter    $parameter
  */
 public function addLinkParam(CommandInterface $command, Parameter $parameter)
 {
     $params = array();
     if (isset($this->params[$command])) {
         $params = $this->params[$command];
     }
     // Store parameter definition for later
     $params[$parameter->getName()] = array('name' => $parameter->getName(), 'description' => $parameter->getDescription(), 'required' => $parameter->getRequired(), 'sentAs' => $parameter->getSentAs(), 'type' => 'object', 'properties' => array('class' => array('type' => 'string', 'required' => true, 'pattern' => '/^[a-z_]+$/'), 'href' => array('type' => 'string', 'required' => true, 'pattern' => '#^/api/v2/#')));
     $this->params[$command] = $params;
 }
Ejemplo n.º 6
0
 public function testCanBuildUpParams()
 {
     $p = new Parameter(array());
     $p->setName('foo')->setDescription('c')->setFilters(array('d'))->setLocation('e')->setSentAs('f')->setMaxLength(1)->setMinLength(1)->setMinimum(2)->setMaximum(2)->setMinItems(3)->setMaxItems(3)->setRequired(true)->setStatic(true)->setDefault('h')->setType('i');
     $p->addFilter('foo');
     $this->assertEquals('foo', $p->getName());
     $this->assertEquals('h', $p->getDefault());
     $this->assertEquals('c', $p->getDescription());
     $this->assertEquals(array('d', 'foo'), $p->getFilters());
     $this->assertEquals('e', $p->getLocation());
     $this->assertEquals('f', $p->getSentAs());
     $this->assertEquals(1, $p->getMaxLength());
     $this->assertEquals(1, $p->getMinLength());
     $this->assertEquals(2, $p->getMaximum());
     $this->assertEquals(2, $p->getMinimum());
     $this->assertEquals(3, $p->getMaxItems());
     $this->assertEquals(3, $p->getMinItems());
     $this->assertEquals(true, $p->getRequired());
     $this->assertEquals(true, $p->getStatic());
     $this->assertEquals('i', $p->getType());
 }