本文整理汇总了PHP中Symfony\Component\HttpFoundation\HeaderBag类的典型用法代码示例。如果您正苦于以下问题:PHP HeaderBag类的具体用法?PHP HeaderBag怎么用?PHP HeaderBag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HeaderBag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: it_will_create_event_from_request
public function it_will_create_event_from_request(Request $request, HeaderBag $headerBag)
{
$request->headers = $headerBag;
$headerBag->get('X-GitHub-Event')->willReturn('push');
$headerBag->get('X-Hub-Signature')->willReturn('sha1=abc123');
$this->create($request)->shouldReturnAnInstanceOf('DevBoard\\Notify\\Event');
}
示例2:
function it_gets_an_item_from_the_header(Request $request, HeaderBag $headerBag)
{
$item = 'foo';
$return = 'bar';
$request->headers = $headerBag;
$headerBag->get($item)->shouldBeCalled(1)->willReturn($return);
$this->header($item)->shouldReturn($return);
}
示例3: fixAuthHeader
/**
* PHP does not include HTTP_AUTHORIZATION in the $_SERVER array, so this header is missing.
* We retrieve it from apache_request_headers()
*
* @see https://github.com/symfony/symfony/issues/7170
*
* @param HeaderBag $headers
*/
private static function fixAuthHeader(\Symfony\Component\HttpFoundation\HeaderBag $headers)
{
if (!$headers->has('Authorization') && function_exists('apache_request_headers')) {
$all = apache_request_headers();
if (isset($all['Authorization'])) {
$headers->set('Authorization', $all['Authorization']);
}
}
}
示例4: it_will_create_pull_request_event
public function it_will_create_pull_request_event($signatureFactory, WebHookSignature $signature, Request $request, HeaderBag $headerBag)
{
$request->headers = $headerBag;
$headerBag->get('X-GitHub-Event')->willReturn('pull_request');
$headerBag->get('X-Hub-Signature')->willReturn('sha1=abc123');
$signatureFactory->create('sha1=abc123')->willReturn($signature);
$request->getContent()->willReturn('{}');
$this->create($request)->shouldReturnAnInstanceOf('DevBoard\\Github\\WebHook\\Data\\PullRequestEvent');
}
示例5:
function it_invalidates_signature(Request $request, HeaderBag $headers)
{
$headers->get('X-Shopify-Hmac-Sha256')->willReturn(self::HMAC_HEADER_WRONG)->shouldbeCalled();
$request->headers = $headers;
$request->getContent()->willReturn(self::DATA)->shouldbeCalled();
$this->setHttpRequest($request);
$this->verify()->shouldBeBool();
$this->verify()->shouldReturn(false);
}
示例6: formatHeaders
private function formatHeaders(HeaderBag $headerBag)
{
$headers = $headerBag->all();
$content = '';
foreach ($headers as $name => $values) {
$name = implode('-', array_map('ucfirst', explode('-', $name)));
foreach ($values as $value) {
$content .= sprintf("%s %s; ", $name . ':', $value);
}
}
return $content;
}
示例7: fixAuthHeader
/**
* PHP does not include HTTP_AUTHORIZATION in the $_SERVER array, so this header is missing.
* We retrieve it from apache_request_headers()
*
* @param HeaderBag $headers
*/
protected function fixAuthHeader(HeaderBag $headers)
{
if (!$headers->has('Authorization') && function_exists('apache_request_headers')) {
$all = apache_request_headers();
if (isset($all['Authorization'])) {
$headers->set('Authorization', $all['Authorization']);
}
if (isset($all['authorization'])) {
$headers->set('Authorization', $all['authorization']);
}
}
}
示例8: persistHeaders
/**
* Creates an array of cacheable and normalized request headers
*
* @param HeaderBag $headers
* @return array
*/
private function persistHeaders(HeaderBag $headers)
{
// Headers are excluded from the caching (see RFC 2616:13.5.1)
static $noCache = array('age', 'connection', 'keep-alive', 'proxy-authenticate', 'proxy-authorization', 'te', 'trailers', 'transfer-encoding', 'upgrade', 'set-cookie', 'set-cookie2');
foreach ($headers as $key => $value) {
if (in_array($key, $noCache) || strpos($key, 'x-') === 0) {
$headers->remove($key);
}
}
// Postman client sends a dynamic token to bypass a Chrome bug
$headers->remove('postman-token');
return $headers;
}
示例9: testContains
/**
* @covers Symfony\Component\HttpFoundation\HeaderBag::contains
*/
public function testContains()
{
$bag = new HeaderBag(array('foo' => 'bar', 'fuzz' => 'bizz'));
$this->assertTrue($bag->contains('foo', 'bar'), '->contains first value');
$this->assertTrue($bag->contains('fuzz', 'bizz'), '->contains second value');
$this->assertFalse($bag->contains('nope', 'nope'), '->contains unknown value');
$this->assertFalse($bag->contains('foo', 'nope'), '->contains unknown value');
// Multiple values
$bag->set('foo', 'bor', false);
$this->assertTrue($bag->contains('foo', 'bar'), '->contains first value');
$this->assertTrue($bag->contains('foo', 'bor'), '->contains second value');
$this->assertFalse($bag->contains('foo', 'nope'), '->contains unknown value');
}
示例10: let
public function let(AngularCsrfTokenManager $tokenManager, RouteMatcherInterface $routeMatcher, Request $secureValidRequest, Request $secureInvalidRequest, Request $unsecureRequest, HeaderBag $validHeaders, HeaderBag $invalidHeaders)
{
$tokenManager->isTokenValid(self::VALID_TOKEN)->willReturn(true);
$tokenManager->isTokenValid(self::INVALID_TOKEN)->willReturn(false);
$this->secureValidRequest = $secureValidRequest;
$validHeaders->get(self::HEADER_NAME)->willReturn(self::VALID_TOKEN);
$this->secureValidRequest->headers = $validHeaders;
$this->secureInvalidRequest = $secureInvalidRequest;
$invalidHeaders->get(self::HEADER_NAME)->willReturn(self::INVALID_TOKEN);
$this->secureInvalidRequest->headers = $invalidHeaders;
$this->unsecureRequest = $unsecureRequest;
$routeMatcher->match($this->secureValidRequest, $this->routes)->willReturn(true);
$routeMatcher->match($this->secureInvalidRequest, $this->routes)->willReturn(true);
$routeMatcher->match($this->unsecureRequest, $this->routes)->willReturn(false);
$this->beConstructedWith($tokenManager, $routeMatcher, $this->routes, self::HEADER_NAME);
}
示例11: validateField
/**
* Verifies that the provided header has the expected/mandatory fields.
*
* @param ParameterBag|HeaderBag $header object representation of the request header.
* @param string $fieldName Name of the header field to be validated.
*
* @return void
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
protected function validateField($header, $fieldName)
{
$passed = $header->has($fieldName);
// return without exception so we can return a dummy user
if (true === $passed) {
// get rid of anything not a valid character
$authInfo = filter_var($header->get($fieldName), FILTER_SANITIZE_STRING);
// get rid of whitespaces
$patterns = array("\r\n", "\n", "\r", "\\s", "\t");
$authInfo = str_replace($patterns, "", trim($authInfo));
// get rid of control characters
if (empty($authInfo) || $authInfo !== preg_replace('#[[:cntrl:]]#i', '', $authInfo)) {
throw new HttpException(Response::HTTP_NETWORK_AUTHENTICATION_REQUIRED, 'Mandatory header field (' . $fieldName . ') not provided or invalid.');
}
}
}
示例12: function
function it_handles_communication_logging(CommunicationLogger $logger, CommunicationExtractor $extractor, Request $request, Response $response, HeaderBag $requestHeaders, IEvent $event)
{
$request->getMethod()->shouldBeCalled()->willReturn('POST');
$request->getContent()->shouldBeCalled()->willReturn('request');
$request->getUri()->shouldBeCalled()->willReturn('http://example.com');
$request->headers = $requestHeaders;
$requestHeaders->all()->shouldBeCalled()->willReturn([]);
$next = function (Request $request) use($response) {
return new Response();
};
$extractor->getRequest(Argument::type(GuzzleRequest::class))->shouldBeCalled()->willReturn(['request' => 'request']);
$extractor->getResponse(Argument::type(GuzzleResponse::class))->shouldBeCalled()->willReturn(['response' => 'response']);
$logger->begin('request', 'http://example.com', 'POST', '')->shouldBeCalled()->willReturn($event);
$logger->end($event, 'response')->shouldBeCalled();
$this->handle($request, $next);
}
示例13: testCacheControlDirectiveOverrideWithReplace
public function testCacheControlDirectiveOverrideWithReplace()
{
$bag = new HeaderBag(array('cache-control' => 'private, max-age=100'));
$bag->replace(array('cache-control' => 'public, max-age=10'));
$this->assertTrue($bag->hasCacheControlDirective('public'));
$this->assertTrue($bag->getCacheControlDirective('public'));
$this->assertTrue($bag->hasCacheControlDirective('max-age'));
$this->assertEquals(10, $bag->getCacheControlDirective('max-age'));
}
示例14: getTagsFromHeaders
/**
* Retrieve and decode the tag list from the response
* headers.
*
* If no tags header is found then throw a \RuntimeException.
* If the JSON is invalid then throw a \RuntimeException
*
* @param HeaderBag $headers
*
* @throws \RuntimeException
*
* @return string[]
*/
private function getTagsFromHeaders(HeaderBag $headers)
{
$tagsRaw = $headers->get($this->options['header_tags']);
$tags = $this->decodeTags($tagsRaw, true);
return $tags;
}
示例15: createRequestMock
/**
* @return \Symfony\Component\HttpFoundation\Request
*/
private function createRequestMock(array $headers = null)
{
$headers = $this->mergeHeaders($headers);
$headerBag = new HeaderBag();
$headerBag->add($headers);
$fakeReq = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
$fakeReq->headers = $headerBag;
return $fakeReq;
}