ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSaxController.php
Go to the documentation of this file.
1<?php
2
27{
29 protected array $element_handlers = [];
30 protected array $handlers_in_use = [];
34 protected $handler_in_use = null;
36
42 public function setHandlers($a_xml_parser): void
43 {
44 xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
45 xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
46 }
47
51 public function setDefaultElementHandler(ilSaxSubsetParser $a_default_parser): void
52 {
53 $this->default_handler = $a_default_parser;
54 }
55
60 public function setElementHandler(ilSaxSubsetParser $a_parser, string $a_element): void
61 {
62 $this->element_handlers[$a_element] = $a_parser;
63 $this->handlers_in_use[$a_element] = false;
64 }
65
74 public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs): void
75 {
76 if (isset($this->element_handlers[$a_name]) or $this->handler_in_use) {
77 if (!$this->handler_in_use) {
78 $this->handler_in_use = $this->element_handlers[$a_name];
79 }
80 // Forward to handler
81 $this->current_handler = $this->handler_in_use;
82 $this->current_handler->handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
83 return;
84 }
85 // Call default handler
86 $this->handler_in_use = false;
87 $this->current_handler = $this->default_handler;
88 $this->default_handler->handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
89 }
90
97 public function handlerEndTag($a_xml_parser, string $a_name): void
98 {
99 if (isset($this->element_handlers[$a_name])) {
100 $this->handler_in_use = false;
101 $this->current_handler = $this->element_handlers[$a_name];
102 $this->element_handlers[$a_name]->handlerEndTag($a_xml_parser, $a_name);
103 return;
104 } elseif ($this->handler_in_use) {
105 $this->current_handler = $this->handler_in_use;
106 $this->current_handler->handlerEndTag($a_xml_parser, $a_name);
107 return;
108 }
109 $this->handler_in_use = false;
110 $this->current_handler = $this->default_handler;
111 $this->default_handler->handlerEndTag($a_xml_parser, $a_name);
112 }
113
120 public function handlerCharacterData(
121 $a_xml_parser,
122 string $a_data
123 ): void {
124 $this->current_handler->handlerCharacterData(
125 $a_xml_parser,
126 $a_data
127 );
128 }
129}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
Start element handler.
handlerEndTag($a_xml_parser, string $a_name)
End element handler.