Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Authentication / AuthenticationCollector.php
1 <?php
2
3 namespace Drupal\Core\Authentication;
4
5 /**
6  * A collector class for authentication providers.
7  */
8 class AuthenticationCollector implements AuthenticationCollectorInterface {
9
10   /**
11    * Array of all registered authentication providers, keyed by ID.
12    *
13    * @var \Drupal\Core\Authentication\AuthenticationProviderInterface[]
14    */
15   protected $providers;
16
17   /**
18    * Array of all providers and their priority.
19    *
20    * @var array
21    */
22   protected $providerOrders = [];
23
24   /**
25    * Sorted list of registered providers.
26    *
27    * @var \Drupal\Core\Authentication\AuthenticationProviderInterface[]
28    */
29   protected $sortedProviders;
30
31   /**
32    * List of providers which are allowed on routes with no _auth option.
33    *
34    * @var string[]
35    */
36   protected $globalProviders;
37
38   /**
39    * {@inheritdoc}
40    */
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;
46
47     if ($global) {
48       $this->globalProviders[$provider_id] = TRUE;
49     }
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   public function isGlobal($provider_id) {
56     return isset($this->globalProviders[$provider_id]);
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function getProvider($provider_id) {
63     return isset($this->providers[$provider_id]) ? $this->providers[$provider_id] : NULL;
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public function getSortedProviders() {
70     if (!isset($this->sortedProviders)) {
71       // Sort the providers according to priority.
72       krsort($this->providerOrders);
73
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);
78       }
79     }
80
81     return $this->sortedProviders;
82   }
83
84 }