コード例 #1
0
ファイル: CookieBaseTest.php プロジェクト: comodojo/cookies
 public function testErase()
 {
     $result = \Comodojo\Cookies\Cookie::erase($this->cookie_name);
     $this->assertTrue($result);
 }
コード例 #2
0
 private static function deleteCookie()
 {
     return Cookie::erase(self::$cookie_name);
 }
コード例 #3
0
 private function getCurrentUser()
 {
     $token_name = $this->configuration->get('auth-token');
     try {
         $token = Cookie::retrieve($token_name);
         $broker = new Broker($database);
         $user = $broker->validate($token);
     } catch (CookieException $ce) {
         $user = $this->loadGuestUser();
     } catch (AuthenticationException $ae) {
         $user = $this->loadGuestUser();
     } catch (Exception $e) {
         throw $e;
     }
     return $user;
 }
コード例 #4
0
ファイル: SetCookieManager.php プロジェクト: comodojo/cookies
<?php

use Comodojo\Cookies\Cookie;
use Comodojo\Cookies\SecureCookie;
use Comodojo\Cookies\CookieManager;
use Comodojo\Exception\CookieException;
require __DIR__ . '/../../vendor/autoload.php';
ob_start();
$manager = new CookieManager();
$manager->register(Cookie::create('cookie_1', array('value' => 'cookie-1')));
$manager->register(SecureCookie::create('cookie_2', "thisismyverycomplexpassword", array('value' => 'cookie-2')));
$result = $manager->save();
ob_end_clean();
echo json_encode(array("manager" => $result));
コード例 #5
0
ファイル: Cookie.php プロジェクト: comodojo/cookies
 /**
  * Static method to get a cookie quickly
  *
  * @param   string   $name  The cookie name
  *
  * @return  \Comodojo\Cookies\Cookie
  *
  * @throws  \Comodojo\Exception\CookieException
  */
 public static function retrieve($name)
 {
     try {
         $cookie = new Cookie($name);
         $return = $cookie->load();
     } catch (CookieException $ce) {
         throw $ce;
     }
     return $return;
 }
コード例 #6
0
ファイル: CookieBase.php プロジェクト: comodojo/cookies
 /**
  * Static method to delete a cookie quickly
  *
  * @param   string   $name  The cookie name
  *
  * @return  boolean
  *
  * @throws  \Comodojo\Exception\CookieException
  */
 public static function erase($name)
 {
     try {
         $cookie = new Cookie($name);
         $return = $cookie->delete();
     } catch (CookieException $ce) {
         throw $ce;
     }
     return $return;
 }
コード例 #7
0
ファイル: GetCookie.php プロジェクト: comodojo/cookies
<?php

use Comodojo\Cookies\Cookie;
use Comodojo\Exception\CookieException;
require __DIR__ . '/../../vendor/autoload.php';
ob_start();
// create cookie with class constructor
$cookies = array();
$cookie_1 = new Cookie('cookie_1');
$cookies['cookie_1'] = $cookie_1->load()->getValue();
// create cookie with static method create
$cookies['cookie_2'] = Cookie::retrieve('cookie_2')->getValue();
try {
    $cookies['cookie_3'] = Cookie::retrieve('cookie_3')->getValue();
} catch (CookieException $ce) {
    $cookies['cookie_3'] = $ce->getMessage();
}
$cookies['cookie_4'] = Cookie::retrieve('cookie_4')->getValue();
try {
    $cookies['cookie_5'] = Cookie::retrieve('cookie_5')->getValue();
} catch (CookieException $ce) {
    $cookies['cookie_5'] = $ce->getMessage();
}
ob_end_clean();
echo json_encode($cookies);
コード例 #8
0
ファイル: GetCookieManager.php プロジェクト: comodojo/cookies
<?php

use Comodojo\Cookies\Cookie;
use Comodojo\Cookies\SecureCookie;
use Comodojo\Cookies\CookieManager;
use Comodojo\Exception\CookieException;
require __DIR__ . '/../../vendor/autoload.php';
ob_start();
$manager = new CookieManager();
$manager->register(Cookie::create('cookie_1'));
$manager->register(SecureCookie::create('cookie_2', "thisismyverycomplexpassword"));
$result = $manager->load()->getValues();
ob_end_clean();
echo json_encode($result);
コード例 #9
0
ファイル: SetCookie.php プロジェクト: comodojo/cookies
<?php

use Comodojo\Cookies\Cookie;
require __DIR__ . '/../../vendor/autoload.php';
ob_start();
// create cookie with class constructor
$cookies = array();
$cookie_1 = new Cookie('cookie_1');
$cookies['cookie_1'] = $cookie_1->setValue("cookie-1")->save();
// create cookie with static method create
$cookies['cookie_2'] = Cookie::create('cookie_2', array('value' => 'cookie-2'))->save();
// delete a cookie (should return a CookieException when retrieved)
$cookie_3 = new Cookie('cookie_3');
$cookies['cookie_3'] = $cookie_3->setValue('bla')->delete();
// set a cookie expiration timestamp
$cookie_4 = new Cookie('cookie_4');
$time = time();
$cookies['cookie_4'] = $cookie_4->setValue("expiry time: " . $time)->setExpire($time + 3600)->save();
// set a cookie for another domain (should return a CookieException when retrieved)
$cookie_5 = new Cookie('cookie_5');
$time = time();
$cookies['cookie_5'] = $cookie_5->setValue("cookie for www.example.com")->setDomain("www.example.com")->save();
ob_end_clean();
echo json_encode($cookies);
コード例 #10
0
ファイル: CookieTest.php プロジェクト: comodojo/cookies
 /**
  * @expectedException        Comodojo\Exception\CookieException
  */
 public function testRetrieve()
 {
     $cookie = \Comodojo\Cookies\Cookie::retrieve('test_cookie');
 }