本文整理汇总了PHP中Symfony\Component\HttpFoundation\HeaderBag::set方法的典型用法代码示例。如果您正苦于以下问题:PHP HeaderBag::set方法的具体用法?PHP HeaderBag::set怎么用?PHP HeaderBag::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\HeaderBag
的用法示例。
在下文中一共展示了HeaderBag::set方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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']);
}
}
}
示例2: 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']);
}
}
}
示例3: setHeaders
/**
* @param array $headers
*/
public function setHeaders(array $headers)
{
foreach ($headers as $name => $value) {
if ($this->metadata->isPrefixedKey($name)) {
$this->metadata->set($name, $value);
} else {
// make sure we store an array
$this->headers->set($name, (array) $value);
}
}
}
示例4: setRedirect
/**
* Modifies the response so that it conforms to the rules defined for a redirect status code.
*
* @see http://tools.ietf.org/html/rfc2616#section-10.3.5
*/
public function setRedirect($url, $status = 302)
{
if (empty($url)) {
throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
}
$this->setStatusCode($status);
if (!$this->isRedirect()) {
throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
}
$this->headers->set('Location', $url);
$this->setContent(sprintf('<html><head><meta http-equiv="refresh" content="1;url=%s"/></head></html>', htmlspecialchars($url, ENT_QUOTES)));
}
示例5: 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');
}
示例6: setVary
/**
* Sets the Vary header.
*
* @param string|array $headers
* @param Boolean $replace Whether to replace the actual value of not (true by default)
*/
public function setVary($headers, $replace = true)
{
$this->headers->set('Vary', $headers, $replace);
}
示例7: set
/**
* Sets a header by name.
*
* @param string $key
* @param mixed $values
* @param Boolean $replace
*/
public function set($key, $values, $replace = true)
{
parent::set($key, $values, $replace);
$this->updateRequest();
}
示例8: enforceNoCache
/**
* @param HeaderBag $headers
*/
private function enforceNoCache(HeaderBag $headers)
{
$headers->set('cache-control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', false);
$headers->set('Pragma', 'no-cache', false);
}
示例9: getContainerRenderActionCached
protected function getContainerRenderActionCached()
{
$headerBag = new HeaderBag();
$headerBag->set('If-Modified-Since', false);
$requestMock = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
$requestMock->expects($this->at(0))->method('get')->will($this->returnValue('test.txt'));
$requestMock->expects($this->at(1))->method('get')->will($this->returnValue('cached_hash'));
$requestMock->expects($this->any())->method('isMethodSafe')->will($this->returnValue(true));
$requestMock->expects($this->any())->method('getMethod')->will($this->returnValue('GET'));
$requestMock->expects($this->any())->method('getEtags')->will($this->returnValue(array('"cached_hash"')));
$requestMock->headers = $headerBag;
$container = new Container();
$container->set('request', $requestMock);
return $container;
}
示例10: set
/**
* {@inheritdoc}
*
* @api
*/
public function set($key, $values, $replace = true)
{
parent::set($key, $values, $replace);
$uniqueKey = strtr(strtolower($key), '_', '-');
$this->headerNames[$uniqueKey] = $key;
}
示例11: setLastModifiedDate
/**
* @param \DateTime $lastModified
*/
public function setLastModifiedDate(\DateTime $lastModified)
{
$this->headers->set('Last-Modified', $lastModified->format(DATE_RFC2822));
}
示例12: fixHeaderBag
/**
* @param HeaderBag $headers
*/
public function fixHeaderBag(HeaderBag $headers)
{
if (!$headers->has('Authorization')) {
$headers->set('Authorization', $this->getAuthorizationHeader());
}
}