ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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.

Referenced by beginLogging(), and endLogging().

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  }
+ Here is the caller graph for this function:

◆ beginLogging()

ilScormImportParser::beginLogging ( )
private

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

References addErrors().

Referenced by parse().

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  }
+ 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.

References $errors, and addErrors().

Referenced by parse().

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  }
$errors
Definition: imgupload.php:65
+ 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.

Referenced by formatErrors().

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  }
+ Here is the caller graph for this function:

◆ formatErrors()

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

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

References formatError().

Referenced by parse().

46  : string
47  {
48  $text = '';
49  foreach ($errors as $error) {
50  $text .= $this->formatError($error) . "\n";
51  }
52 
53  return $text;
54  }
$errors
Definition: imgupload.php:65
formatError(LibXMLError $error)
+ 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.

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

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  }
$errors
Definition: imgupload.php:65
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:14
$xml
Definition: metadata.php:351
formatErrors(LibXMLError ... $errors)
+ 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: