4949 */
5050class AuthorizationProviderFactory
5151{
52+ //All configured options from the webtrees config.ini.php file
53+ private static $ webtrees_config = [];
54+
5255 /**
5356 * Create an OAuth2 authorization provider
5457 *
@@ -61,7 +64,7 @@ public static function make(string $name, string $redirectUri) : ?AuthorizationP
6164 {
6265 $ name_space = str_replace ('\\\\' , '\\' ,__NAMESPACE__ );
6366 $ name_space = str_replace ('Factories ' , 'Provider \\' , $ name_space );
64- $ options = self ::readProviderOptionsFromConfigFile ($ name );
67+ $ options = self ::getProviderOptions ($ name );
6568
6669 //If no options found
6770 if (sizeof ($ options ) === 0 ) {
@@ -110,14 +113,14 @@ public static function getAuthorizatonProviderNames(): array {
110113 }
111114
112115 /**
113- * Read the options of the provider from the webtrees config.ini.php file
116+ * Get the options of a provider
114117 *
115118 * @param string $name Authorization provider name
116119 *
117120 * @return array An array with the options. Empty if options could not be read completely.
118121 */
119122
120- public static function readProviderOptionsFromConfigFile (string $ name ): array {
123+ public static function getProviderOptions (string $ name ): array {
121124
122125 $ options = [];
123126 $ name_space = str_replace ('\\\\' , '\\' ,__NAMESPACE__ );
@@ -132,19 +135,15 @@ public static function readProviderOptionsFromConfigFile(string $name): array {
132135 }
133136 }
134137
135- // Read the configuration settings
136- if (file_exists (Webtrees::CONFIG_FILE )) {
137- $ config = parse_ini_file (Webtrees::CONFIG_FILE );
138- foreach ($ config as $ key => $ value ) {
139- if (strpos ($ key , $ name . '_ ' ) === 0 ) {
140- $ key = str_replace ($ name . '_ ' , '' , $ key );
141- $ options [$ key ] = $ value ;
142- }
138+
139+ // Get the configuration settings from the webtrees configutration
140+ $ config = self ::getWebtreesConfig ();
141+ foreach ($ config as $ key => $ value ) {
142+ if (strpos ($ key , $ name . '_ ' ) === 0 ) {
143+ $ key = str_replace ($ name . '_ ' , '' , $ key );
144+ $ options [$ key ] = $ value ;
143145 }
144146 }
145- else {
146- return [];
147- }
148147
149148 //Return if no options found, i.e. the authorization provider is not configured
150149 if (sizeof ($ options ) === 0 ) {
@@ -162,6 +161,25 @@ public static function readProviderOptionsFromConfigFile(string $name): array {
162161 return $ options ;
163162 }
164163
164+
165+ /**
166+ * Get all options from the webtrees config.ini.php file
167+ *
168+ * @param string $name Authorization provider name
169+ *
170+ * @return array An array with the options. Empty if options could not be read.
171+ */
172+
173+ public static function getWebtreesConfig (): array {
174+
175+ // If not already available, read the configuration settings from the webtrees config file
176+ if (self ::$ webtrees_config === [] && file_exists (Webtrees::CONFIG_FILE )) {
177+ self ::$ webtrees_config = parse_ini_file (Webtrees::CONFIG_FILE );
178+ }
179+
180+ return self ::$ webtrees_config ;
181+ }
182+
165183 /**
166184 * Whether a provider provides enough user data for a webtrees registration, e.g. username and email
167185 *
@@ -205,7 +223,7 @@ public static function getSignInButtonLabels($registration = false): array {
205223
206224 //Remove any providers from list, for which no sufficient config is available, or which do not allow webtrees registration
207225 foreach ($ provider_names as $ class_name => $ provider_name ) {
208- if (self ::readProviderOptionsFromConfigFile ($ provider_name ) === []) {
226+ if (self ::getProviderOptions ($ provider_name ) === []) {
209227 unset($ provider_names [$ class_name ]);
210228 }
211229 if ($ registration && !self ::providerSupportsRegistration ($ provider_name )) {
0 commit comments