|
13 | 13 |
|
14 | 14 | use Doctrine\Bundle\PHPCRBundle\DataFixtures\PHPCRExecutor; |
15 | 15 | use Doctrine\Common\DataFixtures\DependentFixtureInterface; |
| 16 | +use Doctrine\Common\DataFixtures\FixtureInterface; |
16 | 17 | use Doctrine\Common\DataFixtures\Loader; |
17 | 18 | use Doctrine\Common\DataFixtures\ProxyReferenceRepository; |
18 | 19 | use Doctrine\Common\DataFixtures\Purger\PHPCRPurger; |
@@ -64,30 +65,40 @@ public function purgeRepository(bool $initialize = false): void |
64 | 65 | } |
65 | 66 |
|
66 | 67 | /** |
67 | | - * @param string[] $classNames Fixture classes to load |
68 | | - * @param bool $initialize if the ODM repository initializers should be executed |
| 68 | + * @param array<class-string|object> $classes Fixture classes or class names to load |
| 69 | + * @param bool $initialize Whether the ODM repository initializers should be executed |
69 | 70 | */ |
70 | | - public function loadFixtures(array $classNames, bool $initialize = false): void |
| 71 | + public function loadFixtures(array $classes, bool $initialize = false): void |
71 | 72 | { |
72 | | - $loader = new ContainerAwareLoader($this->container); |
| 73 | + $loader = class_exists(ContainerAwareLoader::class) |
| 74 | + ? new ContainerAwareLoader($this->container) |
| 75 | + : new Loader() |
| 76 | + ; |
73 | 77 |
|
74 | | - foreach ($classNames as $className) { |
| 78 | + foreach ($classes as $className) { |
75 | 79 | $this->loadFixtureClass($loader, $className); |
76 | 80 | } |
77 | 81 |
|
78 | 82 | $this->getExecutor($initialize)->execute($loader->getFixtures(), false); |
79 | 83 | } |
80 | 84 |
|
81 | | - public function loadFixtureClass(Loader $loader, string $className) |
| 85 | + /** |
| 86 | + * @param class-string|FixtureInterface $class |
| 87 | + */ |
| 88 | + public function loadFixtureClass(Loader $loader, $class) |
82 | 89 | { |
83 | | - if (!class_exists($className)) { |
84 | | - throw new \InvalidArgumentException(sprintf( |
85 | | - 'Fixture class "%s" does not exist.', |
86 | | - $className |
87 | | - )); |
88 | | - } |
| 90 | + if (\is_object($class)) { |
| 91 | + $fixture = $class; |
| 92 | + } else { |
| 93 | + if (!class_exists($class)) { |
| 94 | + throw new \InvalidArgumentException(sprintf( |
| 95 | + 'Fixture class "%s" does not exist.', |
| 96 | + $class |
| 97 | + )); |
| 98 | + } |
89 | 99 |
|
90 | | - $fixture = new $className(); |
| 100 | + $fixture = new $class(); |
| 101 | + } |
91 | 102 |
|
92 | 103 | if ($loader->hasFixture($fixture)) { |
93 | 104 | unset($fixture); |
|
0 commit comments