summaryrefslogtreecommitdiffstats
path: root/lib/SAML2/XML/md/Organization.php
blob: 3869b042ae5ae7f04116e3a164d3f1ac51ed209f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php

/**
 * Class representing SAML 2 Organization element.
 *
 * @package simpleSAMLphp
 * @version $Id$
 */
class SAML2_XML_md_Organization {

	/**
	 * Extensions on this element.
	 *
	 * Array of extension elements.
	 *
	 * @var array
	 */
	public $Extensions = array();


	/**
	 * The OrganizationName, as an array of language => translation.
	 *
	 * @var array
	 */
	public $OrganizationName = array();


	/**
	 * The OrganizationDisplayName, as an array of language => translation.
	 *
	 * @var array
	 */
	public $OrganizationDisplayName = array();


	/**
	 * The OrganizationURL, as an array of language => translation.
	 *
	 * @var array
	 */
	public $OrganizationURL = array();


	/**
	 * Initialize an Organization element.
	 *
	 * @param DOMElement|NULL $xml  The XML element we should load.
	 */
	public function __construct(DOMElement $xml = NULL) {

		if ($xml === NULL) {
			return;
		}

		$this->Extensions = SAML2_XML_md_Extensions::getList($xml);


		$this->OrganizationName = SAML2_Utils::extractLocalizedStrings($xml, './saml_metadata:OrganizationName');
		if (empty($this->OrganizationName)) {
			$this->OrganizationName = array('invalid' => '');
		}

		$this->OrganizationDisplayName = SAML2_Utils::extractLocalizedStrings($xml, './saml_metadata:OrganizationDisplayName');
		if (empty($this->OrganizationDisplayName)) {
			$this->OrganizationDisplayName = array('invalid' => '');
		}

		$this->OrganizationURL = SAML2_Utils::extractLocalizedStrings($xml, './saml_metadata:OrganizationURL');
		if (empty($this->OrganizationURL)) {
			$this->OrganizationURL = array('invalid' => '');
		}
	}


	/**
	 * Convert this Organization to XML.
	 *
	 * @param DOMElement $parent  The element we should add this organization to.
	 * @return DOMElement  This Organization-element.
	 */
	public function toXML(DOMElement $parent) {
		assert('is_array($this->Extensions)');
		assert('is_array($this->OrganizationName)');
		assert('!empty($this->OrganizationName)');
		assert('is_array($this->OrganizationDisplayName)');
		assert('!empty($this->OrganizationDisplayName)');
		assert('is_array($this->OrganizationURL)');
		assert('!empty($this->OrganizationURL)');

		$doc = $parent->ownerDocument;

		$e = $doc->createElementNS(SAML2_Const::NS_MD, 'md:Organization');
		$parent->appendChild($e);

		SAML2_XML_md_Extensions::addList($e, $this->Extensions);

		SAML2_Utils::addStrings($e, SAML2_Const::NS_MD, 'md:OrganizationName', TRUE, $this->OrganizationName);
		SAML2_Utils::addStrings($e, SAML2_Const::NS_MD, 'md:OrganizationDisplayName', TRUE, $this->OrganizationDisplayName);
		SAML2_Utils::addStrings($e, SAML2_Const::NS_MD, 'md:OrganizationURL', TRUE, $this->OrganizationURL);

		return $e;
	}

}