ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\VObject\Parser\XML Class Reference

XML Parser. More...

+ Inheritance diagram for Sabre\VObject\Parser\XML:
+ Collaboration diagram for Sabre\VObject\Parser\XML:

Public Member Functions

 __construct ($input=null, $options=0)
 Creates the parser. More...
 
 parse ($input=null, $options=0)
 Parse xCal or xCard. More...
 
 setInput ($input)
 Sets the input data. More...
 
- Public Member Functions inherited from Sabre\VObject\Parser\Parser
 __construct ($input=null, $options=0)
 Creates the parser. More...
 
 parse ($input=null, $options=0)
 This method starts the parsing process. More...
 
 setInput ($input)
 Sets the input data. More...
 

Data Fields

const XCAL_NAMESPACE = 'urn:ietf:params:xml:ns:icalendar-2.0'
 
const XCARD_NAMESPACE = 'urn:ietf:params:xml:ns:vcard-4.0'
 
- Data Fields inherited from Sabre\VObject\Parser\Parser
const OPTION_FORGIVING = 1
 Turning on this option makes the parser more forgiving. More...
 
const OPTION_IGNORE_INVALID_LINES = 2
 If this option is turned on, any lines we cannot parse will be ignored by the reader. More...
 

Protected Member Functions

 parseVCalendarComponents (Component $parentComponent)
 Parse a xCalendar component. More...
 
 parseVCardComponents (Component $parentComponent)
 Parse a xCard component. More...
 
 parseProperties (Component $parentComponent, $propertyNamePrefix='')
 Parse xCalendar and xCard properties. More...
 
 parseComponent (Component $parentComponent)
 Parse a component. More...
 
 createProperty (Component $parentComponent, $name, $parameters, $type, $value)
 Create a property. More...
 

Static Protected Member Functions

static getTagName ($clarkedTagName)
 Get tag name from a Clark notation. More...
 

Protected Attributes

 $input
 
 $root
 
- Protected Attributes inherited from Sabre\VObject\Parser\Parser
 $options
 

Private Attributes

 $pointer
 

Detailed Description

XML Parser.

This parser parses both the xCal and xCard formats.

Author
Ivan Enderlin http://sabre.io/license/ Modified BSD License

Definition at line 21 of file XML.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\VObject\Parser\XML::__construct (   $input = null,
  $options = 0 
)

Creates the parser.

Optionally, it's possible to parse the input stream here.

Parameters
mixed$input
int$optionsAny parser options (OPTION constants).
Returns
void

Definition at line 57 of file XML.php.

References Sabre\VObject\Parser\XML\$input, and Sabre\VObject\Parser\Parser\$options.

57  {
58 
59  if (0 === $options) {
60  $options = parent::OPTION_FORGIVING;
61  }
62 
63  parent::__construct($input, $options);
64 
65  }

Member Function Documentation

◆ createProperty()

Sabre\VObject\Parser\XML::createProperty ( Component  $parentComponent,
  $name,
  $parameters,
  $type,
  $value 
)
protected

Create a property.

Parameters
Component$parentComponent
string$name
array$parameters
string$type
mixed$value
Returns
void

Definition at line 373 of file XML.php.

References $name, $type, and Sabre\VObject\Component\add().

Referenced by Sabre\VObject\Parser\XML\parseProperties().

373  {
374 
375  $property = $this->root->createProperty(
376  $name,
377  null,
378  $parameters,
379  $type
380  );
381  $parentComponent->add($property);
382  $property->setXmlValue($value);
383 
384  }
$type
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTagName()

static Sabre\VObject\Parser\XML::getTagName (   $clarkedTagName)
staticprotected

Get tag name from a Clark notation.

Parameters
string$clarkedTagName
Returns
string

Definition at line 422 of file XML.php.

References Sabre\Xml\Service\parseClarkNotation().

422  {
423 
424  list(, $tagName) = SabreXml\Service::parseClarkNotation($clarkedTagName);
425  return $tagName;
426 
427  }
static parseClarkNotation($str)
Parses a clark-notation string, and returns the namespace and element name components.
Definition: Service.php:274
+ Here is the call graph for this function:

◆ parse()

Sabre\VObject\Parser\XML::parse (   $input = null,
  $options = 0 
)

Parse xCal or xCard.

Parameters
resource | string$input
int$options
Exceptions

Definition at line 77 of file XML.php.

References Sabre\VObject\Parser\XML\$input, Sabre\VObject\Parser\Parser\$options, Sabre\VObject\Parser\XML\$root, input, Sabre\VObject\Parser\XML\parseVCalendarComponents(), Sabre\VObject\Parser\XML\parseVCardComponents(), and Sabre\VObject\Parser\XML\setInput().

77  {
78 
79  if (!is_null($input)) {
80  $this->setInput($input);
81  }
82 
83  if (0 !== $options) {
84  $this->options = $options;
85  }
86 
87  if (is_null($this->input)) {
88  throw new EofException('End of input stream, or no input supplied');
89  }
90 
91  switch ($this->input['name']) {
92 
93  case '{' . self::XCAL_NAMESPACE . '}icalendar':
94  $this->root = new VCalendar([], false);
95  $this->pointer = &$this->input['value'][0];
96  $this->parseVCalendarComponents($this->root);
97  break;
98 
99  case '{' . self::XCARD_NAMESPACE . '}vcards':
100  foreach ($this->input['value'] as &$vCard) {
101 
102  $this->root = new VCard(['version' => '4.0'], false);
103  $this->pointer = &$vCard;
104  $this->parseVCardComponents($this->root);
105 
106  // We just parse the first <vcard /> element.
107  break;
108 
109  }
110  break;
111 
112  default:
113  throw new ParseException('Unsupported XML standard');
114 
115  }
116 
117  return $this->root;
118  }
setInput($input)
Sets the input data.
Definition: XML.php:393
input
Definition: langcheck.php:166
parseVCalendarComponents(Component $parentComponent)
Parse a xCalendar component.
Definition: XML.php:127
parseVCardComponents(Component $parentComponent)
Parse a xCard component.
Definition: XML.php:154
+ Here is the call graph for this function:

◆ parseComponent()

Sabre\VObject\Parser\XML::parseComponent ( Component  $parentComponent)
protected

Parse a component.

Parameters
Component$parentComponent
Returns
void

Definition at line 340 of file XML.php.

References Sabre\VObject\Component\add(), and Sabre\VObject\Parser\XML\parseVCalendarComponents().

Referenced by Sabre\VObject\Parser\XML\parseVCalendarComponents().

340  {
341 
342  $components = $this->pointer['value'] ?: [];
343 
344  foreach ($components as $component) {
345 
346  $componentName = static::getTagName($component['name']);
347  $currentComponent = $this->root->createComponent(
348  $componentName,
349  null,
350  false
351  );
352 
353  $this->pointer = &$component;
354  $this->parseVCalendarComponents($currentComponent);
355 
356  $parentComponent->add($currentComponent);
357 
358  }
359 
360  }
parseVCalendarComponents(Component $parentComponent)
Parse a xCalendar component.
Definition: XML.php:127
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseProperties()

Sabre\VObject\Parser\XML::parseProperties ( Component  $parentComponent,
  $propertyNamePrefix = '' 
)
protected

Parse xCalendar and xCard properties.

Parameters
Component$parentComponent
string$propertyNamePrefix
Returns
void

Definition at line 169 of file XML.php.

References $i, $namespace, Sabre\VObject\Parser\XML\createProperty(), and Sabre\Xml\Service\parseClarkNotation().

Referenced by Sabre\VObject\Parser\XML\parseVCalendarComponents(), and Sabre\VObject\Parser\XML\parseVCardComponents().

169  {
170 
171  foreach ($this->pointer ?: [] as $xmlProperty) {
172 
173  list($namespace, $tagName) = SabreXml\Service::parseClarkNotation($xmlProperty['name']);
174 
175  $propertyName = $tagName;
176  $propertyValue = [];
177  $propertyParameters = [];
178  $propertyType = 'text';
179 
180  // A property which is not part of the standard.
181  if ($namespace !== self::XCAL_NAMESPACE
182  && $namespace !== self::XCARD_NAMESPACE) {
183 
184  $propertyName = 'xml';
185  $value = '<' . $tagName . ' xmlns="' . $namespace . '"';
186 
187  foreach ($xmlProperty['attributes'] as $attributeName => $attributeValue) {
188  $value .= ' ' . $attributeName . '="' . str_replace('"', '\"', $attributeValue) . '"';
189  }
190 
191  $value .= '>' . $xmlProperty['value'] . '</' . $tagName . '>';
192 
193  $propertyValue = [$value];
194 
195  $this->createProperty(
196  $parentComponent,
197  $propertyName,
198  $propertyParameters,
199  $propertyType,
200  $propertyValue
201  );
202 
203  continue;
204  }
205 
206  // xCard group.
207  if ($propertyName === 'group') {
208 
209  if (!isset($xmlProperty['attributes']['name'])) {
210  continue;
211  }
212 
213  $this->pointer = &$xmlProperty['value'];
214  $this->parseProperties(
215  $parentComponent,
216  strtoupper($xmlProperty['attributes']['name']) . '.'
217  );
218 
219  continue;
220 
221  }
222 
223  // Collect parameters.
224  foreach ($xmlProperty['value'] as $i => $xmlPropertyChild) {
225 
226  if (!is_array($xmlPropertyChild)
227  || 'parameters' !== static::getTagName($xmlPropertyChild['name']))
228  continue;
229 
230  $xmlParameters = $xmlPropertyChild['value'];
231 
232  foreach ($xmlParameters as $xmlParameter) {
233 
234  $propertyParameterValues = [];
235 
236  foreach ($xmlParameter['value'] as $xmlParameterValues) {
237  $propertyParameterValues[] = $xmlParameterValues['value'];
238  }
239 
240  $propertyParameters[static::getTagName($xmlParameter['name'])]
241  = implode(',', $propertyParameterValues);
242 
243  }
244 
245  array_splice($xmlProperty['value'], $i, 1);
246 
247  }
248 
249  $propertyNameExtended = ($this->root instanceof VCalendar
250  ? 'xcal'
251  : 'xcard') . ':' . $propertyName;
252 
253  switch ($propertyNameExtended) {
254 
255  case 'xcal:geo':
256  $propertyType = 'float';
257  $propertyValue['latitude'] = 0;
258  $propertyValue['longitude'] = 0;
259 
260  foreach ($xmlProperty['value'] as $xmlRequestChild) {
261  $propertyValue[static::getTagName($xmlRequestChild['name'])]
262  = $xmlRequestChild['value'];
263  }
264  break;
265 
266  case 'xcal:request-status':
267  $propertyType = 'text';
268 
269  foreach ($xmlProperty['value'] as $xmlRequestChild) {
270  $propertyValue[static::getTagName($xmlRequestChild['name'])]
271  = $xmlRequestChild['value'];
272  }
273  break;
274 
275  case 'xcal:freebusy':
276  $propertyType = 'freebusy';
277  // We don't break because we only want to set
278  // another property type.
279 
280  case 'xcal:categories':
281  case 'xcal:resources':
282  case 'xcal:exdate':
283  foreach ($xmlProperty['value'] as $specialChild) {
284  $propertyValue[static::getTagName($specialChild['name'])]
285  = $specialChild['value'];
286  }
287  break;
288 
289  case 'xcal:rdate':
290  $propertyType = 'date-time';
291 
292  foreach ($xmlProperty['value'] as $specialChild) {
293 
294  $tagName = static::getTagName($specialChild['name']);
295 
296  if ('period' === $tagName) {
297 
298  $propertyParameters['value'] = 'PERIOD';
299  $propertyValue[] = implode('/', $specialChild['value']);
300 
301  }
302  else {
303  $propertyValue[] = $specialChild['value'];
304  }
305  }
306  break;
307 
308  default:
309  $propertyType = static::getTagName($xmlProperty['value'][0]['name']);
310 
311  foreach ($xmlProperty['value'] as $value) {
312  $propertyValue[] = $value['value'];
313  }
314 
315  if ('date' === $propertyType) {
316  $propertyParameters['value'] = 'DATE';
317  }
318  break;
319  }
320 
321  $this->createProperty(
322  $parentComponent,
323  $propertyNamePrefix . $propertyName,
324  $propertyParameters,
325  $propertyType,
326  $propertyValue
327  );
328 
329  }
330 
331  }
if($err=$client->getError()) $namespace
createProperty(Component $parentComponent, $name, $parameters, $type, $value)
Create a property.
Definition: XML.php:373
static parseClarkNotation($str)
Parses a clark-notation string, and returns the namespace and element name components.
Definition: Service.php:274
$i
Definition: disco.tpl.php:19
parseProperties(Component $parentComponent, $propertyNamePrefix='')
Parse xCalendar and xCard properties.
Definition: XML.php:169
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseVCalendarComponents()

Sabre\VObject\Parser\XML::parseVCalendarComponents ( Component  $parentComponent)
protected

Parse a xCalendar component.

Parameters
Component$parentComponent
Returns
void

Definition at line 127 of file XML.php.

References Sabre\VObject\Parser\XML\parseComponent(), and Sabre\VObject\Parser\XML\parseProperties().

Referenced by Sabre\VObject\Parser\XML\parse(), and Sabre\VObject\Parser\XML\parseComponent().

127  {
128 
129  foreach ($this->pointer['value'] ?: [] as $children) {
130 
131  switch (static::getTagName($children['name'])) {
132 
133  case 'properties':
134  $this->pointer = &$children['value'];
135  $this->parseProperties($parentComponent);
136  break;
137 
138  case 'components':
139  $this->pointer = &$children;
140  $this->parseComponent($parentComponent);
141  break;
142  }
143  }
144 
145  }
parseComponent(Component $parentComponent)
Parse a component.
Definition: XML.php:340
parseProperties(Component $parentComponent, $propertyNamePrefix='')
Parse xCalendar and xCard properties.
Definition: XML.php:169
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseVCardComponents()

Sabre\VObject\Parser\XML::parseVCardComponents ( Component  $parentComponent)
protected

Parse a xCard component.

Parameters
Component$parentComponent
Returns
void

Definition at line 154 of file XML.php.

References Sabre\VObject\Parser\XML\parseProperties().

Referenced by Sabre\VObject\Parser\XML\parse().

154  {
155 
156  $this->pointer = &$this->pointer['value'];
157  $this->parseProperties($parentComponent);
158 
159  }
parseProperties(Component $parentComponent, $propertyNamePrefix='')
Parse xCalendar and xCard properties.
Definition: XML.php:169
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setInput()

Sabre\VObject\Parser\XML::setInput (   $input)

Sets the input data.

Parameters
resource | string$input
Returns
void

Definition at line 393 of file XML.php.

References Sabre\VObject\Parser\XML\$input, $reader, and input.

Referenced by Sabre\VObject\Parser\XML\parse().

393  {
394 
395  if (is_resource($input)) {
396  $input = stream_get_contents($input);
397  }
398 
399  if (is_string($input)) {
400 
401  $reader = new SabreXml\Reader();
402  $reader->elementMap['{' . self::XCAL_NAMESPACE . '}period']
403  = 'Sabre\VObject\Parser\XML\Element\KeyValue';
404  $reader->elementMap['{' . self::XCAL_NAMESPACE . '}recur']
405  = 'Sabre\VObject\Parser\XML\Element\KeyValue';
406  $reader->xml($input);
407  $input = $reader->parse();
408 
409  }
410 
411  $this->input = $input;
412 
413  }
The Reader class expands upon PHP&#39;s built-in XMLReader.
Definition: Reader.php:20
input
Definition: langcheck.php:166
+ Here is the caller graph for this function:

Field Documentation

◆ $input

Sabre\VObject\Parser\XML::$input
protected

◆ $pointer

Sabre\VObject\Parser\XML::$pointer
private

Definition at line 38 of file XML.php.

◆ $root

Sabre\VObject\Parser\XML::$root
protected

Definition at line 45 of file XML.php.

Referenced by Sabre\VObject\Parser\XML\parse().

◆ XCAL_NAMESPACE

const Sabre\VObject\Parser\XML::XCAL_NAMESPACE = 'urn:ietf:params:xml:ns:icalendar-2.0'

Definition at line 23 of file XML.php.

◆ XCARD_NAMESPACE

const Sabre\VObject\Parser\XML::XCARD_NAMESPACE = 'urn:ietf:params:xml:ns:vcard-4.0'

Definition at line 24 of file XML.php.


The documentation for this class was generated from the following file: