public getCacheControlDirective ( string $name ) : mixed | ||
$name | string | Name of the cache directive, for example "max-age" |
return | mixed |
public function getCacheControlDirective($name)
{
$value = null;
switch ($name) {
case 'public':
$value = $this->cacheDirectives['visibility'] === 'public' ? true : null;
break;
case 'private':
case 'no-cache':
preg_match('/^(' . $name . ')(?:="([^"]+)")?$/', $this->cacheDirectives['visibility'], $matches);
if (!isset($matches[1])) {
$value = null;
} else {
$value = isset($matches[2]) ? $matches[2] : true;
}
break;
case 'no-store':
case 'no-transform':
case 'must-revalidate':
case 'proxy-revalidate':
$value = $this->cacheDirectives[$name] !== '' ? true : null;
break;
case 'max-age':
case 's-maxage':
preg_match('/^(' . $name . ')=(.+)$/', $this->cacheDirectives[$name], $matches);
if (!isset($matches[1])) {
$value = null;
} else {
$value = isset($matches[2]) ? intval($matches[2]) : true;
}
break;
}
return $value;
}
/** * @dataProvider cacheDirectivesAndExampleValues * @test */ public function getCacheControlDirectiveReturnsTheSpecifiedDirectiveValueIfPresent($name, $value) { $headers = new Headers(); $this->assertNull($headers->getCacheControlDirective($name)); if ($value === true) { $headers->setCacheControlDirective($name); } else { $headers->setCacheControlDirective($name, $value); } $this->assertEquals($value, $headers->getCacheControlDirective($name)); }