示例#1
0
 /**
  * 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;
 }
示例#2
0
<?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);