Esempio n. 1
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;
 }
Esempio n. 2
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();
 }