| 141 | | switch ($error->level) { |
|---|
| 142 | | case LIBXML_ERR_WARNING: |
|---|
| 143 | | $element = $resultDoc->createElement('stub:error', 'Warning: ' . trim($error->message) . (($error->file) ? (' in file ' . $error->file) : ('')) . ' on line ' . $error->line . ' in column ' . $error->column); |
|---|
| 144 | | $element->setAttribute('stub:errorType', 'warning'); |
|---|
| 145 | | if (null != $this->part && strlen($this->part) > 0) { |
|---|
| 146 | | $xpath = new DOMXPath($resultDoc); |
|---|
| 147 | | $entry = $xpath->query("/parts/part[@name='" . $this->part ."']/node()")->item(0); |
|---|
| 148 | | $entry->appendChild($element); |
|---|
| 149 | | } else { |
|---|
| 150 | | $resultDoc->documentElement->appendChild($element); |
|---|
| 151 | | } |
|---|
| 152 | | break; |
|---|
| 153 | | case LIBXML_ERR_ERROR: |
|---|
| 154 | | $element = $resultDoc->createElement('stub:error', 'Error: ' . trim($error->message) . (($error->file) ? (' in file ' . $error->file) : ('')) . ' on line ' . $error->line . ' in column ' . $error->column); |
|---|
| 155 | | $element->setAttribute('stub:errorType', 'error'); |
|---|
| 156 | | if (null != $this->part && strlen($this->part) > 0) { |
|---|
| 157 | | $xpath = new DOMXPath($resultDoc); |
|---|
| 158 | | $entry = $xpath->query("/parts/part[@name='" . $this->part ."']")->item(0); |
|---|
| 159 | | $entry->appendChild($element); |
|---|
| 160 | | } else { |
|---|
| 161 | | $resultDoc->documentElement->appendChild($element); |
|---|
| 162 | | } |
|---|
| 163 | | break; |
|---|
| 164 | | case LIBXML_ERR_FATAL: |
|---|
| 165 | | throw new stubXMLException('Fatal error: ' . trim($error->message) . (($error->file) ? (' in file ' . $error->file) : ('')) . ' on line ' . $error->line . ' in column ' . $error->column); |
|---|
| 166 | | } |
|---|
| | 141 | $message = trim($error->message) . (($error->file) ? (' in file ' . $error->file) : ('')) . ' on line ' . $error->line . ' in column ' . $error->column; |
|---|
| | 142 | switch ($error->level) { |
|---|
| | 143 | case LIBXML_ERR_WARNING: |
|---|
| | 144 | $this->appendError($resultDoc, 'warning', $message); |
|---|
| | 145 | break; |
|---|
| | 146 | case LIBXML_ERR_ERROR: |
|---|
| | 147 | $this->appendError($resultDoc, 'error', $message); |
|---|
| | 148 | break; |
|---|
| | 149 | case LIBXML_ERR_FATAL: |
|---|
| | 150 | throw new stubXMLException('Fatal error: ' . $message); |
|---|
| | 151 | } |
|---|
| 171 | | libxml_use_internal_errors($previousErrorHandling); |
|---|
| | 157 | } |
|---|
| | 158 | |
|---|
| | 159 | /** |
|---|
| | 160 | * appends the error message into the result document |
|---|
| | 161 | * |
|---|
| | 162 | * If a part for the inclusion is known it tries to append the error |
|---|
| | 163 | * message into this part, if no part is known the error message is |
|---|
| | 164 | * appended directly before the end tag of the root element. |
|---|
| | 165 | * |
|---|
| | 166 | * @param DOMDocument $resultDoc the document to append the error message into |
|---|
| | 167 | * @param string $level level of the error |
|---|
| | 168 | * @param string $message the error message |
|---|
| | 169 | */ |
|---|
| | 170 | protected function appendError(DOMDocument $resultDoc, $level, $message) |
|---|
| | 171 | { |
|---|
| | 172 | $element = $resultDoc->createElement('stub:error', ucfirst($level) . ': ' . $message); |
|---|
| | 173 | $element->setAttribute('stub:errorType', $level); |
|---|
| | 174 | if (null != $this->part && strlen($this->part) > 0) { |
|---|
| | 175 | $xpath = new DOMXPath($resultDoc); |
|---|
| | 176 | $entry = $xpath->query("/parts/part[@name='" . $this->part ."']")->item(0); |
|---|
| | 177 | $entry->appendChild($element); |
|---|
| | 178 | } else { |
|---|
| | 179 | $resultDoc->documentElement->appendChild($element); |
|---|
| | 180 | } |
|---|