本文整理汇总了PHP中Guzzle\Http\Message\Request::getCookies方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getCookies方法的具体用法?PHP Request::getCookies怎么用?PHP Request::getCookies使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Request
的用法示例。
在下文中一共展示了Request::getCookies方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setRequestCookies
private function setRequestCookies(\Guzzle\Http\Message\Request $request)
{
if (!is_null($request->getCookies())) {
foreach ($request->getCookies() as $name => $value) {
$request->removeCookie($name);
}
}
$cookieUrlMatcher = new \webignition\Cookie\UrlMatcher\UrlMatcher();
foreach ($this->getConfiguration()->getCookies() as $cookie) {
if ($cookieUrlMatcher->isMatch($cookie, $request->getUrl())) {
$request->addCookie($cookie['name'], $cookie['value']);
}
}
}
示例2: testHoldsCookies
/**
* @covers Guzzle\Http\Message\Request
*/
public function testHoldsCookies()
{
$this->assertNull($this->request->getCookie('test'));
// Set a cookie
$this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
$this->assertEquals('abc', $this->request->getCookie('test'));
// Multiple cookies by setting the Cookie header
$this->request->setHeader('Cookie', '__utma=1.638370270.1344367610.1374365610.1944450276.2; __utmz=1.1346368610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); hl=de; PHPSESSID=ak93pqashi5uubuoq8fjv60897');
$this->assertEquals('1.638370270.1344367610.1374365610.1944450276.2', $this->request->getCookie('__utma'));
$this->assertEquals('1.1346368610.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)', $this->request->getCookie('__utmz'));
$this->assertEquals('de', $this->request->getCookie('hl'));
$this->assertEquals('ak93pqashi5uubuoq8fjv60897', $this->request->getCookie('PHPSESSID'));
// Unset the cookies by setting the Cookie header to null
$this->request->setHeader('Cookie', null);
$this->assertNull($this->request->getCookie('test'));
$this->request->removeHeader('Cookie');
// Set and remove a cookie
$this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
$this->assertEquals('abc', $this->request->getCookie('test'));
$this->assertSame($this->request, $this->request->removeCookie('test'));
$this->assertNull($this->request->getCookie('test'));
// Remove the cookie header
$this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
$this->request->removeHeader('Cookie');
$this->assertEquals('', (string) $this->request->getHeader('Cookie'));
// Remove a cookie value
$this->request->addCookie('foo', 'bar')->addCookie('baz', 'boo');
$this->request->removeCookie('foo');
$this->assertEquals(array('baz' => 'boo'), $this->request->getCookies());
$this->request->addCookie('foo', 'bar');
$this->assertEquals('baz=boo; foo=bar', (string) $this->request->getHeader('Cookie'));
}
示例3: testHoldsCookies
/**
* @covers Guzzle\Http\Message\Request
*/
public function testHoldsCookies()
{
$this->assertNull($this->request->getCookie('test'));
// Set a cookie
$this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
$this->assertEquals('abc', $this->request->getCookie('test'));
// Unset the cookies by setting the Cookie header to null
$this->request->setHeader('Cookie', null);
$this->assertNull($this->request->getCookie('test'));
// Set and remove a cookie
$this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
$this->assertEquals('abc', $this->request->getCookie('test'));
$this->assertSame($this->request, $this->request->removeCookie('test'));
$this->assertNull($this->request->getCookie('test'));
// Remove the cookie header
$this->assertSame($this->request, $this->request->addCookie('test', 'abc'));
$this->request->removeHeader('Cookie');
$this->assertEquals('', (string) $this->request->getHeader('Cookie'));
// Remove a cookie value
$this->request->addCookie('foo', 'bar')->addCookie('baz', 'boo');
$this->request->removeCookie('foo');
$this->assertEquals(array('baz' => 'boo'), $this->request->getCookies());
}