示例#1
0
 /**
  * Fetch COOKIE data
  *
  * This method returns a key-value array of Cookie data sent in the HTTP request, or
  * the value of a array key if requested; if the array key does not exist, NULL is returned.
  *
  * @param string $key
  * @return array|string|null
  */
 public function cookies($key = null)
 {
     if (!isset($this->env['slim.request.cookie_hash'])) {
         $cookieHeader = isset($this->env['COOKIE']) ? $this->env['COOKIE'] : '';
         $this->env['slim.request.cookie_hash'] = Slim_Http_Util::parseCookieHeader($cookieHeader);
     }
     if ($key) {
         if (isset($this->env['slim.request.cookie_hash'][$key])) {
             return $this->env['slim.request.cookie_hash'][$key];
         } else {
             return null;
         }
     } else {
         return $this->env['slim.request.cookie_hash'];
     }
 }
示例#2
0
 public function testPrefersLeftmostCookieWhenManyCookiesWithSameName()
 {
     $header = 'foo=bar; foo=beer';
     $result = Slim_Http_Util::parseCookieHeader($header);
     $this->assertEquals('bar', $result['foo']);
 }
示例#3
0
 /**
  * Test parses Cookie: HTTP header
  */
 public function testParsesCookieHeader()
 {
     $header = 'foo=bar; one=two; colors=blue; colors=red; colors=green';
     $result = Slim_Http_Util::parseCookieHeader($header);
     $this->assertEquals(3, count($result));
     $this->assertEquals('bar', $result['foo']);
     $this->assertEquals('two', $result['one']);
     $this->assertEquals(3, count($result['colors']));
     $this->assertEquals('blue', $result['colors'][0]);
     $this->assertEquals('red', $result['colors'][1]);
     $this->assertEquals('green', $result['colors'][2]);
 }