Neos\Flow\Http\Headers::getCacheControlDirective PHP Method

getCacheControlDirective() public method

If the cache directive is not present, NULL is returned. If the specified directive is present but contains no value, this method returns TRUE. Finally, if the directive is present and does contain a value, the value is returned.
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;
    }

Usage Example

コード例 #1
0
 /**
  * @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));
 }