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

Public Member Functions

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

Private Member Functions

 beginLogging ()
 
 addErrors ()
 
 endLogging ()
 

Private Attributes

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

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilXMLChecker::__construct ( private readonly DataTypeFactory  $dataFactory)

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

32 {
33 $this->result = new Result\Error('No XML parsed, yet');
34 }

References result().

+ Here is the call graph for this function:

Member Function Documentation

◆ addErrors()

ilXMLChecker::addErrors ( )
private

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

48 : void
49 {
50 $currentErrors = libxml_get_errors();
51 libxml_clear_errors();
52
53 $level = count($this->errorStack) - 1;
54 $this->errorStack[$level] = array_merge($this->errorStack[$level], $currentErrors);
55 }

Referenced by beginLogging(), and endLogging().

+ Here is the caller graph for this function:

◆ beginLogging()

ilXMLChecker::beginLogging ( )
private

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

36 : void
37 {
38 if ([] === $this->errorStack) {
39 $this->xmlErrorState = libxml_use_internal_errors(true);
40 libxml_clear_errors();
41 } else {
42 $this->addErrors();
43 }
44
45 $this->errorStack[] = [];
46 }

References addErrors().

Referenced by parse().

+ 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 60 of file class.ilXmlChecker.php.

60 : array
61 {
62 $this->addErrors();
63
64 $errors = array_pop($this->errorStack);
65
66 if ([] === $this->errorStack) {
67 libxml_use_internal_errors($this->xmlErrorState);
68 }
69
70 return $errors;
71 }

References addErrors().

Referenced by parse().

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

◆ parse()

ilXMLChecker::parse ( string  $xmlString)

@noinspection PhpExpressionResultUnusedInspection

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

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

References beginLogging(), endLogging(), and result().

+ Here is the call graph for this function:

◆ result()

ilXMLChecker::result ( )

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

99 : Result
100 {
101 return $this->result;
102 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Result.php:29

References $result.

Referenced by __construct(), and parse().

+ Here is the caller graph for this function:

Field Documentation

◆ $errorStack

array ilXMLChecker::$errorStack = []
private

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

◆ $result

Result ilXMLChecker::$result
private

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

Referenced by result().

◆ $xmlErrorState

bool ilXMLChecker::$xmlErrorState = false
private

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


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