__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
declare(strict_types=1);
namespace OpenSpout\Reader\Wrapper;
use OpenSpout\Reader\Exception\XMLProcessingException;
/**
* @internal
*/
trait XMLInternalErrorsHelper
{
/** @var bool Stores whether XML errors were initially stored internally - used to reset */
private bool $initialUseInternalErrorsValue;
/**
* To avoid displaying lots of warning/error messages on screen,
* stores errors internally instead.
*/
private function useXMLInternalErrors(): void
{
libxml_clear_errors();
$this->initialUseInternalErrorsValue = libxml_use_internal_errors(true);
}
/**
* Throws an XMLProcessingException if an error occured.
* It also always resets the "libxml_use_internal_errors" setting back to its initial value.
*
* @throws XMLProcessingException
*/
private function resetXMLInternalErrorsSettingAndThrowIfXMLErrorOccured(): void
{
if ($this->hasXMLErrorOccured()) {
$this->resetXMLInternalErrorsSetting();
throw new XMLProcessingException($this->getLastXMLErrorMessage());
}
$this->resetXMLInternalErrorsSetting();
}
private function resetXMLInternalErrorsSetting(): void
{
libxml_use_internal_errors($this->initialUseInternalErrorsValue);
}
/**
* Returns whether the a XML error has occured since the last time errors were cleared.
*
* @return bool TRUE if an error occured, FALSE otherwise
*/
private function hasXMLErrorOccured(): bool
{
return false !== libxml_get_last_error();
}
/**
* Returns the error message for the last XML error that occured.
*
* @see libxml_get_last_error
*
* @return string Last XML error message or null if no error
*/
private function getLastXMLErrorMessage(): string
{
$errorMessage = '';
$error = libxml_get_last_error();
if (false !== $error) {
$errorMessage = trim($error->message);
}
return $errorMessage;
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| XMLInternalErrorsHelper.php | File | 2.02 KB | 0777 |
|
| XMLReader.php | File | 5.6 KB | 0777 |
|