This repository was archived by the owner on Sep 19, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed
Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace SimpleSAML \Module \perun \transformers ;
6+
7+ use SimpleSAML \Configuration ;
8+ use SimpleSAML \Module \perun \AttributeTransformer ;
9+
10+ /**
11+ * Get contacts array from lists in contact attributes.
12+ */
13+ class ContactsToArray extends AttributeTransformer
14+ {
15+ private $ contactTypes ;
16+
17+ private $ removeSource ;
18+
19+ private $ outputAttr ;
20+
21+ /**
22+ * @override
23+ */
24+ public function __construct (Configuration $ config )
25+ {
26+ $ this ->contactTypes = $ config ->getArray ('contactTypes ' );
27+ $ this ->removeSource = !$ config ->getBoolean ('keepSource ' , true );
28+ $ this ->outputAttr = $ config ->getString ('outputAttr ' , 'contacts ' );
29+ }
30+
31+ /**
32+ * @override
33+ */
34+ public function transform (array $ attributes )
35+ {
36+ $ result = [];
37+ $ contacts = [];
38+ foreach ($ attributes as $ attribute => $ emailList ) {
39+ if ($ this ->removeSource ) {
40+ $ result [$ attribute ] = null ;
41+ }
42+ if (!empty ($ emailList ) && isset ($ this ->contactTypes [$ attribute ])) {
43+ foreach ($ emailList as $ email ) {
44+ $ contacts [] = [
45+ 'contactType ' => $ this ->contactTypes [$ attribute ],
46+ 'emailAddress ' => $ email ,
47+ ];
48+ }
49+ }
50+ }
51+ // contacts array
52+ return array_merge ($ result , [
53+ $ this ->outputAttr => $ contacts ,
54+ ]);
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments