ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
AttributeConsumingService.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SAML2\XML\md;
4 
6 use SAML2\Utils;
7 
14 {
20  public $index;
21 
27  public $isDefault = null;
28 
36  public $ServiceName = array();
37 
46 
55 
62  public function __construct(\DOMElement $xml = null)
63  {
64  if ($xml === null) {
65  return;
66  }
67 
68  if (!$xml->hasAttribute('index')) {
69  throw new \Exception('Missing index on AttributeConsumingService.');
70  }
71  $this->index = (int) $xml->getAttribute('index');
72 
73  $this->isDefault = Utils::parseBoolean($xml, 'isDefault', null);
74 
75  $this->ServiceName = Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'ServiceName');
76  if (empty($this->ServiceName)) {
77  throw new \Exception('Missing ServiceName in AttributeConsumingService.');
78  }
79 
80  $this->ServiceDescription = Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'ServiceDescription');
81 
82  foreach (Utils::xpQuery($xml, './saml_metadata:RequestedAttribute') as $ra) {
83  $this->RequestedAttribute[] = new RequestedAttribute($ra);
84  }
85  }
86 
93  public function toXML(\DOMElement $parent)
94  {
95  assert(is_int($this->index));
96  assert(is_null($this->isDefault) || is_bool($this->isDefault));
97  assert(is_array($this->ServiceName));
98  assert(is_array($this->ServiceDescription));
99  assert(is_array($this->RequestedAttribute));
100 
101  $doc = $parent->ownerDocument;
102 
103  $e = $doc->createElementNS(Constants::NS_MD, 'md:AttributeConsumingService');
104  $parent->appendChild($e);
105 
106  $e->setAttribute('index', (string) $this->index);
107 
108  if ($this->isDefault === true) {
109  $e->setAttribute('isDefault', 'true');
110  } elseif ($this->isDefault === false) {
111  $e->setAttribute('isDefault', 'false');
112  }
113 
114  Utils::addStrings($e, Constants::NS_MD, 'md:ServiceName', true, $this->ServiceName);
115  Utils::addStrings($e, Constants::NS_MD, 'md:ServiceDescription', true, $this->ServiceDescription);
116 
117  foreach ($this->RequestedAttribute as $ra) {
118  $ra->toXML($e);
119  }
120 
121  return $e;
122  }
123 }
toXML(\DOMElement $parent)
Convert to .
static extractLocalizedStrings(\DOMElement $parent, $namespaceURI, $localName)
Extract localized strings from a set of nodes.
Definition: Utils.php:580
__construct(\DOMElement $xml=null)
Initialize / parse an AttributeConsumingService.
$xml
Definition: metadata.php:240
static addStrings(\DOMElement $parent, $namespace, $name, $localized, array $values)
Append string elements.
Definition: Utils.php:659
static parseBoolean(\DOMElement $node, $attributeName, $default=null)
Parse a boolean attribute.
Definition: Utils.php:276
const NS_MD
The namespace for the SAML 2 metadata.
Definition: Constants.php:225
static xpQuery(\DOMNode $node, $query)
Do an XPath query on an XML node.
Definition: Utils.php:191
Create styles array
The data for the language used.