Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
14 / 14
AuthenticationCollector
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
8
100.00% covered (success)
100.00%
14 / 14
 addProvider
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
 isGlobal
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getProvider
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 getSortedProviders
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
6 / 6
<?php
/**
 * @file
 * Contains \Drupal\Core\Authentication\AuthenticationCollector.
 */
namespace Drupal\Core\Authentication;
/**
 * A collector class for authentication providers.
 */
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 isset($this->providers[$provider_id]) ? $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 = [];
      foreach ($this->providerOrders as $providers) {
        $this->sortedProviders = array_merge($this->sortedProviders, $providers);
      }
    }
    return $this->sortedProviders;
  }
}