ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilScormImportParser Class Reference
+ Collaboration diagram for ilScormImportParser:

Public Member Functions

 __construct (DataTypeFactory $data_factory)
 
 parse (string $xmlString)
 

Private Member Functions

 formatError (LibXMLError $error)
 
 formatErrors (LibXMLError ... $errors)
 
 beginLogging ()
 
 addErrors ()
 
 endLogging ()
 

Private Attributes

bool $xml_error_state = false
 
array $error_stack = []
 
DataTypeFactory $df
 

Detailed Description

Definition at line 23 of file class.ilScormImportParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilScormImportParser::__construct ( DataTypeFactory  $data_factory)

Definition at line 30 of file class.ilScormImportParser.php.

31 {
32 $this->df = $data_factory;
33 }

Member Function Documentation

◆ addErrors()

ilScormImportParser::addErrors ( )
private

Definition at line 68 of file class.ilScormImportParser.php.

68 : void
69 {
70 $currentErrors = libxml_get_errors();
71 libxml_clear_errors();
72
73 $level = count($this->error_stack) - 1;
74 $this->error_stack[$level] = array_merge($this->error_stack[$level], $currentErrors);
75 }

Referenced by beginLogging(), and endLogging().

+ Here is the caller graph for this function:

◆ beginLogging()

ilScormImportParser::beginLogging ( )
private

Definition at line 56 of file class.ilScormImportParser.php.

56 : void
57 {
58 if ([] === $this->error_stack) {
59 $this->xml_error_state = libxml_use_internal_errors(true);
60 libxml_clear_errors();
61 } else {
62 $this->addErrors();
63 }
64
65 $this->error_stack[] = [];
66 }

References addErrors().

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ endLogging()

ilScormImportParser::endLogging ( )
private
Returns
LibXMLError[] An array with the LibXMLErrors which has occurred since beginLogging() was called.

Definition at line 80 of file class.ilScormImportParser.php.

80 : array
81 {
82 $this->addErrors();
83
84 $errors = array_pop($this->error_stack);
85
86 if ([] === $this->error_stack) {
87 libxml_use_internal_errors($this->xml_error_state);
88 }
89
90 return $errors;
91 }

References addErrors().

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatError()

ilScormImportParser::formatError ( LibXMLError  $error)
private

Definition at line 35 of file class.ilScormImportParser.php.

35 : string
36 {
37 return implode(',', [
38 'level=' . $error->level,
39 'code=' . $error->code,
40 'line=' . $error->line,
41 'col=' . $error->column,
42 'msg=' . trim($error->message)
43 ]);
44 }

Referenced by formatErrors().

+ Here is the caller graph for this function:

◆ formatErrors()

ilScormImportParser::formatErrors ( LibXMLError ...  $errors)
private

Definition at line 46 of file class.ilScormImportParser.php.

46 : string
47 {
48 $text = '';
49 foreach ($errors as $error) {
50 $text .= $this->formatError($error) . "\n";
51 }
52
53 return $text;
54 }
formatError(LibXMLError $error)

References formatError().

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse()

ilScormImportParser::parse ( string  $xmlString)

Definition at line 93 of file class.ilScormImportParser.php.

94 {
95 try {
96 $this->beginLogging();
97
98 $xml = new SimpleXMLElement($xmlString);
99
100 $errors = $this->endLogging();
101
102 if ($xml->xpath('//SubType')) {
103 return $this->df->ok($xml);
104 }
105
106 $error = new LibXMLError();
107 $error->level = LIBXML_ERR_FATAL;
108 $error->code = 0;
109 $error->message = 'No "SubType" element found';
110 $error->line = 1;
111 $error->column = 0;
112
113 $errors[] = $error;
114
115 return $this->df->error($this->formatErrors(...$errors));
116 } catch (Throwable $e) {
117 return $this->df->error($this->formatErrors(...$this->endLogging()));
118 }
119 }
formatErrors(LibXMLError ... $errors)
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29

References Vendor\Package\$e, beginLogging(), endLogging(), and formatErrors().

+ Here is the call graph for this function:

Field Documentation

◆ $df

DataTypeFactory ilScormImportParser::$df
private

Definition at line 28 of file class.ilScormImportParser.php.

◆ $error_stack

array ilScormImportParser::$error_stack = []
private

Definition at line 27 of file class.ilScormImportParser.php.

◆ $xml_error_state

bool ilScormImportParser::$xml_error_state = false
private

Definition at line 25 of file class.ilScormImportParser.php.


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