/** * 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)); }
protected function createResponse(array $headerData = array(), array $cookieData = array(), $body = '', $status = 200) { $headers = new \Slim\Http\Headers(); $headers->replace($headerData); $cookies = new \Slim\Http\Cookies(); $cookies->replace($cookieData); return new \Slim\Http\Response($headers, $cookies, $body, $status); }
public function testDoesNotUseCertainHeaders() { $env = new \Slim\Environment(); $env->mock(array('CONTENT_TYPE' => 'text/csv', 'HTTP_CONTENT_TYPE' => 'text/plain', 'CONTENT_LENGTH' => 10, 'HTTP_CONTENT_LENGTH' => 20)); $headers = new \Slim\Http\Headers($env); $this->assertEquals('text/csv', $headers->get('HTTP_CONTENT_TYPE')); $this->assertEquals(10, $headers->get('HTTP_CONTENT_LENGTH')); }
public function testDeleteCookieHeaderWithoutMatchingDomain() { $headers = new \Slim\Http\Headers(); $headers->replace(array('Set-Cookie' => "foo=bar; domain=foo.com")); $cookies = new \Slim\Http\Cookies(); $cookies->deleteHeader($headers, 'foo', array('domain' => 'bar.com')); $this->assertEquals(1, preg_match("@foo=bar; domain=foo\\.com\nfoo=; domain=bar\\.com@", $headers->get('Set-Cookie'))); }