function ResponseStatus::evaluate

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

Evaluates the condition and returns TRUE or FALSE accordingly.

Return value

bool TRUE if the condition has been met, FALSE otherwise.

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.