@@ -71,6 +71,28 @@ private function getUserWithAttributes(string $userName, array $attributes): ?ar
7171 return $ users [0 ];
7272 }
7373
74+ /**
75+ * Calculate the display name.
76+ */
77+ protected function getUserDisplayName (array $ displayNameAttr , array $ userDetails , string $ defaultValue ): string
78+ {
79+ $ displayName = [];
80+ foreach ($ displayNameAttr as $ dnAttr ) {
81+ $ dnComponent = $ this ->getUserResponseProperty ($ userDetails , $ dnAttr , null );
82+ if ($ dnComponent !== null ) {
83+ $ displayName [] = $ dnComponent ;
84+ }
85+ }
86+
87+ if (count ($ displayName ) == 0 ) {
88+ $ displayName = $ defaultValue ;
89+ } else {
90+ $ displayName = implode (' ' , $ displayName );
91+ }
92+
93+ return $ displayName ;
94+ }
95+
7496 /**
7597 * Get the details of a user from LDAP using the given username.
7698 * User found via configurable user filter.
@@ -84,9 +106,9 @@ public function getUserDetails(string $userName): ?array
84106 $ displayNameAttr = $ this ->config ['display_name_attribute ' ];
85107 $ thumbnailAttr = $ this ->config ['thumbnail_attribute ' ];
86108
87- $ user = $ this ->getUserWithAttributes ($ userName , array_filter ([
88- 'cn ' , 'dn ' , $ idAttr , $ emailAttr , $ displayNameAttr , $ thumbnailAttr ,
89- ]));
109+ $ user = $ this ->getUserWithAttributes ($ userName , array_filter (array_merge ( $ displayNameAttr , [
110+ 'cn ' , 'dn ' , $ idAttr , $ emailAttr , $ thumbnailAttr ,
111+ ]))) ;
90112
91113 if (is_null ($ user )) {
92114 return null ;
@@ -95,7 +117,7 @@ public function getUserDetails(string $userName): ?array
95117 $ userCn = $ this ->getUserResponseProperty ($ user , 'cn ' , null );
96118 $ formatted = [
97119 'uid ' => $ this ->getUserResponseProperty ($ user , $ idAttr , $ user ['dn ' ]),
98- 'name ' => $ this ->getUserResponseProperty ( $ user , $ displayNameAttr , $ userCn ),
120+ 'name ' => $ this ->getUserDisplayName ( $ displayNameAttr , $ user , $ userCn ),
99121 'dn ' => $ user ['dn ' ],
100122 'email ' => $ this ->getUserResponseProperty ($ user , $ emailAttr , null ),
101123 'avatar ' => $ thumbnailAttr ? $ this ->getUserResponseProperty ($ user , $ thumbnailAttr , null ) : null ,
0 commit comments