PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.20
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.20
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / vendor / openspout / openspout / src / Reader / Wrapper / XMLInternalErrorsHelper.php

XMLInternalErrorsHelper.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.20, at vendor/openspout/openspout/src/Reader/Wrapper/XMLInternalErrorsHelper.php

66 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\OpenSpout\Reader\Wrapper;
4
5 use FluentCart\OpenSpout\Reader\Exception\XMLProcessingException;
6 /**
7 * Trait XMLInternalErrorsHelper.
8 */
9 trait XMLInternalErrorsHelper
10 {
11 /** @var bool Stores whether XML errors were initially stored internally - used to reset */
12 protected $initialUseInternalErrorsValue;
13 /**
14 * To avoid displaying lots of warning/error messages on screen,
15 * stores errors internally instead.
16 */
17 protected function useXMLInternalErrors()
18 {
19 \libxml_clear_errors();
20 $this->initialUseInternalErrorsValue = \libxml_use_internal_errors(\true);
21 }
22 /**
23 * Throws an XMLProcessingException if an error occured.
24 * It also always resets the "libxml_use_internal_errors" setting back to its initial value.
25 *
26 * @throws \OpenSpout\Reader\Exception\XMLProcessingException
27 */
28 protected function resetXMLInternalErrorsSettingAndThrowIfXMLErrorOccured()
29 {
30 if ($this->hasXMLErrorOccured()) {
31 $this->resetXMLInternalErrorsSetting();
32 throw new XMLProcessingException($this->getLastXMLErrorMessage());
33 }
34 $this->resetXMLInternalErrorsSetting();
35 }
36 protected function resetXMLInternalErrorsSetting()
37 {
38 \libxml_use_internal_errors($this->initialUseInternalErrorsValue);
39 }
40 /**
41 * Returns whether the a XML error has occured since the last time errors were cleared.
42 *
43 * @return bool TRUE if an error occured, FALSE otherwise
44 */
45 private function hasXMLErrorOccured()
46 {
47 return \false !== \libxml_get_last_error();
48 }
49 /**
50 * Returns the error message for the last XML error that occured.
51 *
52 * @see libxml_get_last_error
53 *
54 * @return null|string Last XML error message or null if no error
55 */
56 private function getLastXMLErrorMessage()
57 {
58 $errorMessage = null;
59 $error = \libxml_get_last_error();
60 if (\false !== $error) {
61 $errorMessage = \trim($error->message);
62 }
63 return $errorMessage;
64 }
65 }
66