예제 #1
0
파일: Jar.php 프로젝트: nimbles/Framework
 /**
  * Overloads offsetSet to restrict value type
  * @param  int|string      $key
  * @param  \Nimbles\Http\Cookie $value
  * @return void
  * @throws \Nimbles\Http\Cookie\Exception\InvalidInstance
  */
 public function offsetSet($key, $value)
 {
     if (is_string($value)) {
         $value = new Cookie(array('name' => $key, 'value' => $value));
     }
     if (!$value instanceof Cookie) {
         throw new Cookie\Exception\InvalidInstance('Invalid value, must be an instance of Nimbles\\Http\\Cookie');
     }
     if (null === $value->getName()) {
         $value->setName($key);
     }
     return parent::offsetSet($value->getName(), $value);
 }
예제 #2
0
 public function testExpires()
 {
     $cookie = new Cookie();
     $expire = 3600;
     $currentTime = time();
     $expireTime = time() + $expire;
     $expireString = date('r', $expireTime);
     $cookie->setExpires($expireString);
     $this->assertEquals($expire, $cookie->getExpires());
 }
예제 #3
0
 /**
  * Tests sending the cookie jar and that the Nimbles\Http\Cookie\Exception\HeadersAlreadySent
  * exception is thrown when attempt to send once headers are already sent
  * @return void
  */
 public function testSend()
 {
     $jar = new Cookie\Jar();
     $cookie = new Cookie(array('name' => 'test_name', 'value' => 'test value'));
     $sent = false;
     $urlencoded = array();
     $raw = array();
     $cookie->setDelegate('headers_sent', function () use(&$sent) {
         return $sent;
     });
     $cookie->setDelegate('setcookie', function () use(&$urlencoded) {
         $urlencoded = func_get_args();
         $urlencoded[1] = urlencode($urlencoded[1]);
     });
     $jar[] = $cookie;
     $this->assertEquals('test value', (string) $jar['test_name']);
     $jar->send();
     $this->assertSame(array('test_name', 'test+value', 0, '/', null, false, false), $urlencoded);
     $sent = true;
     $this->setExpectedException('Nimbles\\Http\\Cookie\\Exception\\HeadersAlreadySent');
     $jar->send();
 }
예제 #4
0
 /**
  * Destroys the session
  * @return \Nimbles\Http\Session
  */
 public function destroy()
 {
     if (!$this->isStarted()) {
         return;
     }
     $this->clear();
     if (ini_get('session.use_cookies')) {
         $params = $this->getCookieParams();
         $cookie = new Cookie(array('name' => $this->getName(), 'value' => '', 'expire' => time() - 42000, 'path' => $params['path'], 'domain' => $params['domain'], 'secure' => $params['secure'], 'httponly' => $params['httponly']));
         $cookie->setDelegate('headers_sent', $this->getDelegate('headers_sent'));
         $cookie->setDelegate('setcookie', $this->getDelegate('setcookie'));
         $cookie->setDelegate('setrawcookie', $this->getDelegate('setrawcookie'));
         $cookie->send();
     }
     $this->session_destroy();
     return $this;
 }