8000 Dynamically fix compatibility with doctrine/data-fixtures v2 · symfony/symfony@e20459a · GitHub
[go: up one dir, main page]

Skip to content

Commit e20459a

Browse files
committed
Dynamically fix compatibility with doctrine/data-fixtures v2
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.
1 parent 4b8695c commit e20459a

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function addFixture(FixtureInterface $fixture)
25+
{
26+
$this->doAddFixture($fixture);
27+
}
28+
}
29+
} else {
30+
/** @internal */
31+
trait AddFixtureImplementation
32+
{
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function addFixture(FixtureInterface $fixture): void
37+
{
38+
$this->doAddFixture($fixture);
39+
}
40+
}
41+
}

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