ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Principal.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Sabre\DAV;
10 
22 
26  const UNAUTHENTICATED = 1;
27 
31  const AUTHENTICATED = 2;
32 
36  const HREF = 3;
37 
41  const ALL = 4;
42 
50  protected $type;
51 
62  function __construct($type, $href = null) {
63 
64  $this->type = $type;
65  if ($type === self::HREF && is_null($href)) {
66  throw new DAV\Exception('The href argument must be specified for the HREF principal type.');
67  }
68  if ($href) {
69  $href = rtrim($href, '/') . '/';
70  parent::__construct($href);
71  }
72 
73  }
74 
80  function getType() {
81 
82  return $this->type;
83 
84  }
85 
86 
106  function xmlSerialize(Writer $writer) {
107 
108  switch ($this->type) {
109 
110  case self::UNAUTHENTICATED :
111  $writer->writeElement('{DAV:}unauthenticated');
112  break;
113  case self::AUTHENTICATED :
114  $writer->writeElement('{DAV:}authenticated');
115  break;
116  case self::HREF :
117  parent::xmlSerialize($writer);
118  break;
119  case self::ALL :
120  $writer->writeElement('{DAV:}all');
121  break;
122  }
123 
124  }
125 
141 
142  switch ($this->type) {
143 
144  case self::UNAUTHENTICATED :
145  return '<em>unauthenticated</em>';
146  case self::AUTHENTICATED :
147  return '<em>authenticated</em>';
148  case self::HREF :
149  return parent::toHtml($html);
150  case self::ALL :
151  return '<em>all</em>';
152  }
153 
154  }
155 
177  static function xmlDeserialize(Reader $reader) {
178 
179  $tree = $reader->parseInnerTree()[0];
180 
181  switch ($tree['name']) {
182  case '{DAV:}unauthenticated' :
183  return new self(self::UNAUTHENTICATED);
184  case '{DAV:}authenticated' :
185  return new self(self::AUTHENTICATED);
186  case '{DAV:}href':
187  return new self(self::HREF, $tree['value']);
188  case '{DAV:}all':
189  return new self(self::ALL);
190  default :
191  throw new BadRequest('Unknown or unsupported principal type: ' . $tree['name']);
192  }
193 
194  }
195 
196 }
parseInnerTree(array $elementMap=null)
Parses all elements below the current element.
Definition: Reader.php:129
const ALL
Everybody, basically.
Definition: Principal.php:41
__construct($type, $href=null)
Creates the property.
Definition: Principal.php:62
Href property.
Definition: Href.php:26
const UNAUTHENTICATED
To specify a not-logged-in user, use the UNAUTHENTICATED principal.
Definition: Principal.php:26
Main Exception class.
Definition: Exception.php:18
static xmlDeserialize(Reader $reader)
The deserialize method is called during xml parsing.
Definition: Principal.php:177
The Reader class expands upon PHP&#39;s built-in XMLReader.
Definition: Reader.php:20
const AUTHENTICATED
To specify any principal that is logged in, use AUTHENTICATED.
Definition: Principal.php:31
xmlSerialize(Writer $writer)
The xmlSerialize method is called during xml writing.
Definition: Principal.php:106
const HREF
Specific principals can be specified with the HREF.
Definition: Principal.php:36
getType()
Returns the principal type.
Definition: Principal.php:80
$html
Definition: example_001.php:87
writeElement($name, $content=null)
Write a full element tag and it&#39;s contents.
Definition: Writer.php:189
toHtml(HtmlOutputHelper $html)
Generate html representation for this value.
Definition: Principal.php:140
The XML Writer class.
Definition: Writer.php:31
This class provides a few utility functions for easily generating HTML for the browser plugin...