@@ -56,26 +56,28 @@ public static function getCurrentRequest() : RequestInterface
56
56
return $ request ;
57
57
}
58
58
59
- private static $ authenticationSchemesClasses ;
59
+ private static $ authenticationSchemeClasses ;
60
60
61
- public static function setAuthenticationSchemes (array $ authenticationSchemesClasses )
61
+ public static function setAuthenticationSchemes (array $ authenticationSchemeClasses )
62
62
{
63
- array_walk ($ authenticationSchemesClasses , function ($ v ) {
64
- if (!class_exists ($ v )) {
65
- throw new InvalidArgumentException ("Class $ v does not exists. " );
66
- }
67
- if (!is_subclass_of ($ v , AbstractAuthorizationHeader::class)) {
68
- throw new InvalidArgumentException (
69
- 'Authentication Schemes classes MUST extends from ' .
70
- AbstractAuthorizationHeader::class
71
- );
72
- }
73
- });
74
- $ types = array_map (function (AbstractAuthorizationHeader $ v ) {
75
- return $ v ::getAuthorizationType ();
76
- }, $ authenticationSchemesClasses );
77
-
78
- static ::$ authenticationSchemesClasses = array_combine ($ types , $ authenticationSchemesClasses );
63
+ foreach ($ authenticationSchemeClasses as $ class ) {
64
+ static ::addAuthenticationScheme ($ class );
65
+ }
66
+ }
67
+
68
+ public static function addAuthenticationScheme (string $ authenticationSchemeClass )
69
+ {
70
+ if (!class_exists ($ authenticationSchemeClass )) {
71
+ throw new InvalidArgumentException (sprintf ('Class %s does not exists. ' , $ authenticationSchemeClass ));
72
+ }
73
+ if (!is_subclass_of ($ authenticationSchemeClass , AbstractAuthorizationHeader::class)) {
74
+ throw new InvalidArgumentException (
75
+ 'Authentication Scheme class MUST extend from ' .
76
+ AbstractAuthorizationHeader::class
77
+ );
78
+ }
79
+ $ type = $ authenticationSchemeClass ::getAuthorizationType ();
80
+ static ::$ authenticationSchemeClasses [$ type ] = $ authenticationSchemeClass ;
79
81
}
80
82
81
83
public static function getFirstAuthorizationHeader (MessageInterface $ message ) : ?AbstractAuthorizationHeader
@@ -92,10 +94,10 @@ public static function getFirstAuthorizationHeader(MessageInterface $message) :
92
94
$ type = ucfirst (strtolower (substr ($ header , 0 , $ wsp )));
93
95
$ content = substr ($ header , $ wsp + 1 );
94
96
95
- if (!array_key_exists ($ type , static ::$ authenticationSchemesClasses )) {
97
+ if (!array_key_exists ($ type , static ::$ authenticationSchemeClasses )) {
96
98
return null ;
97
99
}
98
- $ authSch = static ::$ authenticationSchemesClasses [$ type ];
100
+ $ authSch = static ::$ authenticationSchemeClasses [$ type ];
99
101
100
102
$ authHeader = new $ authSch ();
101
103
return $ authHeader ->withCredentials ($ content );
0 commit comments