function ResponseStatus::evaluate

Same name and namespace in other branches
  1. 10 core/modules/system/src/Plugin/Condition/ResponseStatus.php \Drupal\system\Plugin\Condition\ResponseStatus::evaluate()

Overrides ConditionInterface::evaluate

File

core/modules/system/src/Plugin/Condition/ResponseStatus.php, line 104

Class

ResponseStatus
Provides a 'Response status' condition.

Namespace

Drupal\system\Plugin\Condition

Code

public function evaluate() : bool {
    $allowed_codes = $this->configuration['status_codes'];
    if (empty($allowed_codes)) {
        return TRUE;
    }
    $exception = $this->requestStack
        ->getCurrentRequest()->attributes
        ->get('exception');
    if ($exception) {
        return $exception instanceof HttpExceptionInterface && in_array($exception->getStatusCode(), $allowed_codes, TRUE);
    }
    return in_array(Response::HTTP_OK, $allowed_codes, TRUE);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.