本文整理汇总了PHP中Symfony\Component\HttpFoundation\HeaderBag::get方法的典型用法代码示例。如果您正苦于以下问题:PHP HeaderBag::get方法的具体用法?PHP HeaderBag::get怎么用?PHP HeaderBag::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\HeaderBag
的用法示例。
在下文中一共展示了HeaderBag::get方法的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: 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');
}
示例3: prepareRequestUri
protected function prepareRequestUri()
{
$requestUri = '';
if ($this->headers->has('X_REWRITE_URL') && false !== stripos(PHP_OS, 'WIN')) {
// check this first so IIS will catch
$requestUri = $this->headers->get('X_REWRITE_URL');
} elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') {
// IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem)
$requestUri = $this->server->get('UNENCODED_URL');
} elseif ($this->server->has('REQUEST_URI')) {
$requestUri = $this->server->get('REQUEST_URI');
// HTTP proxy reqs setup request uri with scheme and host [and port] + the url path, only use url path
$schemeAndHttpHost = $this->getScheme() . '://' . $this->getHttpHost();
if (strpos($requestUri, $schemeAndHttpHost) === 0) {
$requestUri = substr($requestUri, strlen($schemeAndHttpHost));
}
} elseif ($this->server->has('ORIG_PATH_INFO')) {
// IIS 5.0, PHP as CGI
$requestUri = $this->server->get('ORIG_PATH_INFO');
if ($this->server->get('QUERY_STRING')) {
$requestUri .= '?' . $this->server->get('QUERY_STRING');
}
}
return $requestUri;
}
示例4:
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);
}
示例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: testGet
/**
* @covers Symfony\Component\HttpFoundation\HeaderBag::get
*/
public function testGet()
{
$bag = new HeaderBag(array('foo' => 'bar', 'fuzz' => 'bizz'));
$this->assertEquals('bar', $bag->get('foo'), '->get return current value');
$this->assertEquals('bar', $bag->get('FoO'), '->get key in case insensitive');
$this->assertEquals(array('bar'), $bag->get('foo', 'nope', false), '->get return the value as array');
// defaults
$this->assertNull($bag->get('none'), '->get unknown values returns null');
$this->assertEquals('default', $bag->get('none', 'default'), '->get unknown values returns default');
$this->assertEquals(array('default'), $bag->get('none', 'default', false), '->get unknown values returns default as array');
$bag->set('foo', 'bor', false);
$this->assertEquals('bar', $bag->get('foo'), '->get return first value');
$this->assertEquals(array('bar', 'bor'), $bag->get('foo', 'nope', false), '->get return all values as array');
}
示例7: 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);
}
示例8: 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.');
}
}
}
示例9: prepareRequestUri
protected function prepareRequestUri()
{
$requestUri = '';
if ($this->headers->has('X_ORIGINAL_URL')) {
// IIS with Microsoft Rewrite Module
$requestUri = $this->headers->get('X_ORIGINAL_URL');
$this->headers->remove('X_ORIGINAL_URL');
$this->server->remove('HTTP_X_ORIGINAL_URL');
$this->server->remove('UNENCODED_URL');
$this->server->remove('IIS_WasUrlRewritten');
} elseif ($this->headers->has('X_REWRITE_URL')) {
// IIS with ISAPI_Rewrite
$requestUri = $this->headers->get('X_REWRITE_URL');
$this->headers->remove('X_REWRITE_URL');
} elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') {
// IIS7 with URL Rewrite: make sure we get the unencoded url (double slash problem)
$requestUri = $this->server->get('UNENCODED_URL');
$this->server->remove('UNENCODED_URL');
$this->server->remove('IIS_WasUrlRewritten');
} elseif ($this->server->has('REQUEST_URI')) {
$requestUri = $this->server->get('REQUEST_URI');
// HTTP proxy reqs setup request uri with scheme and host [and port] + the url path, only use url path
$schemeAndHttpHost = $this->getSchemeAndHttpHost();
if (strpos($requestUri, $schemeAndHttpHost) === 0) {
$requestUri = substr($requestUri, strlen($schemeAndHttpHost));
}
} elseif ($this->server->has('ORIG_PATH_INFO')) {
// IIS 5.0, PHP as CGI
$requestUri = $this->server->get('ORIG_PATH_INFO');
if ('' != $this->server->get('QUERY_STRING')) {
$requestUri .= '?' . $this->server->get('QUERY_STRING');
}
$this->server->remove('ORIG_PATH_INFO');
}
// normalize the request URI to ease creating sub-requests from this request
$this->server->set('REQUEST_URI', $requestUri);
return $requestUri;
}
示例10: testCacheControlDirectiveParsing
public function testCacheControlDirectiveParsing()
{
$bag = new HeaderBag(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'));
$bag->addCacheControlDirective('s-maxage', 100);
$this->assertEquals('max-age=10, public, s-maxage=100', $bag->get('cache-control'));
}
示例11: isRedirected
public function isRedirected($location)
{
return $this->isRedirect() && $location == $this->headers->get('Location');
}
示例12: 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;
}
示例13: getHeader
/**
* @param string $name
*
* @return array|string
*/
public function getHeader($name)
{
return $this->headers->get($name);
}
示例14: pjax
/**
* Determine if the request is the result of an PJAX call.
*
* @return bool
*/
public function pjax()
{
return $this->headers->get('X-PJAX') == true;
}
示例15: getProgramByOrigin
protected function getProgramByOrigin(HeaderBag $headers)
{
$program = null;
if ($headers->has('Origin')) {
$host = parse_url($headers->get('Origin'), PHP_URL_HOST);
/** @var \Petrosoft\LoyaltyBundle\Models\FrontSiteSettings\Collection $siteCol */
$siteCol = $this->meetz->collection('Loyalty:Models\\FrontSiteSettings');
$siteCol->addFieldToFilter('hosts', array($host), 'in');
$siteSettings = $siteCol->getFirstItem();
if (!$siteSettings->isObjectNew()) {
$program = $siteSettings->getData('loyalty_program_id');
if ($program instanceof \MongoId) {
$program = $program->{'$id'};
}
}
}
return $program;
}