本文整理汇总了PHP中Guzzle\Http\Message\Request::getCookie方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getCookie方法的具体用法?PHP Request::getCookie怎么用?PHP Request::getCookie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Request
的用法示例。
在下文中一共展示了Request::getCookie方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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'));
}
示例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'));
// 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());
}
示例3: testHoldsCookies
/**
* @covers Guzzle\Http\Message\Request
*/
public function testHoldsCookies()
{
$cookie = $this->request->getCookie();
$this->assertInstanceOf('Guzzle\\Http\\Cookie', $this->request->getCookie());
// Ensure that the cookie will not affect the request
$this->assertNull($this->request->getCookie('test'));
$cookie->set('test', 'abc');
$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->getCookie());
// Set the cookie using a cookie object
$this->assertSame($this->request, $this->request->setCookie($cookie));
$this->assertEquals($cookie->getAll(), $this->request->getCookie()->getAll());
// Set the cookie using an array
$this->assertSame($this->request, $this->request->setCookie(array('test' => 'def')));
$this->assertEquals(array('test' => 'def'), $this->request->getCookie()->getAll());
// Test using an invalid value
try {
$this->request->setCookie('a');
$this->fail('Did not throw expected exception when passing invalid value');
} catch (\InvalidArgumentException $e) {
}
}
示例4: testAddsCookiesToRequests
/**
* @covers Guzzle\Http\Plugin\CookiePlugin
*/
public function testAddsCookiesToRequests()
{
ArrayCookieJarTest::addCookies($this->storage);
$this->storage->save(array('domain' => '.y.example.com', 'path' => '/acme/', 'cookie' => array('secure', 'sec'), 'expires' => Guzzle::getHttpDate('+1 day'), 'secure' => true));
// Add a cookie that is only set on a specific port, so it wont be
// added to the following requests
$this->storage->save(array('domain' => '.y.example.com', 'path' => '/acme/', 'cookie' => array('test', 'port'), 'expires' => Guzzle::getHttpDate('+1 day'), 'secure' => false, 'port' => array(8192)));
$request1 = new Request('GET', 'https://a.y.example.com/acme/');
$request1->setClient(new Client());
$request2 = new Request('GET', 'https://a.y.example.com/acme/');
$request2->setClient(new Client());
$request3 = new Request('GET', 'http://a.y.example.com/acme/');
$request3->setClient(new Client());
$request4 = new Request('GET', 'http://a.y.example.com/acme/');
$request4->setClient(new Client());
$request1->getEventDispatcher()->addSubscriber($this->plugin);
$request2->getEventDispatcher()->addSubscriber($this->plugin);
$request3->getEventDispatcher()->addSubscriber($this->plugin);
$request4->getEventDispatcher()->addSubscriber($this->plugin);
// Set a secure cookie
$response1 = Response::fromMessage("HTTP/1.1 200 OK\r\nSet-Cookie: a=b; c=d; Max-Age=86400; domain=.example.com; secure;\r\n\r\n");
// Set a regular cookie
$response2 = Response::fromMessage("HTTP/1.1 200 OK\r\nSet-Cookie: e=f h; discard; domain=.example.com;\r\n\r\n");
$response3 = Response::fromMessage("HTTP/1.1 200 OK\r\n\r\n");
$request1->setResponse($response1, true);
$request2->setResponse($response2, true);
$request3->setResponse($response3, true);
$request1->send();
$request2->send();
$request3->send();
$this->assertEquals('muppet=cookie_monster;secure=sec', (string) $request1->getCookie());
$this->assertEquals('muppet=cookie_monster;secure=sec;a=b;c=d', (string) $request2->getCookie());
$this->assertEquals('muppet=cookie_monster;e=f h', (string) $request3->getCookie());
// Clear the e=f h temporary cookie
$this->plugin->clearTemporaryCookies();
$request4->setResponse($response3, true);
$request4->send();
$this->assertEquals('muppet=cookie_monster', (string) $request4->getCookie());
}
示例5: createNewUser
/**
* @param Lang $lang
* @param Logger $logger
* @param User $newUserWrapper
* @param Request $socketRequest
* @return UserDAO
*/
private function createNewUser(Lang $lang, Logger $logger, User $newUserWrapper, Request $socketRequest)
{
$user = UserDAO::create()->setChatId(1)->setDateRegister(DbQueryHelper::timestamp2date())->setRole(UserRoleEnum::USER)->setBanned(false)->setImprint(null);
try {
$user->save();
} catch (\PDOException $e) {
$logger->error("PDO Exception: " . $e->getMessage() . ': ' . $e->getTraceAsString(), [__METHOD__]);
}
$id = $user->getId();
$guestName = $lang->getPhrase('Guest') . $id;
if (PropertiesDAO::create()->getByUserName($guestName)->getName()) {
$guestName = $lang->getPhrase('Guest') . ' ' . $id;
}
$properties = $user->getPropeties();
$properties->setUserId($user->getId())->setName($guestName)->setSex(SexEnum::create(SexEnum::ANONYM))->setTim(TimEnum::create(TimEnum::ANY))->setBirthday(Rules::LOWEST_YEAR)->setOptions([PropertiesDAO::CENSOR => true])->setOnlineCount(0)->setMusicCount(0)->setWordsCount(0)->setRudeCount(0)->setKarma(0)->setMessagesCount(0)->setSubscription(true);
try {
$properties->save();
} catch (\PDOException $e) {
$logger->error("PDO Exception: " . $e->getTraceAsString(), [__CLASS__]);
}
if ($refUserId = $socketRequest->getCookie('refUserId')) {
$ref = ReferralDAO::create()->getByUserId($user->getId(), $refUserId);
if (!$ref) {
$ref = ReferralDAO::create()->setUserId($user->getId())->setRefUserId($refUserId)->setDateRegister(DbQueryHelper::timestamp2date());
$ref->save();
$logger->info('Found referral userId ' . $refUserId . ' for guest userId ' . $user->getId());
}
}
$logger->info("Created new user with id = {$id} for connectionId = {$newUserWrapper->getConnectionId()}", [__CLASS__]);
return $user;
}