From a638b14c537592471cab6f2144faf40a3e33e027 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Fri, 12 Nov 2010 11:24:38 +0000
Subject: [PATCH] SAMLParser: Extract contact persons.

Thanks to Sixto Martin for providing this patch.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2628 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Metadata/SAMLParser.php | 50 ++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php
index 1efd6b01a..22557766d 100644
--- a/lib/SimpleSAML/Metadata/SAMLParser.php
+++ b/lib/SimpleSAML/Metadata/SAMLParser.php
@@ -86,6 +86,13 @@ class SimpleSAML_Metadata_SAMLParser {
 	 */
 	private $organizationURL = array();
 	
+
+	/**
+	 * This is an array of the Contact Persons of this entity.
+	 */
+	private $contacts = array();
+
+
 	private $scopes;
 	private $attributes;
 	private $tags;
@@ -149,6 +156,12 @@ class SimpleSAML_Metadata_SAMLParser {
 		if ($entityElement->Organization) {
 			$this->processOrganization($entityElement->Organization);
 		}
+
+		if(!empty($entityElement->ContactPerson)) {
+			foreach($entityElement->ContactPerson as $contact) {
+				$this->processContactPerson($contact);
+			}
+		}
 	}
 
 
@@ -389,6 +402,11 @@ class SimpleSAML_Metadata_SAMLParser {
 			$ret['OrganizationURL'] = $this->organizationURL;
 		}
 
+		/*
+		 * Add contact metadata
+		 */
+		$ret['contacts'] = $this->contacts;
+
 		return $ret;
 	}
 
@@ -891,6 +909,38 @@ class SimpleSAML_Metadata_SAMLParser {
 		$this->organizationURL = $element->OrganizationURL;
 	}
 
+	/**
+	 * Parse and process a ContactPerson element.
+	 *
+	 * @param SAML2_XML_md_ContactPerson $element  The ContactPerson element.
+	 */
+
+	private function processContactPerson(SAML2_XML_md_ContactPerson $element) {
+
+		$contactPerson = array();
+		if(!empty($element->contactType)) {
+			$contactPerson['contactType'] = $element->contactType;
+		}
+		if(!empty($element->Company)) {
+			$contactPerson['company'] = $element->Company;
+		}
+		if(!empty($element->GivenName)) {
+			$contactPerson['givenName'] = $element->GivenName;
+		}
+		if(!empty($element->SurName)) {
+			$contactPerson['surName'] = $element->SurName;
+		}
+		if(!empty($element->EmailAddress)) {
+			$contactPerson['emailAddress'] = $element->EmailAddress;
+		}
+		if(!empty($element->TelephoneNumber)) {
+			$contactPerson['telephoneNumber'] = $element->TelephoneNumber;
+		}
+		if(!empty($contactPerson)) {
+			$this->contacts[] = $contactPerson;
+		}
+	}
+
 
 	/**
 	 * This function parses AttributeConsumerService elements.
-- 
GitLab