mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 23:08:46 +02:00
N°8834 - Add compatibility with PHP 8.4 (#819)
* N°8834 - Add compatibility with PHP 8.4 * Rollback of scssphp/scssphp version upgrade due to compilation error
This commit is contained in:
@@ -41,7 +41,7 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
protected $autoRegisterAliasesForSinglyImplementedInterfaces = false;
|
||||
|
||||
public function load(mixed $resource, string $type = null): mixed
|
||||
public function load(mixed $resource, ?string $type = null): mixed
|
||||
{
|
||||
$path = $this->locator->locate($resource);
|
||||
|
||||
@@ -54,7 +54,7 @@ class XmlFileLoader extends FileLoader
|
||||
if ($this->env) {
|
||||
$xpath = new \DOMXPath($xml);
|
||||
$xpath->registerNamespace('container', self::NS);
|
||||
foreach ($xpath->query(sprintf('//container:when[@env="%s"]', $this->env)) ?: [] as $root) {
|
||||
foreach ($xpath->query(\sprintf('//container:when[@env="%s"]', $this->env)) ?: [] as $root) {
|
||||
$env = $this->env;
|
||||
$this->env = null;
|
||||
try {
|
||||
@@ -68,7 +68,7 @@ class XmlFileLoader extends FileLoader
|
||||
return null;
|
||||
}
|
||||
|
||||
private function loadXml(\DOMDocument $xml, string $path, \DOMNode $root = null): void
|
||||
private function loadXml(\DOMDocument $xml, string $path, ?\DOMNode $root = null): void
|
||||
{
|
||||
$defaults = $this->getServiceDefaults($xml, $path, $root);
|
||||
|
||||
@@ -93,7 +93,7 @@ class XmlFileLoader extends FileLoader
|
||||
}
|
||||
}
|
||||
|
||||
public function supports(mixed $resource, string $type = null): bool
|
||||
public function supports(mixed $resource, ?string $type = null): bool
|
||||
{
|
||||
if (!\is_string($resource)) {
|
||||
return false;
|
||||
@@ -106,19 +106,19 @@ class XmlFileLoader extends FileLoader
|
||||
return 'xml' === $type;
|
||||
}
|
||||
|
||||
private function parseParameters(\DOMDocument $xml, string $file, \DOMNode $root = null): void
|
||||
private function parseParameters(\DOMDocument $xml, string $file, ?\DOMNode $root = null): void
|
||||
{
|
||||
if ($parameters = $this->getChildren($root ?? $xml->documentElement, 'parameters')) {
|
||||
$this->container->getParameterBag()->add($this->getArgumentsAsPhp($parameters[0], 'parameter', $file));
|
||||
}
|
||||
}
|
||||
|
||||
private function parseImports(\DOMDocument $xml, string $file, \DOMNode $root = null): void
|
||||
private function parseImports(\DOMDocument $xml, string $file, ?\DOMNode $root = null): void
|
||||
{
|
||||
$xpath = new \DOMXPath($xml);
|
||||
$xpath->registerNamespace('container', self::NS);
|
||||
|
||||
if (false === $imports = $xpath->query('.//container:imports/container:import', $root)) {
|
||||
if (false === $imports = $xpath->query('./container:imports/container:import', $root)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -129,19 +129,19 @@ class XmlFileLoader extends FileLoader
|
||||
}
|
||||
}
|
||||
|
||||
private function parseDefinitions(\DOMDocument $xml, string $file, Definition $defaults, \DOMNode $root = null): void
|
||||
private function parseDefinitions(\DOMDocument $xml, string $file, Definition $defaults, ?\DOMNode $root = null): void
|
||||
{
|
||||
$xpath = new \DOMXPath($xml);
|
||||
$xpath->registerNamespace('container', self::NS);
|
||||
|
||||
if (false === $services = $xpath->query('.//container:services/container:service|.//container:services/container:prototype|.//container:services/container:stack', $root)) {
|
||||
if (false === $services = $xpath->query('./container:services/container:service|./container:services/container:prototype|./container:services/container:stack', $root)) {
|
||||
return;
|
||||
}
|
||||
$this->setCurrentDir(\dirname($file));
|
||||
|
||||
$this->instanceof = [];
|
||||
$this->isLoadingInstanceof = true;
|
||||
$instanceof = $xpath->query('.//container:services/container:instanceof', $root);
|
||||
$instanceof = $xpath->query('./container:services/container:instanceof', $root);
|
||||
foreach ($instanceof as $service) {
|
||||
$this->setDefinition((string) $service->getAttribute('id'), $this->parseDefinition($service, $file, new Definition()));
|
||||
}
|
||||
@@ -187,12 +187,12 @@ class XmlFileLoader extends FileLoader
|
||||
}
|
||||
}
|
||||
|
||||
private function getServiceDefaults(\DOMDocument $xml, string $file, \DOMNode $root = null): Definition
|
||||
private function getServiceDefaults(\DOMDocument $xml, string $file, ?\DOMNode $root = null): Definition
|
||||
{
|
||||
$xpath = new \DOMXPath($xml);
|
||||
$xpath->registerNamespace('container', self::NS);
|
||||
|
||||
if (null === $defaultsNode = $xpath->query('.//container:services/container:defaults', $root)->item(0)) {
|
||||
if (null === $defaultsNode = $xpath->query('./container:services/container:defaults', $root)->item(0)) {
|
||||
return new Definition();
|
||||
}
|
||||
|
||||
@@ -222,11 +222,11 @@ class XmlFileLoader extends FileLoader
|
||||
$version = $deprecated[0]->getAttribute('version') ?: '';
|
||||
|
||||
if (!$deprecated[0]->hasAttribute('package')) {
|
||||
throw new InvalidArgumentException(sprintf('Missing attribute "package" at node "deprecated" in "%s".', $file));
|
||||
throw new InvalidArgumentException(\sprintf('Missing attribute "package" at node "deprecated" in "%s".', $file));
|
||||
}
|
||||
|
||||
if (!$deprecated[0]->hasAttribute('version')) {
|
||||
throw new InvalidArgumentException(sprintf('Missing attribute "version" at node "deprecated" in "%s".', $file));
|
||||
throw new InvalidArgumentException(\sprintf('Missing attribute "version" at node "deprecated" in "%s".', $file));
|
||||
}
|
||||
|
||||
$alias->setDeprecated($package, $version, $message);
|
||||
@@ -282,11 +282,11 @@ class XmlFileLoader extends FileLoader
|
||||
$version = $deprecated[0]->getAttribute('version') ?: '';
|
||||
|
||||
if (!$deprecated[0]->hasAttribute('package')) {
|
||||
throw new InvalidArgumentException(sprintf('Missing attribute "package" at node "deprecated" in "%s".', $file));
|
||||
throw new InvalidArgumentException(\sprintf('Missing attribute "package" at node "deprecated" in "%s".', $file));
|
||||
}
|
||||
|
||||
if (!$deprecated[0]->hasAttribute('version')) {
|
||||
throw new InvalidArgumentException(sprintf('Missing attribute "version" at node "deprecated" in "%s".', $file));
|
||||
throw new InvalidArgumentException(\sprintf('Missing attribute "version" at node "deprecated" in "%s".', $file));
|
||||
}
|
||||
|
||||
$definition->setDeprecated($package, $version, $message);
|
||||
@@ -317,7 +317,7 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
if ($constructor = $service->getAttribute('constructor')) {
|
||||
if (null !== $definition->getFactory()) {
|
||||
throw new LogicException(sprintf('The "%s" service cannot declare a factory as well as a constructor.', $service->getAttribute('id')));
|
||||
throw new LogicException(\sprintf('The "%s" service cannot declare a factory as well as a constructor.', $service->getAttribute('id')));
|
||||
}
|
||||
|
||||
$definition->setFactory([null, $constructor]);
|
||||
@@ -339,7 +339,11 @@ class XmlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
foreach ($this->getChildren($service, 'call') as $call) {
|
||||
$definition->addMethodCall($call->getAttribute('method'), $this->getArgumentsAsPhp($call, 'argument', $file), XmlUtils::phpize($call->getAttribute('returns-clone')));
|
||||
$definition->addMethodCall(
|
||||
$call->getAttribute('method'),
|
||||
$this->getArgumentsAsPhp($call, 'argument', $file),
|
||||
XmlUtils::phpize($call->getAttribute('returns-clone')) ?: false
|
||||
);
|
||||
}
|
||||
|
||||
$tags = $this->getChildren($service, 'tag');
|
||||
@@ -347,10 +351,10 @@ class XmlFileLoader extends FileLoader
|
||||
foreach ($tags as $tag) {
|
||||
$tagNameComesFromAttribute = $tag->childElementCount || '' === $tag->nodeValue;
|
||||
if ('' === $tagName = $tagNameComesFromAttribute ? $tag->getAttribute('name') : $tag->nodeValue) {
|
||||
throw new InvalidArgumentException(sprintf('The tag name for service "%s" in "%s" must be a non-empty string.', (string) $service->getAttribute('id'), $file));
|
||||
throw new InvalidArgumentException(\sprintf('The tag name for service "%s" in "%s" must be a non-empty string.', (string) $service->getAttribute('id'), $file));
|
||||
}
|
||||
|
||||
$parameters = $this->getTagAttributes($tag, sprintf('The attribute name of tag "%s" for service "%s" in %s must be a non-empty string.', $tagName, (string) $service->getAttribute('id'), $file));
|
||||
$parameters = $this->getTagAttributes($tag, \sprintf('The attribute name of tag "%s" for service "%s" in %s must be a non-empty string.', $tagName, (string) $service->getAttribute('id'), $file));
|
||||
foreach ($tag->attributes as $name => $node) {
|
||||
if ($tagNameComesFromAttribute && 'name' === $name) {
|
||||
continue;
|
||||
@@ -390,7 +394,7 @@ class XmlFileLoader extends FileLoader
|
||||
} elseif ('null' === $decorationOnInvalid) {
|
||||
$invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE;
|
||||
} else {
|
||||
throw new InvalidArgumentException(sprintf('Invalid value "%s" for attribute "decoration-on-invalid" on service "%s". Did you mean "exception", "ignore" or "null" in "%s"?', $decorationOnInvalid, $service->getAttribute('id'), $file));
|
||||
throw new InvalidArgumentException(\sprintf('Invalid value "%s" for attribute "decoration-on-invalid" on service "%s". Did you mean "exception", "ignore" or "null" in "%s"?', $decorationOnInvalid, $service->getAttribute('id'), $file));
|
||||
}
|
||||
|
||||
$renameId = $service->hasAttribute('decoration-inner-name') ? $service->getAttribute('decoration-inner-name') : null;
|
||||
@@ -401,7 +405,7 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
if ($callable = $this->getChildren($service, 'from-callable')) {
|
||||
if ($definition instanceof ChildDefinition) {
|
||||
throw new InvalidArgumentException(sprintf('Attribute "parent" is unsupported when using "<from-callable>" on service "%s".', (string) $service->getAttribute('id')));
|
||||
throw new InvalidArgumentException(\sprintf('Attribute "parent" is unsupported when using "<from-callable>" on service "%s".', (string) $service->getAttribute('id')));
|
||||
}
|
||||
|
||||
foreach ([
|
||||
@@ -414,7 +418,7 @@ class XmlFileLoader extends FileLoader
|
||||
'Tag "<call>"' => 'getMethodCalls',
|
||||
] as $key => $method) {
|
||||
if ($definition->$method()) {
|
||||
throw new InvalidArgumentException($key.sprintf(' is unsupported when using "<from-callable>" on service "%s".', (string) $service->getAttribute('id')));
|
||||
throw new InvalidArgumentException($key.\sprintf(' is unsupported when using "<from-callable>" on service "%s".', (string) $service->getAttribute('id')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -458,7 +462,33 @@ class XmlFileLoader extends FileLoader
|
||||
try {
|
||||
$dom = XmlUtils::loadFile($file, $this->validateSchema(...));
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
throw new InvalidArgumentException(sprintf('Unable to parse file "%s": ', $file).$e->getMessage(), $e->getCode(), $e);
|
||||
$invalidSecurityElements = [];
|
||||
$errors = explode("\n", $e->getMessage());
|
||||
foreach ($errors as $i => $error) {
|
||||
if (preg_match("#^\[ERROR 1871] Element '\{http://symfony\.com/schema/dic/security}([^']+)'#", $error, $matches)) {
|
||||
$invalidSecurityElements[$i] = $matches[1];
|
||||
}
|
||||
}
|
||||
if ($invalidSecurityElements) {
|
||||
$dom = XmlUtils::loadFile($file);
|
||||
|
||||
foreach ($invalidSecurityElements as $errorIndex => $tagName) {
|
||||
foreach ($dom->getElementsByTagNameNS('http://symfony.com/schema/dic/security', $tagName) as $element) {
|
||||
if (!$parent = $element->parentNode) {
|
||||
continue;
|
||||
}
|
||||
if ('http://symfony.com/schema/dic/security' !== $parent->namespaceURI) {
|
||||
continue;
|
||||
}
|
||||
if ('provider' === $parent->localName || 'firewall' === $parent->localName) {
|
||||
unset($errors[$errorIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($errors) {
|
||||
throw new InvalidArgumentException(\sprintf('Unable to parse file "%s": ', $file).implode("\n", $errors), $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
$this->validateExtensions($dom, $file);
|
||||
@@ -469,7 +499,7 @@ class XmlFileLoader extends FileLoader
|
||||
/**
|
||||
* Processes anonymous services.
|
||||
*/
|
||||
private function processAnonymousServices(\DOMDocument $xml, string $file, \DOMNode $root = null): void
|
||||
private function processAnonymousServices(\DOMDocument $xml, string $file, ?\DOMNode $root = null): void
|
||||
{
|
||||
$definitions = [];
|
||||
$count = 0;
|
||||
@@ -483,7 +513,7 @@ class XmlFileLoader extends FileLoader
|
||||
foreach ($nodes as $node) {
|
||||
if ($services = $this->getChildren($node, 'service')) {
|
||||
// give it a unique name
|
||||
$id = sprintf('.%d_%s', ++$count, preg_replace('/^.*\\\\/', '', $services[0]->getAttribute('class')).$suffix);
|
||||
$id = \sprintf('.%d_%s', ++$count, preg_replace('/^.*\\\\/', '', $services[0]->getAttribute('class')).$suffix);
|
||||
$node->setAttribute('id', $id);
|
||||
$node->setAttribute('service', $id);
|
||||
|
||||
@@ -500,7 +530,7 @@ class XmlFileLoader extends FileLoader
|
||||
// anonymous services "in the wild"
|
||||
if (false !== $nodes = $xpath->query('.//container:services/container:service[not(@id)]', $root)) {
|
||||
foreach ($nodes as $node) {
|
||||
throw new InvalidArgumentException(sprintf('Top-level services must have "id" attribute, none found in "%s" at line %d.', $file, $node->getLineNo()));
|
||||
throw new InvalidArgumentException(\sprintf('Top-level services must have "id" attribute, none found in "%s" at line %d.', $file, $node->getLineNo()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,7 +578,7 @@ class XmlFileLoader extends FileLoader
|
||||
switch ($type = $arg->getAttribute('type')) {
|
||||
case 'service':
|
||||
if ('' === $arg->getAttribute('id')) {
|
||||
throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="service" has no or empty "id" attribute in "%s".', $name, $file));
|
||||
throw new InvalidArgumentException(\sprintf('Tag "<%s>" with type="service" has no or empty "id" attribute in "%s".', $name, $file));
|
||||
}
|
||||
|
||||
$arguments[$key] = new Reference($arg->getAttribute('id'), $invalidBehavior);
|
||||
@@ -596,7 +626,7 @@ class XmlFileLoader extends FileLoader
|
||||
$forLocator = 'tagged_locator' === $type;
|
||||
|
||||
if (!$arg->getAttribute('tag')) {
|
||||
throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="%s" has no or empty "tag" attribute in "%s".', $name, $type, $file));
|
||||
throw new InvalidArgumentException(\sprintf('Tag "<%s>" with type="%s" has no or empty "tag" attribute in "%s".', $name, $type, $file));
|
||||
}
|
||||
|
||||
$excludes = array_column($this->getChildren($arg, 'exclude'), 'nodeValue');
|
||||
@@ -615,7 +645,7 @@ class XmlFileLoader extends FileLoader
|
||||
break;
|
||||
case 'binary':
|
||||
if (false === $value = base64_decode($arg->nodeValue)) {
|
||||
throw new InvalidArgumentException(sprintf('Tag "<%s>" with type="binary" is not a valid base64 encoded string.', $name));
|
||||
throw new InvalidArgumentException(\sprintf('Tag "<%s>" with type="binary" is not a valid base64 encoded string.', $name));
|
||||
}
|
||||
$arguments[$key] = $value;
|
||||
break;
|
||||
@@ -698,7 +728,7 @@ class XmlFileLoader extends FileLoader
|
||||
$path = str_replace([$ns, str_replace('http://', 'https://', $ns)], str_replace('\\', '/', $extension->getXsdValidationBasePath()).'/', $items[$i + 1]);
|
||||
|
||||
if (!is_file($path)) {
|
||||
throw new RuntimeException(sprintf('Extension "%s" references a non-existent XSD file "%s".', get_debug_type($extension), $path));
|
||||
throw new RuntimeException(\sprintf('Extension "%s" references a non-existent XSD file "%s".', get_debug_type($extension), $path));
|
||||
}
|
||||
|
||||
$schemaLocations[$items[$i]] = $path;
|
||||
@@ -727,7 +757,7 @@ class XmlFileLoader extends FileLoader
|
||||
$drive = '\\' === \DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
|
||||
$location = $locationstart.$drive.implode('/', array_map('rawurlencode', $parts));
|
||||
|
||||
$imports .= sprintf(' <xsd:import namespace="%s" schemaLocation="%s" />'."\n", $namespace, $location);
|
||||
$imports .= \sprintf(' <xsd:import namespace="%s" schemaLocation="%s" />'."\n", $namespace, $location);
|
||||
}
|
||||
|
||||
$source = <<<EOF
|
||||
@@ -786,7 +816,7 @@ EOF
|
||||
{
|
||||
foreach ($alias->attributes as $name => $node) {
|
||||
if (!\in_array($name, ['alias', 'id', 'public'])) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid attribute "%s" defined for alias "%s" in "%s".', $name, $alias->getAttribute('id'), $file));
|
||||
throw new InvalidArgumentException(\sprintf('Invalid attribute "%s" defined for alias "%s" in "%s".', $name, $alias->getAttribute('id'), $file));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -795,7 +825,7 @@ EOF
|
||||
continue;
|
||||
}
|
||||
if ('deprecated' !== $child->localName) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid child element "%s" defined for alias "%s" in "%s".', $child->localName, $alias->getAttribute('id'), $file));
|
||||
throw new InvalidArgumentException(\sprintf('Invalid child element "%s" defined for alias "%s" in "%s".', $child->localName, $alias->getAttribute('id'), $file));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -815,7 +845,7 @@ EOF
|
||||
// can it be handled by an extension?
|
||||
if (!$this->container->hasExtension($node->namespaceURI)) {
|
||||
$extensionNamespaces = array_filter(array_map(fn (ExtensionInterface $ext) => $ext->getNamespace(), $this->container->getExtensions()));
|
||||
throw new InvalidArgumentException(sprintf('There is no extension able to load the configuration for "%s" (in "%s"). Looked for namespace "%s", found "%s".', $node->tagName, $file, $node->namespaceURI, $extensionNamespaces ? implode('", "', $extensionNamespaces) : 'none'));
|
||||
throw new InvalidArgumentException(\sprintf('There is no extension able to load the configuration for "%s" (in "%s"). Looked for namespace "%s", found "%s".', $node->tagName, $file, $node->namespaceURI, $extensionNamespaces ? implode('", "', $extensionNamespaces) : 'none'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -858,6 +888,6 @@ EOF
|
||||
*/
|
||||
public static function convertDomElementToArray(\DOMElement $element): mixed
|
||||
{
|
||||
return XmlUtils::convertDomElementToArray($element);
|
||||
return XmlUtils::convertDomElementToArray($element, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user