Back to Rule class

Method allow

public mixed
allow
(mixed $identities)
Checks that this action can be performed by an identity.
Parameters
  • mixed $identities An integer or array of integers representing the identities to check.
Returns
  • mixed True if allowed, false for an explicit deny, null for an implicit deny.
Since
  • 1.7.0
Class: Rule
Project: Joomla

Method allow - Source code

/**
 * Checks that this action can be performed by an identity.
 *
 * The identity is an integer where +ve represents a user group,
 * and -ve represents a user.
 *
 * @param   mixed  $identities  An integer or array of integers representing the identities to check.
 *
 * @return  mixed  True if allowed, false for an explicit deny, null for an implicit deny.
 *
 * @since   1.7.0
 */
public function allow($identities)
{
    // Implicit deny by default.
    $result = null;
    // Check that the inputs are valid.
    if (!empty($identities)) {
        if (!\is_array($identities)) {
            $identities = array($identities);
        }
        foreach ($identities as $identity) {
            // Technically the identity just needs to be unique.
            $identity = (int) $identity;
            // Check if the identity is known.
            if (isset($this->data[$identity])) {
                $result = (bool) $this->data[$identity];
                // An explicit deny wins.
                if ($result === false) {
                    break;
                }
            }
        }
    }
    return $result;
}