merged branch jmikola/doctrine-data-fixtures (PR #3328)

Commits
-------

c754f28 [DoctrineBridge] Rename data fixtures loader class
af84805 [DoctrineBridge] Suggest doctrine/data-fixtures dependency
e4243a1 [DoctrineBridge] Add common data fixtures loader

Discussion
----------

[DoctrineBridge] Add common data fixtures loader

Symfony does not depend on doctrine/data-fixtures, but having this class in the bridge would enable DoctrineMongoDBBundle (and possibly others) to load fixtures without requiring DoctrineFixturesBundle to be installed.

Additionally, DoctrineFixturesBundle seems to only consist of this class and a command for loading ORM fixtures. With this in the bridge, we can possibly eliminate DoctrineFixturesBundle altogether by merging its command into DoctrineBundle.

---------------------------------------------------------------------------

by stof at 2012-02-11T19:40:17Z

The reason to have a separate bundle for the ORM fixtures was that the ORM is released whereas the DataFixtures library is still in alpha versions. So we wanted to avoid having it in Symfony itself for the 2.0 release. It could maybe change now that we have the bundle in a separate repo.
The other solution could be to put all commands related to fixtures in DoctrineFixturesBundle but IIRC @beberlei rejected a PR trying to make the same command work for ORM and PHPCR.

@beberlei what do you think about these suggestions ? And what is missing in DataFixtures to release it ? It has not changed recently except for the addition of the typehint and an update of the PHPCR purger

---------------------------------------------------------------------------

by fabpot at 2012-02-14T23:30:23Z

The Symfony bridges provide integration between a third-party library and Symfony components. IIUC, this PR is only about Doctrine and as such it is not in the scope of the bridge. It should be done "somewhere" in the Doctrine namespace (what about common for instance?).

---------------------------------------------------------------------------

by stof at 2012-02-14T23:34:19Z

@fabpot no it is not a Doctrine-only code. This extended loader is about integrating the Doctrine DataFixtures library with the DI component to allow fixtures to be container-aware (it does absolutely nothing else fancy btw). So this *is* in the scope of the bridge.

---------------------------------------------------------------------------

by jmikola at 2012-02-15T00:40:12Z

I second @stof's point here. This class is specifically for loading fixtures into application with a service container. Likewise, that is why the base class it inherits is in the common data-fixtures library.

Since this is common to both ORM and ODM, the most logical home for it would be DoctrineCommonBundle, and I believe that's what the bridge is :)

---------------------------------------------------------------------------

by stof at 2012-02-15T01:53:17Z

@jmikola not even a DoctrimeCommonBundle IMO. This is not about integrating things with the fullstack framework but with one component
This commit is contained in:
Fabien Potencier 2012-02-15 11:00:50 +01:00
commit e7adf546ef
3 changed files with 59 additions and 1 deletions

View File

@ -52,6 +52,9 @@
"symfony/validator": "self.version",
"symfony/yaml": "self.version"
},
"suggest": {
"doctrine/data-fixtures": "1.0.*"
},
"autoload": {
"psr-0": { "Symfony": "src/" }
}

View File

@ -0,0 +1,54 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bridge\Doctrine\DataFixtures;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\Loader;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Doctrine data fixtures loader that injects the service container into
* fixture objects that implement ContainerAwareInterface.
*
* Note: Use of this class requires the Doctrine data fixtures extension, which
* is a suggested dependency for Symfony.
*/
class ContainerAwareLoader extends Loader
{
/**
* @var ContainerInterface
*/
private $container;
/**
* Constructor.
*
* @param ContainerInterface $container A ContainerInterface instance
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* {@inheritdoc}
*/
public function addFixture(FixtureInterface $fixture)
{
if ($fixture instanceof ContainerAwareInterface) {
$fixture->setContainer($this->container);
}
parent::addFixture($fixture);
}
}

View File

@ -26,7 +26,8 @@
},
"suggest": {
"symfony/form": "self.version",
"symfony/validator": "self.version"
"symfony/validator": "self.version",
"doctrine/data-fixtures": "1.0.*"
},
"autoload": {
"psr-0": { "Symfony\\Bridge\\Doctrine": "" }