mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-30 05:58:46 +02:00
N°6934 - Symfony 6.4 - upgrade Symfony bundles to 6.4 (#580)
* Update Symfony lib to version ~6.4.0 * Update code missing return type * Add an iTop general configuration entry to store application secret (Symfony mandatory parameter) * Use dependency injection in ExceptionListener & UserProvider classes
This commit is contained in:
@@ -38,40 +38,28 @@ class XmlUtils
|
||||
* @param string $content An XML string
|
||||
* @param string|callable|null $schemaOrCallable An XSD schema file path, a callable, or null to disable validation
|
||||
*
|
||||
* @return \DOMDocument
|
||||
*
|
||||
* @throws XmlParsingException When parsing of XML file returns error
|
||||
* @throws InvalidXmlException When parsing of XML with schema or callable produces any errors unrelated to the XML parsing itself
|
||||
* @throws \RuntimeException When DOM extension is missing
|
||||
*/
|
||||
public static function parse(string $content, $schemaOrCallable = null)
|
||||
public static function parse(string $content, string|callable $schemaOrCallable = null): \DOMDocument
|
||||
{
|
||||
if (!\extension_loaded('dom')) {
|
||||
throw new \LogicException('Extension DOM is required.');
|
||||
}
|
||||
|
||||
$internalErrors = libxml_use_internal_errors(true);
|
||||
if (\LIBXML_VERSION < 20900) {
|
||||
$disableEntities = libxml_disable_entity_loader(true);
|
||||
}
|
||||
libxml_clear_errors();
|
||||
|
||||
$dom = new \DOMDocument();
|
||||
$dom->validateOnParse = true;
|
||||
if (!$dom->loadXML($content, \LIBXML_NONET | (\defined('LIBXML_COMPACT') ? \LIBXML_COMPACT : 0))) {
|
||||
if (\LIBXML_VERSION < 20900) {
|
||||
libxml_disable_entity_loader($disableEntities);
|
||||
}
|
||||
|
||||
if (!$dom->loadXML($content, \LIBXML_NONET | \LIBXML_COMPACT)) {
|
||||
throw new XmlParsingException(implode("\n", static::getXmlErrors($internalErrors)));
|
||||
}
|
||||
|
||||
$dom->normalizeDocument();
|
||||
|
||||
libxml_use_internal_errors($internalErrors);
|
||||
if (\LIBXML_VERSION < 20900) {
|
||||
libxml_disable_entity_loader($disableEntities);
|
||||
}
|
||||
|
||||
foreach ($dom->childNodes as $child) {
|
||||
if (\XML_DOCUMENT_TYPE_NODE === $child->nodeType) {
|
||||
@@ -90,18 +78,18 @@ class XmlUtils
|
||||
} catch (\Exception $e) {
|
||||
$valid = false;
|
||||
}
|
||||
} elseif (!\is_array($schemaOrCallable) && is_file((string) $schemaOrCallable)) {
|
||||
} elseif (is_file($schemaOrCallable)) {
|
||||
$schemaSource = file_get_contents((string) $schemaOrCallable);
|
||||
$valid = @$dom->schemaValidateSource($schemaSource);
|
||||
} else {
|
||||
libxml_use_internal_errors($internalErrors);
|
||||
|
||||
throw new XmlParsingException('The schemaOrCallable argument has to be a valid path to XSD file or callable.');
|
||||
throw new XmlParsingException(sprintf('Invalid XSD file: "%s".', $schemaOrCallable));
|
||||
}
|
||||
|
||||
if (!$valid) {
|
||||
$messages = static::getXmlErrors($internalErrors);
|
||||
if (empty($messages)) {
|
||||
if (!$messages) {
|
||||
throw new InvalidXmlException('The XML is not valid.', 0, $e);
|
||||
}
|
||||
throw new XmlParsingException(implode("\n", $messages), 0, $e);
|
||||
@@ -120,13 +108,11 @@ class XmlUtils
|
||||
* @param string $file An XML file path
|
||||
* @param string|callable|null $schemaOrCallable An XSD schema file path, a callable, or null to disable validation
|
||||
*
|
||||
* @return \DOMDocument
|
||||
*
|
||||
* @throws \InvalidArgumentException When loading of XML file returns error
|
||||
* @throws XmlParsingException When XML parsing returns any errors
|
||||
* @throws \RuntimeException When DOM extension is missing
|
||||
*/
|
||||
public static function loadFile(string $file, $schemaOrCallable = null)
|
||||
public static function loadFile(string $file, string|callable $schemaOrCallable = null): \DOMDocument
|
||||
{
|
||||
if (!is_file($file)) {
|
||||
throw new \InvalidArgumentException(sprintf('Resource "%s" is not a file.', $file));
|
||||
@@ -166,10 +152,8 @@ class XmlUtils
|
||||
*
|
||||
* @param \DOMElement $element A \DOMElement instance
|
||||
* @param bool $checkPrefix Check prefix in an element or an attribute name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function convertDomElementToArray(\DOMElement $element, bool $checkPrefix = true)
|
||||
public static function convertDomElementToArray(\DOMElement $element, bool $checkPrefix = true): mixed
|
||||
{
|
||||
$prefix = (string) $element->prefix;
|
||||
$empty = true;
|
||||
@@ -222,12 +206,8 @@ class XmlUtils
|
||||
|
||||
/**
|
||||
* Converts an xml value to a PHP type.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function phpize($value)
|
||||
public static function phpize(string|\Stringable $value): mixed
|
||||
{
|
||||
$value = (string) $value;
|
||||
$lowercaseValue = strtolower($value);
|
||||
@@ -258,6 +238,9 @@ class XmlUtils
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected static function getXmlErrors(bool $internalErrors)
|
||||
{
|
||||
$errors = [];
|
||||
|
||||
Reference in New Issue
Block a user