interface AccessResultReasonInterface implements AccessResultInterface (View source)

Interface for access result value objects with stored reason for developers.

For example, a developer can specify the reason for forbidden access:

Methods

bool
isAllowed()

Checks whether this access result indicates access is explicitly allowed.

bool
isForbidden()

Checks whether this access result indicates access is explicitly forbidden.

bool
isNeutral()

Checks whether this access result indicates access is not yet determined.

orIf(AccessResultInterface $other)

Combine this access result with another using OR.

andIf(AccessResultInterface $other)

Combine this access result with another using AND.

string
getReason()

Gets the reason for this access result.

setReason($reason)

Sets the reason for this access result.

Details

bool isAllowed()

Checks whether this access result indicates access is explicitly allowed.

Return Value

bool

When TRUE then isForbidden() and isNeutral() are FALSE.

bool isForbidden()

Checks whether this access result indicates access is explicitly forbidden.

This is a kill switch — both orIf() and andIf() will result in isForbidden() if either results are isForbidden().

Return Value

bool

When TRUE then isAllowed() and isNeutral() are FALSE.

bool isNeutral()

Checks whether this access result indicates access is not yet determined.

Return Value

bool

When TRUE then isAllowed() and isForbidden() are FALSE.

AccessResultInterface orIf(AccessResultInterface $other)

Combine this access result with another using OR.

When ORing two access results, the result is:

  • isForbidden() in either ⇒ isForbidden()
  • otherwise if isAllowed() in either ⇒ isAllowed()
  • otherwise both must be isNeutral() ⇒ isNeutral()

Truth table:

Parameters

AccessResultInterface $other

The other access result to OR this one with.

Return Value

AccessResultInterface

AccessResultInterface andIf(AccessResultInterface $other)

Combine this access result with another using AND.

When ANDing two access results, the result is:

  • isForbidden() in either ⇒ isForbidden()
  • otherwise, if isAllowed() in both ⇒ isAllowed()
  • otherwise, one of them is isNeutral() ⇒ isNeutral()

Truth table:

Parameters

AccessResultInterface $other

The other access result to AND this one with.

Return Value

AccessResultInterface

string getReason()

Gets the reason for this access result.

Return Value

string

The reason of this access result or an empty string if no reason is provided.

AccessResultInterface setReason($reason)

Sets the reason for this access result.

Parameters

$reason

string|null The reason of this access result or NULL if no reason is provided.

Return Value

AccessResultInterface

The access result instance.