@@ -56,26 +56,28 @@ public static function getCurrentRequest() : RequestInterface
5656 return $ request ;
5757 }
5858
59- private static $ authenticationSchemesClasses ;
59+ private static $ authenticationSchemeClasses ;
6060
61- public static function setAuthenticationSchemes (array $ authenticationSchemesClasses )
61+ public static function setAuthenticationSchemes (array $ authenticationSchemeClasses )
6262 {
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 ;
7981 }
8082
8183 public static function getFirstAuthorizationHeader (MessageInterface $ message ) : ?AbstractAuthorizationHeader
@@ -92,10 +94,10 @@ public static function getFirstAuthorizationHeader(MessageInterface $message) :
9294 $ type = ucfirst (strtolower (substr ($ header , 0 , $ wsp )));
9395 $ content = substr ($ header , $ wsp + 1 );
9496
95- if (!array_key_exists ($ type , static ::$ authenticationSchemesClasses )) {
97+ if (!array_key_exists ($ type , static ::$ authenticationSchemeClasses )) {
9698 return null ;
9799 }
98- $ authSch = static ::$ authenticationSchemesClasses [$ type ];
100+ $ authSch = static ::$ authenticationSchemeClasses [$ type ];
99101
100102 $ authHeader = new $ authSch ();
101103 return $ authHeader ->withCredentials ($ content );
0 commit comments