/** * Prepare a Slim Request by Operation with $parameters * * @param Operation $operation * @param array $parameters * @param int $options BitMask of options to skip or something else * @return Request * @throws \InvalidArgumentException * @throws \RuntimeException */ public function makeRequestByOperation(Operation $operation, array $parameters = [], $options = 0) { $headers = new \Slim\Http\Headers(); $body = new \Slim\Http\RequestBody(); $path = $operation->path; if ($operation->parameters) { foreach ($operation->parameters as $parameter) { if (isset($parameters[$parameter->name])) { switch ($parameter->in) { case 'path': $path = str_replace('{' . $parameter->name . '}', $parameters[$parameter->name], $path); break; case 'header': $headers->set($parameter->name, $parameters[$parameter->name]); break; default: throw new RuntimeException(sprintf('Parameter "%s" with ->in = "%s" is not supported', $parameter->parameter, $parameter->in)); } } elseif ($parameter->required && !($options & SwaggerWrapper::SKIP_REQUIRED)) { throw new InvalidArgumentException(sprintf('Parameter "%s" is required, please pass value for this in $parameters', $parameter->name)); } } } $uri = new \Slim\Http\Uri('http', '', null, $path); return new Request($operation->method, $uri, $headers, [], [], $body); }
public function testNormalizesKey() { $h = new \Slim\Http\Headers(); $h->set('Http_Content_Type', 'text/html'); $prop = new \ReflectionProperty($h, 'data'); $prop->setAccessible(true); $this->assertArrayHasKey('Content-Type', $prop->getValue($h)); }
public function testSetCookieHeaderWithNameAndValueWhenCookieAlreadySet() { $name = 'foo'; $value = 'bar'; $headers = new \Slim\Http\Headers(); $headers->set('Set-Cookie', 'one=two'); $cookies = new \Slim\Http\Cookies(); $cookies->setHeader($headers, $name, $value); $this->assertEquals("one=two\nfoo=bar", $headers->get('Set-Cookie')); }