ソースを参照

[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
Bulat Shakirzyanov 14 年 前
コミット
d447d22809

+ 27 - 0
src/Symfony/Bundle/DoctrineAbstractBundle/Common/DataFixtures/Loader.php

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

+ 1 - 1
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);

+ 4 - 4
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);