Extends
lithium\core\Object
Match an `$expected` cookie with the given headers. If no headers are provided, then
the value of `headers_list()` will be used.
Parameters
- array $expected
- array $headers When empty, value of `headers_list()` will be used.
Returns
boolean True if cookie is found, false otherwise.Source
protected function _cookieMatch($expected, $headers) {
$defaults = array('path' => '/', 'name' => '[\w.-]+');
$expected += $defaults;
$headers = ($headers) ?: headers_list();
$value = preg_quote(urlencode($expected['value']), '/');
$key = explode('.', $expected['key']);
$key = (count($key) == 1) ? '[' . current($key) . ']' : ('[' . join('][', $key) . ']');
$key = preg_quote($key, '/');
if (isset($expected['expires'])) {
$date = gmdate('D, d-M-Y H:i:s \G\M\T', strtotime($expected['expires']));
$expires = preg_quote($date, '/');
} else {
$expires = '(?:.+?)';
}
$path = preg_quote($expected['path'], '/');
$pattern = "/^Set\-Cookie:\s{$expected['name']}$key=$value;";
$pattern .= "\sexpires=$expires;\spath=$path/";
$match = false;
foreach ($headers as $header) {
if (preg_match($pattern, $header)) {
$match = true;
continue;
}
}
return compact('match', 'pattern');
}