示例#1
0
 /**
  * Sets a signed cookie.
  *
  * @access  public
  * @param   string               $name     Cookie name
  * @param   string               $value    Cookie value
  * @param   int                  $ttl      Time to live - if omitted or set to 0 the cookie will expire when the browser closes
  * @param   array                $options  Cookie options
  * @return  \mako\http\Response
  */
 public function signedCookie($name, $value, $ttl = 0, array $options = [])
 {
     if (empty($this->signer)) {
         throw new RuntimeException(vsprintf("%s(): A [ Signer ] instance is required to read signed cookies.", [__METHOD__]));
     }
     return $this->cookie($name, $this->signer->sign($value), $ttl, $options);
 }
示例#2
0
 /**
  * Validates and decrypts string.
  *
  * @access  public
  * @param   string          $string  String to decrypt
  * @return  string|boolean
  */
 public function validateAndDecrypt($string)
 {
     if (empty($this->signer)) {
         throw new RuntimeException(vsprintf("%s(): A [ Signer ] instance is required to validate signed string.", [__METHOD__]));
     }
     $string = $this->signer->validate($string);
     return $string === false ? false : $this->decrypt($string);
 }
示例#3
0
 /**
  * Fetch signed cookie data.
  *
  * @access  public
  * @param   string  $name     Cookie name
  * @param   mixed   $default  Default value
  * @return  string
  */
 public function signedCookie($name = null, $default = null)
 {
     if (empty($this->signer)) {
         throw new RuntimeException(vsprintf("%s(): A [ Signer ] instance is required to read signed cookies.", [__METHOD__]));
     }
     if (isset($this->cookies[$name]) && ($value = $this->signer->validate($this->cookies[$name])) !== false) {
         return $value;
     } else {
         return $default;
     }
 }
 /**
  *
  */
 public function testValidateInvalid()
 {
     $string = 'hello, world!';
     $signer = new Signer('foobar');
     $this->assertFalse($signer->validate(str_repeat('0', 64) . $string));
 }