8000 bug #58865 Dynamically fix compatibility with doctrine/data-fixtures … · symfony/symfony@c098762 · GitHub
[go: up one dir, main page]

Skip to content

Commit c098762

Browse files
bug #58865 Dynamically fix compatibility with doctrine/data-fixtures v2 (greg0ire)
This PR was merged into the 5.4 branch. Discussion ---------- Dynamically fix compatibility with doctrine/data-fixtures v2 | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | see explanation below | License | MIT While working on [allowing v2 of doctrine/data-fixtures in the bundle](doctrine/DoctrineFixturesBundle#457), I stumbled upon an issue that only affects some versions of Symfony that still have a `ContainerAwareLoader` class. The signature of `ContainerAwareLoader::addFixture()` is not compatible with the v2 signature of the `Loader` interface from `doctrine/data-fixtures`, as per this fatal error: ``` Declaration of Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader::addFixture(Doctrine\Common\DataFixtures\FixtureInterface $fixture) must be compatible with Doctrine\Common\DataFixtures\Loader::addFixture(Doctrine\Common\DataFixtures\FixtureInterface $fixture): void ``` Classes that extend ContainerAwareLoader have to also extend Loader, meaning this is no breaking change because it can be argued that the incompatibility of the extending class would be with the Loader interface. Closes #58861, Closes #58863 Commits ------- 1812aaf Dynamically fix compatibility with doctrine/data-fixtures v2
2 parents 32d55d7 + 1812aaf commit c098762

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
"doctrine/annotations": "^1.13.1|^2",
128128
"doctrine/cache": "^1.11|^2.0",
129129
"doctrine/collections": "^1.0|^2.0",
130-
"doctrine/data-fixtures": "^1.1",
130+
"doctrine/data-fixtures": "^1.1|^2",
131131
"doctrine/dbal": "^2.13.1|^3.0",
132132
"doctrine/orm": "^2.7.4",
133133
"guzzlehttp/promises": "^1.4|^2.0",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\DataFixtures;
13+
14+
use Doctrine\Common\DataFixtures\FixtureInterface;
15+
use Doctrine\Common\DataFixtures\ReferenceRepository;
16+
17+
if (method_exists(ReferenceRepository::class, 'getReferences')) {
18+
/** @internal */
19+
trait AddFixtureImplementation
20+
{
21+
public function addFixture(FixtureInterface $fixture)
22+
{
23+
$this->doAddFixture($fixture);
24+
}
25+
}
26+
} else {
27+
/** @internal */
28+
trait AddFixtureImplementation
29+
{
30+
public function addFixture(FixtureInterface $fixture): void
31+
{
32+
$this->doAddFixture($fixture);
33+
}
34+
}
35+
}

src/Symfony/Bridge/Doctrine/DataFixtures/ContainerAwareLoader.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@
2525
*/
2626
class ContainerAwareLoader extends Loader
2727
{
28+
use AddFixtureImplementation;
29+
2830
private $container;
2931

3032
public function __construct(ContainerInterface $container)
3133
{
3234
$this->container = $container;
3335
}
3436

35-
/**
36-
* {@inheritdoc}
37-
*/
38-
public function addFixture(FixtureInterface $fixture)
37+
private function doAddFixture(FixtureInterface $fixture): void
3938
{
4039
if ($fixture instanceof ContainerAwareInterface) {
4140
$fixture->setContainer($this->container);

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"symfony/var-dumper": "^4.4|^5.0|^6.0",
4646
"doctrine/annotations": "^1.10.4|^2",
4747
"doctrine/collections": "^1.0|^2.0",
48-
"doctrine/data-fixtures": "^1.1",
48+
"doctrine/data-fixtures": "^1.1|^2",
4949
"doctrine/dbal": "^2.13.1|^3|^4",
5050
"doctrine/orm": "^2.7.4|^3",
5151
"psr/log": "^1|^2|^3"

0 commit comments

Comments
 (0)
0