ILIAS  release_8 Revision v8.23
ilXMLChecker Class Reference
+ Collaboration diagram for ilXMLChecker:

Public Member Functions

 __construct (DataTypeFactory $dataFactory)
 
 parse (string $xmlString)
 
 result ()
 

Private Member Functions

 beginLogging ()
 
 addErrors ()
 
 endLogging ()
 

Private Attributes

DataTypeFactory $dataFactory
 
Result $result
 
bool $xmlErrorState = false
 
array $errorStack = []
 

Detailed Description

Definition at line 24 of file class.ilXmlChecker.php.

Constructor & Destructor Documentation

◆ __construct()

ilXMLChecker::__construct ( DataTypeFactory  $dataFactory)

Definition at line 32 of file class.ilXmlChecker.php.

References $dataFactory, and result().

33  {
34  $this->dataFactory = $dataFactory;
35  $this->result = new Result\Error('No XML parsed, yet');
36  }
DataTypeFactory $dataFactory
+ Here is the call graph for this function:

Member Function Documentation

◆ addErrors()

ilXMLChecker::addErrors ( )
private

Definition at line 50 of file class.ilXmlChecker.php.

Referenced by beginLogging(), and endLogging().

50  : void
51  {
52  $currentErrors = libxml_get_errors();
53  libxml_clear_errors();
54 
55  $level = count($this->errorStack) - 1;
56  $this->errorStack[$level] = array_merge($this->errorStack[$level], $currentErrors);
57  }
+ Here is the caller graph for this function:

◆ beginLogging()

ilXMLChecker::beginLogging ( )
private

Definition at line 38 of file class.ilXmlChecker.php.

References addErrors().

Referenced by parse().

38  : void
39  {
40  if (0 === count($this->errorStack)) {
41  $this->xmlErrorState = libxml_use_internal_errors(true);
42  libxml_clear_errors();
43  } else {
44  $this->addErrors();
45  }
46 
47  $this->errorStack[] = [];
48  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ endLogging()

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

Definition at line 62 of file class.ilXmlChecker.php.

References $errors, and addErrors().

Referenced by parse().

62  : array
63  {
64  $this->addErrors();
65 
66  $errors = array_pop($this->errorStack);
67 
68  if (0 === count($this->errorStack)) {
69  libxml_use_internal_errors($this->xmlErrorState);
70  }
71 
72  return $errors;
73  }
$errors
Definition: imgupload.php:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse()

ilXMLChecker::parse ( string  $xmlString)

Definition at line 75 of file class.ilXmlChecker.php.

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

75  : void
76  {
77  try {
78  $this->beginLogging();
79 
80  $xml = new SimpleXMLElement($xmlString);
81 
82  $this->result = $this->dataFactory->ok($xmlString);
83  $this->endLogging();
84  } catch (Exception $e) {
85  $this->result = $this->dataFactory->error(implode(
86  "\n",
87  array_map(static function (LibXMLError $error): string {
88  return implode(',', [
89  'level=' . $error->level,
90  'code=' . $error->code,
91  'line=' . $error->line,
92  'col=' . $error->column,
93  'msg=' . trim($error->message)
94  ]);
95  }, $this->endLogging())
96  ));
97  }
98  }
$xml
Definition: metadata.php:351
+ Here is the call graph for this function:

◆ result()

ilXMLChecker::result ( )

Definition at line 100 of file class.ilXmlChecker.php.

References $result.

Referenced by __construct(), and parse().

100  : Result
101  {
102  return $this->result;
103  }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:14
+ Here is the caller graph for this function:

Field Documentation

◆ $dataFactory

DataTypeFactory ilXMLChecker::$dataFactory
private

Definition at line 26 of file class.ilXmlChecker.php.

Referenced by __construct().

◆ $errorStack

array ilXMLChecker::$errorStack = []
private

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

◆ $result

Result ilXMLChecker::$result
private

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

Referenced by result().

◆ $xmlErrorState

bool ilXMLChecker::$xmlErrorState = false
private

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


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