ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Keywords.php
Go to the documentation of this file.
1 <?php
2 
3 namespace SAML2\XML\mdui;
4 
11 class Keywords
12 {
20  public $Keywords;
21 
27  public $lang;
28 
35  public function __construct(\DOMElement $xml = null)
36  {
37  if ($xml === null) {
38  return;
39  }
40 
41  if (!$xml->hasAttribute('xml:lang')) {
42  throw new \Exception('Missing lang on Keywords.');
43  }
44  if (!is_string($xml->textContent) || !strlen($xml->textContent)) {
45  throw new \Exception('Missing value for Keywords.');
46  }
47  $this->Keywords = array();
48  foreach (explode(' ', $xml->textContent) as $keyword) {
49  $this->Keywords[] = str_replace('+', ' ', $keyword);
50  }
51  $this->lang = $xml->getAttribute('xml:lang');
52  }
53 
61  public function toXML(\DOMElement $parent)
62  {
63  assert(is_string($this->lang));
64  assert(is_array($this->Keywords));
65 
66  $doc = $parent->ownerDocument;
67 
68  $e = $doc->createElementNS(Common::NS, 'mdui:Keywords');
69  $e->setAttribute('xml:lang', $this->lang);
70  $value = '';
71  foreach ($this->Keywords as $keyword) {
72  if (strpos($keyword, "+") !== false) {
73  throw new \Exception('Keywords may not contain a "+" character.');
74  }
75  $value .= str_replace(' ', '+', $keyword) . ' ';
76  }
77  $value = rtrim($value);
78  $e->appendChild($doc->createTextNode($value));
79  $parent->appendChild($e);
80 
81  return $e;
82  }
83 }
toXML(\DOMElement $parent)
Convert this Keywords to XML.
Definition: Keywords.php:61
__construct(\DOMElement $xml=null)
Initialize a Keywords.
Definition: Keywords.php:35