3 namespace Drupal\Core\Authentication;
6 * A collector class for authentication providers.
8 class AuthenticationCollector implements AuthenticationCollectorInterface {
11 * Array of all registered authentication providers, keyed by ID.
13 * @var \Drupal\Core\Authentication\AuthenticationProviderInterface[]
18 * Array of all providers and their priority.
22 protected $providerOrders = [];
25 * Sorted list of registered providers.
27 * @var \Drupal\Core\Authentication\AuthenticationProviderInterface[]
29 protected $sortedProviders;
32 * List of providers which are allowed on routes with no _auth option.
36 protected $globalProviders;
41 public function addProvider(AuthenticationProviderInterface $provider, $provider_id, $priority = 0, $global = FALSE) {
42 $this->providers[$provider_id] = $provider;
43 $this->providerOrders[$priority][$provider_id] = $provider;
44 // Force the providers to be re-sorted.
45 $this->sortedProviders = NULL;
48 $this->globalProviders[$provider_id] = TRUE;
55 public function isGlobal($provider_id) {
56 return isset($this->globalProviders[$provider_id]);
62 public function getProvider($provider_id) {
63 return isset($this->providers[$provider_id]) ? $this->providers[$provider_id] : NULL;
69 public function getSortedProviders() {
70 if (!isset($this->sortedProviders)) {
71 // Sort the providers according to priority.
72 krsort($this->providerOrders);
74 // Merge nested providers from $this->providers into $this->sortedProviders.
75 $this->sortedProviders = [];
76 foreach ($this->providerOrders as $providers) {
77 $this->sortedProviders = array_merge($this->sortedProviders, $providers);
81 return $this->sortedProviders;