class AuthenticationCollector

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Authentication/AuthenticationCollector.php \Drupal\Core\Authentication\AuthenticationCollector
  2. 10 core/lib/Drupal/Core/Authentication/AuthenticationCollector.php \Drupal\Core\Authentication\AuthenticationCollector
  3. 11.x core/lib/Drupal/Core/Authentication/AuthenticationCollector.php \Drupal\Core\Authentication\AuthenticationCollector

A collector class for authentication providers.

Hierarchy

Expanded class hierarchy of AuthenticationCollector

2 files declare their use of AuthenticationCollector
AuthenticationCollectorTest.php in core/tests/Drupal/Tests/Core/Authentication/AuthenticationCollectorTest.php
Contains \Drupal\Tests\Core\Authentication\AuthenticationCollectorTest.
AuthenticationManagerTest.php in core/tests/Drupal/Tests/Core/Authentication/AuthenticationManagerTest.php
Contains \Drupal\Tests\Core\Authentication\AuthenticationManagerTest.
1 string reference to 'AuthenticationCollector'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses AuthenticationCollector
authentication_collector in core/core.services.yml
Drupal\Core\Authentication\AuthenticationCollector

File

core/lib/Drupal/Core/Authentication/AuthenticationCollector.php, line 8

Namespace

Drupal\Core\Authentication
View source
class AuthenticationCollector implements AuthenticationCollectorInterface {
    
    /**
     * Array of all registered authentication providers, keyed by ID.
     *
     * @var \Drupal\Core\Authentication\AuthenticationProviderInterface[]
     */
    protected $providers;
    
    /**
     * Array of all providers and their priority.
     *
     * @var array
     */
    protected $providerOrders = [];
    
    /**
     * Sorted list of registered providers.
     *
     * @var \Drupal\Core\Authentication\AuthenticationProviderInterface[]
     */
    protected $sortedProviders;
    
    /**
     * List of providers which are allowed on routes with no _auth option.
     *
     * @var string[]
     */
    protected $globalProviders;
    
    /**
     * {@inheritdoc}
     */
    public function addProvider(AuthenticationProviderInterface $provider, $provider_id, $priority = 0, $global = FALSE) {
        $this->providers[$provider_id] = $provider;
        $this->providerOrders[$priority][$provider_id] = $provider;
        // Force the providers to be re-sorted.
        $this->sortedProviders = NULL;
        if ($global) {
            $this->globalProviders[$provider_id] = TRUE;
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public function isGlobal($provider_id) {
        return isset($this->globalProviders[$provider_id]);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getProvider($provider_id) {
        return $this->providers[$provider_id] ?? NULL;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getSortedProviders() {
        if (!isset($this->sortedProviders)) {
            // Sort the providers according to priority.
            krsort($this->providerOrders);
            // Merge nested providers from $this->providers into $this->sortedProviders.
            $this->sortedProviders = array_merge([], ...$this->providerOrders);
        }
        return $this->sortedProviders;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AuthenticationCollector::$globalProviders protected property List of providers which are allowed on routes with no _auth option.
AuthenticationCollector::$providerOrders protected property Array of all providers and their priority.
AuthenticationCollector::$providers protected property Array of all registered authentication providers, keyed by ID.
AuthenticationCollector::$sortedProviders protected property Sorted list of registered providers.
AuthenticationCollector::addProvider public function Adds a provider to the array of registered providers. Overrides AuthenticationCollectorInterface::addProvider
AuthenticationCollector::getProvider public function Returns an authentication provider. Overrides AuthenticationCollectorInterface::getProvider
AuthenticationCollector::getSortedProviders public function Returns the sorted array of authentication providers. Overrides AuthenticationCollectorInterface::getSortedProviders
AuthenticationCollector::isGlobal public function Returns whether a provider is considered global. Overrides AuthenticationCollectorInterface::isGlobal

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.