ILIAS  release_8 Revision v8.24
class.ilSaxController.php
Go to the documentation of this file.
1<?php
2
3/******************************************************************************
4 *
5 * This file is part of ILIAS, a powerful learning management system.
6 *
7 * ILIAS is licensed with the GPL-3.0, you should have received a copy
8 * of said license along with the source code.
9 *
10 * If this is not the case or you just want to try ILIAS, you'll find
11 * us at:
12 * https://www.ilias.de
13 * https://github.com/ILIAS-eLearning
14 *
15 *****************************************************************************/
24{
26 protected array $element_handlers = [];
27 protected array $handlers_in_use = [];
31 protected $handler_in_use = null;
33
39 public function setHandlers($a_xml_parser): void
40 {
41 xml_set_object($a_xml_parser, $this);
42 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
43 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
44 }
45
49 public function setDefaultElementHandler(ilSaxSubsetParser $a_default_parser): void
50 {
51 $this->default_handler = $a_default_parser;
52 }
53
58 public function setElementHandler(ilSaxSubsetParser $a_parser, string $a_element): void
59 {
60 $this->element_handlers[$a_element] = $a_parser;
61 $this->handlers_in_use[$a_element] = false;
62 }
63
72 public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs): void
73 {
74 if (isset($this->element_handlers[$a_name]) or $this->handler_in_use) {
75 if (!$this->handler_in_use) {
76 $this->handler_in_use = $this->element_handlers[$a_name];
77 }
78 // Forward to handler
79 $this->current_handler = $this->handler_in_use;
80 $this->current_handler->handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
81 return;
82 }
83 // Call default handler
84 $this->handler_in_use = false;
85 $this->current_handler = $this->default_handler;
86 $this->default_handler->handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
87 }
88
95 public function handlerEndTag($a_xml_parser, string $a_name): void
96 {
97 if (isset($this->element_handlers[$a_name])) {
98 $this->handler_in_use = false;
99 $this->current_handler = $this->element_handlers[$a_name];
100 $this->element_handlers[$a_name]->handlerEndTag($a_xml_parser, $a_name);
101 return;
102 } elseif ($this->handler_in_use) {
103 $this->current_handler = $this->handler_in_use;
104 $this->current_handler->handlerEndTag($a_xml_parser, $a_name);
105 return;
106 }
107 $this->handler_in_use = false;
108 $this->current_handler = $this->default_handler;
109 $this->default_handler->handlerEndTag($a_xml_parser, $a_name);
110 }
111
118 public function handlerCharacterData(
119 $a_xml_parser,
120 string $a_data
121 ): void {
122 $this->current_handler->handlerCharacterData(
123 $a_xml_parser,
124 $a_data
125 );
126 }
127}
Controller class for sax element handlers.
ilSaxSubsetParser $default_handler
handlerEndTag($a_xml_parser, string $a_name)
handler for end of element
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
default handlerBeginTag
ilSaxSubsetParser $current_handler
setDefaultElementHandler(ilSaxSubsetParser $a_default_parser)
Set default element handler.
handlerCharacterData( $a_xml_parser, string $a_data)
handler for character data
setHandlers($a_xml_parser)
Set handlers.
setElementHandler(ilSaxSubsetParser $a_parser, string $a_element)
Interface definition for sax subset parsers.
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
Start element handler.
handlerEndTag($a_xml_parser, string $a_name)
End element handler.