ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Errors.php
Go to the documentation of this file.
1 <?php
2 
13 namespace SimpleSAML\XML;
14 
15 class Errors
16 {
17 
21  private static $errorStack = array();
22 
26  private static $xmlErrorState;
27 
28 
32  private static function addErrors()
33  {
34  $currentErrors = libxml_get_errors();
35  libxml_clear_errors();
36 
37  $level = count(self::$errorStack) - 1;
38  self::$errorStack[$level] = array_merge(self::$errorStack[$level], $currentErrors);
39  }
40 
41 
48  public static function begin()
49  {
50 
51  // Check whether the error access functions are present
52  if (!function_exists('libxml_use_internal_errors')) {
53  return;
54  }
55 
56  if (count(self::$errorStack) === 0) {
57  // No error logging is currently in progress. Initialize it.
58  self::$xmlErrorState = libxml_use_internal_errors(true);
59  libxml_clear_errors();
60  } else {
61  /* We have already started error logging. Append the current errors to the
62  * list of errors in this level.
63  */
64  self::addErrors();
65  }
66 
67  // Add a new level to the error stack
68  self::$errorStack[] = array();
69  }
70 
71 
77  public static function end()
78  {
79 
80  // Check whether the error access functions are present
81  if (!function_exists('libxml_use_internal_errors')) {
82  // Pretend that no errors occurred
83  return array();
84  }
85 
86  // Add any errors which may have occurred
87  self::addErrors();
88 
89 
90  $ret = array_pop(self::$errorStack);
91 
92  if (count(self::$errorStack) === 0) {
93  // Disable our error logging and restore the previous state
94  libxml_use_internal_errors(self::$xmlErrorState);
95  }
96 
97  return $ret;
98  }
99 
100 
109  public static function formatError($error)
110  {
111  assert('$error instanceof LibXMLError');
112  return 'level=' . $error->level . ',code=' . $error->code . ',line=' . $error->line . ',col=' . $error->column .
113  ',msg=' . trim($error->message);
114  }
115 
116 
127  public static function formatErrors($errors)
128  {
129  assert('is_array($errors)');
130 
131  $ret = '';
132  foreach ($errors as $error) {
133  $ret .= self::formatError($error) . "\n";
134  }
135 
136  return $ret;
137  }
138 }
static formatError($error)
Format an error as a string.
Definition: Errors.php:109
static formatErrors($errors)
Format a list of errors as a string.
Definition: Errors.php:127
$error
Definition: Error.php:17
Create styles array
The data for the language used.
static begin()
Start error logging.
Definition: Errors.php:48
static addErrors()
Append current XML errors to the current stack level.
Definition: Errors.php:32
$errors
Definition: index.php:6
static $xmlErrorState
Definition: Errors.php:26
$ret
Definition: parser.php:6
static end()
End error logging.
Definition: Errors.php:77