示例#1
0
 /**
  * Gets the cookie or jar
  * @param string|null $key
  * @return \Nimbles\Http\Cookie|\Nimbles\Http\Cookie\Jar|null
  */
 public function getCookie($key = null)
 {
     if (null === $this->_cookie) {
         $this->setCookie();
     }
     if (null === $key) {
         return $this->_cookie;
     }
     if ($this->_cookie->offsetExists($key)) {
         return $this->_cookie[$key];
     }
     return null;
 }
示例#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();
 }
示例#3
0
 /**
  * Gets a cookie variable by key
  * @param string|null $key
  * @return \Nimbles\Http\Cookie\Jar|string|null
  */
 public function getCookie($key = null)
 {
     if (null === $this->_cookie) {
         $this->_cookie = new Cookie\Jar($this->getCookieRaw(), array('readonly' => true));
     }
     if (null === $key) {
         return $this->_cookie;
     }
     return $this->_cookie->offsetExists($key) ? $this->_cookie[$key] : null;
 }