lithium\net\http\Request::cookies PHP Method

cookies() public method

NOTE: Cookies values are expected to be scalar. This function will not serialize cookie values. If you wish to store a non-scalar value, you must serialize the data first.
public cookies ( string $key = null, string $value = null ) : mixed
$key string
$value string
return mixed
    public function cookies($key = null, $value = null)
    {
        if (is_string($key)) {
            if ($value === null) {
                return isset($this->cookies[$key]) ? $this->cookies[$key] : null;
            }
            if ($value === false) {
                unset($this->cookies[$key]);
                return $this->cookies;
            }
        }
        if ($key) {
            $cookies = is_array($key) ? $key : array($key => $value);
            $this->cookies = $cookies + $this->cookies;
        }
        return $this->cookies;
    }

Usage Example

Example #1
0
 public function testConstructWithCookies()
 {
     $request = new Request(array('host' => 'localhost', 'port' => 443, 'headers' => array('Cookie' => 'name1=value1; name2=value2'), 'body' => array('Part 1'), 'params' => array('param' => 'value')));
     $expected = array('name1' => 'value1', 'name2' => 'value2');
     $this->assertEqual($expected, $request->cookies());
 }