@@ -14,32 +14,35 @@ class XmlImporter {
1414
1515 public const OBJECT_PREFIX = '<?xml version="1.0" encoding="UTF-8"?><icalendar xmlns="urn:ietf:params:xml:ns:icalendar-2.0"><vcalendar><components> ' ;
1616 public const OBJECT_SUFFIX = '</components></vcalendar></icalendar> ' ;
17- protected const COMPONENT_TYPES = ['VEVENT ' , 'VTODO ' , 'VJOURNAL ' , 'VTIMEZONE ' ];
17+ private const COMPONENT_TYPES = ['VEVENT ' , 'VTODO ' , 'VJOURNAL ' , 'VTIMEZONE ' ];
1818
19- protected bool $ analyzed = false ;
20- protected array $ structure = ['VCALENDAR ' => [], 'VEVENT ' => [], 'VTODO ' => [], 'VJOURNAL ' => [], 'VTIMEZONE ' => []];
21- protected int $ praseLevel = 0 ;
22- protected array $ prasePath = [];
23- protected ?int $ componentStart = null ;
24- protected ?int $ componentEnd = null ;
25- protected int $ componentLevel = 0 ;
26- protected ?string $ componentId = null ;
27- protected ?string $ componentType = null ;
28- protected bool $ componentIdProperty = false ;
19+ private bool $ analyzed = false ;
20+ private array $ structure = ['VCALENDAR ' => [], 'VEVENT ' => [], 'VTODO ' => [], 'VJOURNAL ' => [], 'VTIMEZONE ' => []];
21+ private int $ praseLevel = 0 ;
22+ private array $ prasePath = [];
23+ private ?int $ componentStart = null ;
24+ private ?int $ componentEnd = null ;
25+ private int $ componentLevel = 0 ;
26+ private ?string $ componentId = null ;
27+ private ?string $ componentType = null ;
28+ private bool $ componentIdProperty = false ;
2929
30+ /**
31+ * @param resource $source
32+ */
3033 public function __construct (
31- protected $ source ,
34+ private $ source ,
3235 ) {
33- // ensure that the source is of the right type
34- if (!is_string ( $ source ) && (! is_resource ($ source ) || get_resource_type ($ source ) !== 'stream ' ) ) {
35- throw new Exception ('Source must be a string or a stream resource ' );
36+ // Ensure that source is a stream resource
37+ if (!is_resource ($ source ) || get_resource_type ($ source ) !== 'stream ' ) {
38+ throw new Exception ('Source must be a stream resource ' );
3639 }
3740 }
3841
3942 /**
4043 * Analyzes the source data and creates a structure of components
4144 */
42- protected function analyze () {
45+ private function analyze () {
4346 $ this ->praseLevel = 0 ;
4447 $ this ->prasePath = [];
4548 $ this ->componentStart = null ;
@@ -53,21 +56,10 @@ protected function analyze() {
5356 xml_set_object ($ parser , $ this );
5457 xml_set_element_handler ($ parser , $ this ->tagStart (...), $ this ->tagEnd (...));
5558 xml_set_default_handler ($ parser , $ this ->tagContents (...));
56- // If the source is resource then prase if in chunks, otherwise just parse the full source
57- if (is_resource ($ this ->source )) {
58- // iterate through the source data chuck by chunk to trigger the handlers
59- @fseek ($ this ->source , 0 );
60- while ($ chunk = fread ($ this ->source , 4096 )) {
61- if (!xml_parse ($ parser , $ chunk , feof ($ this ->source ))) {
62- throw new Exception (
63- xml_error_string (xml_get_error_code ($ parser ))
64- . ' At line: '
65- . xml_get_current_line_number ($ parser )
66- );
67- }
68- }
69- } else {
70- if (!xml_parse ($ parser , $ this ->source , true )) {
59+ // iterate through the source data chuck by chunk to trigger the handlers
60+ @fseek ($ this ->source , 0 );
61+ while ($ chunk = fread ($ this ->source , 4096 )) {
62+ if (!xml_parse ($ parser , $ chunk , feof ($ this ->source ))) {
7163 throw new Exception (
7264 xml_error_string (xml_get_error_code ($ parser ))
7365 . ' At line: '
@@ -82,7 +74,7 @@ protected function analyze() {
8274 /**
8375 * Handles start of tag events from the parser for all tags
8476 */
85- protected function tagStart (XMLParser $ parser , string $ tag , array $ attributes ): void {
77+ private function tagStart (XMLParser $ parser , string $ tag , array $ attributes ): void {
8678 // add the tag to the path tracker and increment depth the level
8779 $ this ->praseLevel ++;
8880 $ this ->prasePath [$ this ->praseLevel ] = $ tag ;
@@ -104,7 +96,7 @@ protected function tagStart(XMLParser $parser, string $tag, array $attributes):
10496 /**
10597 * Handles end of tag events from the parser for all tags
10698 */
107- protected function tagEnd (XMLParser $ parser , string $ tag ): void {
99+ private function tagEnd (XMLParser $ parser , string $ tag ): void {
108100 // if the end tag matched the component type or the component id property
109101 // then add the component to the structure
110102 if ($ tag === 'UID ' || $ tag === 'TZID ' ) {
@@ -142,7 +134,7 @@ protected function tagEnd(XMLParser $parser, string $tag): void {
142134 /**
143135 * Handles tag contents events from the parser for all tags
144136 */
145- protected function tagContents (XMLParser $ parser , string $ data ): void {
137+ private function tagContents (XMLParser $ parser , string $ data ): void {
146138 if ($ this ->componentIdProperty ) {
147139 $ this ->componentId = $ data ;
148140 }
0 commit comments