Skip to content

Commit

Permalink
Accept providers as input
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Dec 2, 2024
1 parent 636dc0b commit 2fee0b2
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ public static function get_providers_registered() {
}

/**
* Get the classnames for all registered providers.
* Get the classnames for specific providers.
*
* Note some of these providers might not be enabled.
* @param array $providers List of paths to provider class files indexed by class names.
*
* @return array List of provider keys and classnames.
*/
private static function get_providers_classes() {
$providers = self::get_providers_registered();

private static function get_providers_classes( $providers ) {
foreach ( $providers as $provider_key => $path ) {
require_once $path;
if ( ! empty( $path ) && is_readable( $path ) ) {
require_once $path;
}

$class = $provider_key;

Expand Down Expand Up @@ -287,15 +287,13 @@ public static function get_providers() {
}

// Map provider keys to classes so that we can instantiate them.
$providers = array_intersect_key( self::get_providers_classes(), $providers );
$providers = self::get_providers_classes( $providers );

foreach ( $providers as $provider_key => $provider_class ) {
if ( method_exists( $provider_class, 'get_instance' ) ) {
try {
$providers[ $provider_key ] = call_user_func( array( $provider_class, 'get_instance' ) );
} catch ( Exception $e ) {
unset( $providers[ $provider_key ] );
}
try {
$providers[ $provider_key ] = call_user_func( array( $provider_class, 'get_instance' ) );
} catch ( Exception $e ) {
unset( $providers[ $provider_key ] );
}
}

Expand Down

0 comments on commit 2fee0b2

Please sign in to comment.