From d447d22809e3751c5d6c13868c77a1657a8f04bd Mon Sep 17 00:00:00 2001 From: Bulat Shakirzyanov Date: Mon, 7 Feb 2011 19:43:45 -0500 Subject: [PATCH] [DoctrineBundle, DoctrineAbstractBundle, DoctrineMongoDBBundle] added container aware fixture loader Updated load data fixtures command in DoctrineMongoDBBundle to be identical to the one in DoctrineBundle Created custom loader, that passes $container to all ContainerAware DataFixtures --- .../Common/DataFixtures/Loader.php | 27 +++++++++++++++++++ .../LoadDataFixturesDoctrineCommand.php | 2 +- .../LoadDataFixturesDoctrineODMCommand.php | 8 +++--- 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 src/Symfony/Bundle/DoctrineAbstractBundle/Common/DataFixtures/Loader.php diff --git a/src/Symfony/Bundle/DoctrineAbstractBundle/Common/DataFixtures/Loader.php b/src/Symfony/Bundle/DoctrineAbstractBundle/Common/DataFixtures/Loader.php new file mode 100644 index 0000000000..80d12cc313 --- /dev/null +++ b/src/Symfony/Bundle/DoctrineAbstractBundle/Common/DataFixtures/Loader.php @@ -0,0 +1,27 @@ +container = $container; + } + + public function addFixture(FixtureInterface $fixture) + { + if ($fixture instanceof ContainerAwareInterface) { + $fixture->setContainer($container); + } + + parent::addFixture($fixture); + } +} diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php index f0557b34ef..9f32ff281c 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php @@ -72,7 +72,7 @@ EOT } } - $loader = new \Doctrine\Common\DataFixtures\Loader(); + $loader = $loader = new \Symfony\Bundle\DoctrineAbstractBundle\Common\DataFixtures\Loader($this->container); foreach ($paths as $path) { if (is_dir($path)) { $loader->loadFromDirectory($path); diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php index 51609ab4d3..a910d1c041 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php @@ -72,11 +72,11 @@ EOT } } - $paths = array_filter($paths, 'is_dir'); - - $loader = new \Doctrine\Common\DataFixtures\Loader(); + $loader = new \Symfony\Bundle\DoctrineAbstractBundle\Common\DataFixtures\Loader($this->container); foreach ($paths as $path) { - $loader->loadFromDirectory($path); + if (is_dir($path)) { + $loader->loadFromDirectory($path); + } } $fixtures = $loader->getFixtures(); $purger = new \Doctrine\Common\DataFixtures\Purger\MongoDBPurger($dm);