AccessResultForbidden.php 911 Bytes
Newer Older
1 2 3 4 5 6 7
<?php

namespace Drupal\Core\Access;

/**
 * Value object indicating a forbidden access result, with cacheability metadata.
 */
8 9 10 11 12 13 14 15 16 17 18 19 20
class AccessResultForbidden extends AccessResult implements AccessResultReasonInterface {

  /**
   * The reason why access is forbidden. For use in error messages.
   *
   * @var string|null
   */
  protected $reason;

  /**
   * Constructs a new AccessResultForbidden instance.
   *
   * @param null|string $reason
21
   *   (optional) A message to provide details about this access result.
22 23 24 25 26
   */
  public function __construct($reason = NULL) {
    $this->reason = $reason;
  }

27 28 29 30 31 32 33
  /**
   * {@inheritdoc}
   */
  public function isForbidden() {
    return TRUE;
  }

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  /**
   * {@inheritdoc}
   */
  public function getReason() {
    return $this->reason;
  }

  /**
   * {@inheritdoc}
   */
  public function setReason($reason) {
    $this->reason = $reason;
    return $this;
  }

49
}