CheckProvider::loadCheck

public CheckProvider::loadCheck($service_id)

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

File

core/lib/Drupal/Core/Access/CheckProvider.php, line 94

Class

CheckProvider
Loads access checkers from the container.

Namespace

Drupal\Core\Access

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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]];
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.