Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Dec 17, 2024
1 parent aa7c62f commit 5d1465d
Show file tree
Hide file tree
Showing 24 changed files with 136 additions and 24 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.3
---

* Deprecate XmlUtils::parse(), XmlUtils::loadFile(), XmlUtils::convertDomElementToArray()

7.2
---

Expand Down
19 changes: 18 additions & 1 deletion src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

class XmlUtilsTest extends TestCase
{
/**
* @group legacy
*/
public function testLoadFile()
{
$fixtures = __DIR__.'/../Fixtures/Util/';
Expand Down Expand Up @@ -90,6 +93,9 @@ public function testLoadFile()
$this->assertSame([], libxml_get_errors());
}

/**
* @group legacy
*/
public function testParseWithInvalidValidatorCallable()
{
$fixtures = __DIR__.'/../Fixtures/Util/';
Expand All @@ -103,6 +109,9 @@ public function testParseWithInvalidValidatorCallable()
XmlUtils::parse(file_get_contents($fixtures.'valid.xml'), [$mock, 'validate']);
}

/**
* @group legacy
*/
public function testLoadFileWithInternalErrorsEnabled()
{
$internalErrors = libxml_use_internal_errors(true);
Expand All @@ -117,6 +126,8 @@ public function testLoadFileWithInternalErrorsEnabled()

/**
* @dataProvider getDataForConvertDomToArray
*
* @group legacy
*/
public function testConvertDomToArray($expected, string $xml, bool $root = false, bool $checkPrefix = true)
{
Expand Down Expand Up @@ -191,6 +202,9 @@ public static function getDataForPhpize(): array
];
}

/**
* @group legacy
*/
public function testLoadEmptyXmlFile()
{
$file = __DIR__.'/../Fixtures/foo.xml';
Expand All @@ -202,13 +216,16 @@ public function testLoadEmptyXmlFile()
}

// test for issue https://github.com/symfony/symfony/issues/9731
/**
* @group legacy
*/
public function testLoadWrongEmptyXMLWithErrorHandler()
{
$errorReporting = error_reporting(-1);

set_error_handler(function ($errno, $errstr) {
throw new \Exception($errstr, $errno);
});
}, \E_ERROR);

$file = __DIR__.'/../Fixtures/foo.xml';
try {
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Config/Util/XmlUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ public static function loadFile(string $file, string|callable|null $schemaOrCall
*
* @param \DOMElement $element A \DOMElement instance
* @param bool $checkPrefix Check prefix in an element or an attribute name
*
* @deprecated since Symfony 7.3
*/
public static function convertDomElementToArray(\DOMElement $element, bool $checkPrefix = true): mixed
{
trigger_deprecation('symfony/config', '7.3', \sprintf('The "%s" method is deprecated.', __METHOD__));

$prefix = $element->prefix;
$empty = true;
$config = [];
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.3
---

* Deprecate XmlDumper and XmlFileLoader

7.2
---

Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
Expand All @@ -29,11 +30,21 @@
*
* @author Fabien Potencier <[email protected]>
* @author Martin Hasoň <[email protected]>
*
* @deprecated since Symfony 7.3
*/
class XmlDumper extends Dumper
{
private \DOMDocument $document;

public function __construct(
protected ContainerBuilder $container,
) {
trigger_deprecation('symfony/dependency-injection', '7.3', \sprintf('The "%s" class is deprecated.', __CLASS__));

parent::__construct($container);
}

/**
* Dumps the service container as an XML string.
*/
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\DependencyInjection\Loader;

use Symfony\Component\Config\FileLocatorInterface;
use Symfony\Component\Config\Util\XmlUtils;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
Expand All @@ -34,13 +35,26 @@
* XmlFileLoader loads XML files service definitions.
*
* @author Fabien Potencier <[email protected]>
*
* @deprecated since Symfony 7.3
*/
class XmlFileLoader extends FileLoader
{
public const NS = 'http://symfony.com/schema/dic/services';

protected bool $autoRegisterAliasesForSinglyImplementedInterfaces = false;

public function __construct(
protected ContainerBuilder $container,
FileLocatorInterface $locator,
?string $env = null,
protected bool $prepend = false,
) {
trigger_deprecation('symfony/dependency-injection', '7.3', \sprintf('The "%s" class is deprecated.', __CLASS__));

parent::__construct($container, $locator, $env, $prepend);
}

public function load(mixed $resource, ?string $type = null): mixed
{
$path = $this->locator->locate($resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ private function isUsingShortSyntax(array $service): bool
private function parseDefinition(string $id, array|string|null $service, string $file, array $defaults, bool $return = false, bool $trackBindings = true): Definition|Alias|null
{
if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) {
throw new InvalidArgumentException(\sprintf('Service names that start with an underscore are reserved. Rename the "%s" service or define it in XML instead.', $id));
throw new InvalidArgumentException(\sprintf('Service names that start with an underscore are reserved. Rename the "%s" service.', $id));
}

if (\is_string($service) && str_starts_with($service, '@')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\AutowiringFailedException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
Expand Down Expand Up @@ -992,8 +992,8 @@ public function testExceptionWhenAliasDoesNotExist()
public function testInlineServicesAreNotCandidates()
{
$container = new ContainerBuilder();
$loader = new XmlFileLoader($container, new FileLocator(realpath(__DIR__.'/../Fixtures/xml')));
$loader->load('services_inline_not_candidate.xml');
$loader = new YamlFileLoader($container, new FileLocator(realpath(__DIR__.'/../Fixtures/yaml')));
$loader->load('services_inline_not_candidate.yml');

$pass = new AutowirePass();
$pass->process($container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public static function setUpBeforeClass(): void
*/
public function testCrossCheck($fixture, $type)
{
if ('xml' === $type) {
$this->markTestSkipped('XmlFileLoader is deprecated.');
}

$loaderClass = 'Symfony\\Component\\DependencyInjection\\Loader\\'.ucfirst($type).'FileLoader';
$dumperClass = 'Symfony\\Component\\DependencyInjection\\Dumper\\'.ucfirst($type).'Dumper';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooUnitEnum;
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooWithAbstractArgument;

/**
* @group legacy
*/
class XmlDumperTest extends TestCase
{
protected static string $fixturesPath;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

services:
foo:
class: stdClass
arguments:
- !service
class: Symfony\Component\DependencyInjection\Tests\Compiler\D

autowired:
class: Symfony\Component\DependencyInjection\Tests\Compiler\E
autowire: true
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
use Symfony\Component\DependencyInjection\Tests\Fixtures\RemoteCallerSocket;
use Symfony\Component\ExpressionLanguage\Expression;

/**
* @group legacy
*/
class XmlFileLoaderTest extends TestCase
{
use ExpectUserDeprecationMessageTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function testLoadImports()
$container = new ContainerBuilder();
$resolver = new LoaderResolver([
new IniFileLoader($container, new FileLocator(self::$fixturesPath.'/ini')),
new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')),
// deprecated new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml')),
new PhpFileLoader($container, new FileLocator(self::$fixturesPath.'/php')),
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')),
]);
Expand Down Expand Up @@ -381,8 +381,8 @@ public function testSupports()
$this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
$this->assertTrue($loader->supports('foo.yaml'), '->supports() returns true if the resource is loadable');
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns false if the resource is not loadable');
$this->assertTrue($loader->supports('with_wrong_ext.xml', 'yml'), '->supports() returns true if the resource with forced type is loadable');
$this->assertTrue($loader->supports('with_wrong_ext.xml', 'yaml'), '->supports() returns true if the resource with forced type is loadable');
// $this->assertTrue($loader->supports('with_wrong_ext.xml', 'yml'), '->supports() returns true if the resource with forced type is loadable');
// $this->assertTrue($loader->supports('with_wrong_ext.xml', 'yaml'), '->supports() returns true if the resource with forced type is loadable');
}

public function testNonArrayTagsThrowsException()
Expand Down Expand Up @@ -767,7 +767,7 @@ public function testInvalidTagsWithDefaults()
public function testUnderscoreServiceId()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Service names that start with an underscore are reserved. Rename the "_foo" service or define it in XML instead.');
$this->expectExceptionMessage('Service names that start with an underscore are reserved. Rename the "_foo" service.');
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('services_underscore.yml');
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Routing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.3
---

* Deprecate XmlFileLoader

7.2
---

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Routing/Loader/XmlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(
protected FileLocatorInterface $locator,
?string $env = null,
) {
trigger_deprecation('symfony/routing', '7.3', 'The "%s" class is deprecated.', __CLASS__);
trigger_deprecation('symfony/routing', '7.3', \sprintf('The "%s" class is deprecated.', __CLASS__));

parent::__construct($locator, $env);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
This scheme defines the elements and attributes that can be used to define
routes. A route maps an HTTP request to a set of configuration variables.
This schema is deprecated since Symfony 7.3.
]]></xsd:documentation>
</xsd:annotation>

Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Serializer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.3
---

* Deprecate XmlFileLoader

7.2
---

Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Serializer/Mapping/Loader/XmlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* Loads XML mapping files.
*
* @author Kévin Dunglas <[email protected]>
*
* @deprecated since Symfony 7.3
*/
class XmlFileLoader extends FileLoader
{
Expand All @@ -33,6 +35,14 @@ class XmlFileLoader extends FileLoader
*/
private ?array $classes = null;

public function __construct(
protected string $file,
) {
trigger_deprecation('symfony/serializer', '7.3', \sprintf('The "%s" class is deprecated.', __CLASS__));

parent::__construct($file);
}

public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
{
if (!$this->classes ??= $this->getClassesFromXml()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

/**
* @author Kévin Dunglas <[email protected]>
*
* @group legacy
*/
class XmlFileLoaderTest extends TestCase
{
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Validator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.3
---

* Deprecate XmlFileLoader and XmlFilesLoader

7.2
---

Expand Down
11 changes: 8 additions & 3 deletions src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* Loads validation metadata from an XML file.
*
* @author Bernhard Schussek <[email protected]>
*
* @deprecated since Symfony 7.3
*/
class XmlFileLoader extends FileLoader
{
Expand All @@ -30,9 +32,12 @@ class XmlFileLoader extends FileLoader
*/
protected array $classes;

public function __construct(string $file)
{
$this->file = $file;
public function __construct(
protected string $file,
) {
trigger_deprecation('symfony/validator', '7.3', \sprintf('The "%s" class is deprecated.', __CLASS__));

parent::__construct($file);
}

public function loadClassMetadata(ClassMetadata $metadata): bool
Expand Down
Loading

0 comments on commit 5d1465d

Please sign in to comment.