本文整理汇总了PHP中Zend\Http\PhpEnvironment\Request::setHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setHeaders方法的具体用法?PHP Request::setHeaders怎么用?PHP Request::setHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\PhpEnvironment\Request
的用法示例。
在下文中一共展示了Request::setHeaders方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
Console::overrideIsConsole(false);
parent::setUp();
$this->request = new Request();
$this->request->setHeaders(new Headers());
$this->routeMatch = new RouteMatch(array('controller' => $this->controllerName));
$this->event = $this->getApplication()->getMvcEvent();
$this->event->setRequest($this->request);
$this->event->setRouteMatch($this->routeMatch);
$this->event->getRouter()->setRequestUri(new HttpUri('http://localhost'));
if (null === $this->controller) {
if (null === $this->controllerName) {
throw new PHPUnit_Framework_Exception('No controller name was specified in the test');
}
$this->controller = $this->getServiceManager()->get('ControllerLoader')->get($this->controllerName);
}
$this->controller->setEvent($this->event);
}
示例2: testFromHeaderMethod
public function testFromHeaderMethod()
{
$headers = "X-Test-Header-1: Header1Value\r\n" . "X-Test-Header-2: Header2Value\r\n";
$r = new Request();
$r->setHeaders(\Zend\Http\Headers::fromString($headers));
$e = new MvcEvent();
$e->setRequest($r);
$helper = new Helper($e);
$header = $helper->fromHeader('X-Test-Header-1');
$this->assertInstanceOf('\\Zend\\Http\\Header\\GenericHeader', $header);
$this->assertEquals('Header1Value', $header->getFieldValue());
$expect = array('X-Test-Header-1' => 'Header1Value', 'X-Test-Header-2' => 'Header2Value');
$this->assertEquals($expect, $helper->fromHeader());
$this->assertEquals('default', $helper->fromHeader('X-Not-Here', 'default'));
}
示例3: testRetrievingASingleValueForParameters
public function testRetrievingASingleValueForParameters()
{
$request = new Request();
$p = new \Zend\Stdlib\Parameters(array('foo' => 'bar'));
$request->setQuery($p);
$request->setPost($p);
$request->setFiles($p);
$request->setServer($p);
$request->setEnv($p);
$this->assertSame('bar', $request->getQuery('foo'));
$this->assertSame('bar', $request->getPost('foo'));
$this->assertSame('bar', $request->getFiles('foo'));
$this->assertSame('bar', $request->getServer('foo'));
$this->assertSame('bar', $request->getEnv('foo'));
$headers = new Headers();
$h = new GenericHeader('foo', 'bar');
$headers->addHeader($h);
$request->setHeaders($headers);
$this->assertSame($headers, $request->getHeaders());
$this->assertSame($h, $request->getHeaders()->get('foo'));
$this->assertSame($h, $request->getHeader('foo'));
}