[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
This commit is contained in:
Bulat Shakirzyanov 2011-02-07 19:43:45 -05:00 committed by Fabien Potencier
parent 734be8107c
commit d447d22809
3 changed files with 32 additions and 5 deletions

View File

@ -0,0 +1,27 @@
<?php
namespace Symfony\Bundle\DoctrineAbstractBundle\Common\DataFixtures;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\Loader as BaseLoader;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
class Loader extends BaseLoader
{
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function addFixture(FixtureInterface $fixture)
{
if ($fixture instanceof ContainerAwareInterface) {
$fixture->setContainer($container);
}
parent::addFixture($fixture);
}
}

View File

@ -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);

View File

@ -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);