本文整理匯總了PHP中Slim::setEncryptedCookie方法的典型用法代碼示例。如果您正苦於以下問題:PHP Slim::setEncryptedCookie方法的具體用法?PHP Slim::setEncryptedCookie怎麽用?PHP Slim::setEncryptedCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Slim
的用法示例。
在下文中一共展示了Slim::setEncryptedCookie方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testSlimSetsEncryptedCookie
/**
* Test Slim sets encrypted cookie
*
* Pre-conditions:
* Slim app initialized;
* Case A: Cookie time not set;
* Case B: Cookie time set as seconds from now (integer);
* Case C: Cookie time set as string;
* Case D: Cookie time is set to 0;
*
* Post-conditions:
* Cookie available in response;
* Case A: Cookie time set using default value;
* Case C: Cookie time set using `strtotime()`;
* Case D: Cookie time is 0;
*/
public function testSlimSetsEncryptedCookie() {
Slim::init();
$cj = Slim::response()->getCookieJar();
//Case A
$timeA = time();
Slim::setEncryptedCookie('myCookie1', 'myValue1');
$cookieA = $cj->getResponseCookie('myCookie1');
$this->assertEquals('myCookie1', $cookieA->getName());
$this->assertEquals($timeA + 1200, $cookieA->getExpires()); //default duration is 20 minutes
$this->assertEquals('/', $cookieA->getPath());
$this->assertEquals('', $cookieA->getDomain());
$this->assertFalse($cookieA->getSecure());
$this->assertFalse($cookieA->getHttpOnly());
//Case C
$timeC = time();
Slim::setEncryptedCookie('myCookie3', 'myValue3', '1 hour');
$cookieC = $cj->getResponseCookie('myCookie3');
$this->assertEquals($timeC + 3600, $cookieC->getExpires());
//Case D
$timeD = time();
Slim::setEncryptedCookie('myCookie4', 'myValue4', 0);
$cookieD = $cj->getResponseCookie('myCookie4');
$this->assertEquals(0, $cookieD->getExpires());
}
示例2: write
public function write($id, $sessionData)
{
Slim::setEncryptedCookie($id, $sessionData, 0);
}
示例3: testSlimDeletesCookies
/**
* Test Slim deletes cookies
*
* Pre-conditions:
* Case A: Classic cookie
* Case B: Encrypted cookie
*
* Post-conditions:
* Response Cookies replaced with empty, auto-expiring Cookies
*/
public function testSlimDeletesCookies()
{
$app = new Slim();
$cj = $app->response()->getCookieJar();
//Case A
$app->setCookie('foo1', 'bar1');
$this->assertEquals('bar1', $cj->getResponseCookie('foo1')->getValue());
$this->assertTrue($cj->getResponseCookie('foo1')->getExpires() > time());
$app->deleteCookie('foo1');
$this->assertEquals('', $app->getCookie('foo1'));
$this->assertTrue($cj->getResponseCookie('foo1')->getExpires() < time());
//Case B
$app->setEncryptedCookie('foo2', 'bar2');
$this->assertTrue(strlen($cj->getResponseCookie('foo2')->getValue()) > 0);
$this->assertTrue($cj->getResponseCookie('foo2')->getExpires() > time());
$app->deleteCookie('foo2');
$this->assertEquals('', $cj->getResponseCookie('foo2')->getValue());
$this->assertTrue($cj->getResponseCookie('foo2')->getExpires() < time());
}
示例4: testSetEncryptedCookie
/**
* Test set encrypted cookie
*
* This method ensures that the `Set-Cookie:` HTTP request
* header is set. The implementation is tested in a separate file.
*/
public function testSetEncryptedCookie()
{
$s = new Slim();
$s->setEncryptedCookie('foo', 'bar');
$r = $s->response();
$this->assertEquals(1, preg_match("@^foo=.+%7C.+%7C.+@", $r['Set-Cookie']));
//<-- %7C is a url-encoded pipe
}
示例5: testSlimDeletesCookies
/**
* Test Slim deletes cookies
*
* Pre-conditions:
* Case A: Classic cookie
* Case B: Encrypted cookie
*
* Post-conditions:
* Response Cookies replaced with empty, auto-expiring Cookies
*/
public function testSlimDeletesCookies()
{
Slim::init();
$cj = Slim::response()->getCookieJar();
//Case A
Slim::setCookie('foo1', 'bar1');
$this->assertEquals('bar1', $cj->getResponseCookie('foo1')->getValue());
$this->assertTrue($cj->getResponseCookie('foo1')->getExpires() > time());
Slim::deleteCookie('foo1');
$this->assertEquals('', Slim::getCookie('foo1'));
$this->assertTrue($cj->getResponseCookie('foo1')->getExpires() < time());
//Case B
Slim::setEncryptedCookie('foo2', 'bar2');
$this->assertTrue(strlen($cj->getResponseCookie('foo2')->getValue()) > 0);
$this->assertTrue($cj->getResponseCookie('foo2')->getExpires() > time());
Slim::deleteCookie('foo2');
$this->assertEquals('', $cj->getResponseCookie('foo2')->getValue());
$this->assertTrue($cj->getResponseCookie('foo2')->getExpires() < time());
}