You are here

public function CheckProvider::loadCheck in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Access/CheckProvider.php \Drupal\Core\Access\CheckProvider::loadCheck()

Lazy-loads access check services.

Parameters

string $service_id: The service id of the access check service to load.

Return value

callable A callable access check.

Throws

\InvalidArgumentException Thrown when the service hasn't been registered in addCheckService().

\Drupal\Core\Access\AccessException Thrown when the service doesn't implement the required interface.

Overrides CheckProviderInterface::loadCheck

1 call to CheckProvider::loadCheck()
CheckProvider::loadDynamicRequirementMap in core/lib/Drupal/Core/Access/CheckProvider.php
Compiles a mapping of requirement keys to access checker service IDs.

File

core/lib/Drupal/Core/Access/CheckProvider.php, line 96
Contains \Drupal\Core\Access\CheckProvider.

Class

CheckProvider
Loads access checkers from the container.

Namespace

Drupal\Core\Access

Code

public function loadCheck($service_id) {
  if (empty($this->checks[$service_id])) {
    if (!in_array($service_id, $this->checkIds)) {
      throw new \InvalidArgumentException(sprintf('No check has been registered for %s', $service_id));
    }
    $check = $this->container
      ->get($service_id);
    if (!$check instanceof AccessInterface) {
      throw new AccessException('All access checks must implement AccessInterface.');
    }
    if (!is_callable(array(
      $check,
      $this->checkMethods[$service_id],
    ))) {
      throw new AccessException(sprintf('Access check method %s in service %s must be callable.', $this->checkMethods[$service_id], $service_id));
    }
    $this->checks[$service_id] = $check;
  }
  return [
    $this->checks[$service_id],
    $this->checkMethods[$service_id],
  ];
}