sp / fixture-dumper
Dump fixtures from doctrine.
Installs: 14 592
Dependents: 2
Suggesters: 0
Security: 0
Stars: 9
Watchers: 4
Forks: 15
Open Issues: 1
Requires
- php: >=5.3.2
- doctrine/common: >=2.2,<2.7-dev
- jms/cg: ~1.2
- phpcollection/phpcollection: ~0.4
- symfony/filesystem: ^2.2|^3.0
- symfony/options-resolver: ^2.2|^3.0
- symfony/property-access: ^2.2|^3.0
Requires (Dev)
- doctrine/data-fixtures: ~1.1
- doctrine/mongodb-odm: ^1.0.8
- doctrine/orm: >=2.2,<2.7-dev
- phpunit/phpunit: ~4.6
- symfony/yaml: ^2.2|^3.0
Suggests
- doctrine/data-fixtures: For loading fixtures
- doctrine/mongodb-odm: For dumping MongoDB ODM fixtures
- doctrine/orm: For dumping ORM fixtures
- doctrine/phpcr-odm: For dumping PHPCR ODM fixtures
- nelmio/alice: To load fixtures in yml or array format
- symfony/yaml: If you want to dump fixtures in yml format
README
This library aims to provide a simple way to dump fixtures for the Doctrine ORM/ODM.
Note: This library is still in an early stage.
Installation
This is installable via Composer as sp/fixture-dumper.
Usage
Basic Usage
$manager = ...; // entity or document manager $registry = new \Sp\FixtureDumper\Converter\Handler\HandlerRegistry(); $registry->addSubscribingHandler(new \Sp\FixtureDumper\Converter\Handler\DateHandler()); // for creating fixtures classes $generator = new \Sp\FixtureDumper\Generator\ClassFixtureGenerator(); // for creating yml files which can be loaded with the alice fixtures library $ymlGenerator = new \Sp\FixtureDumper\Generator\Alice\YamlFixtureGenerator(); // for creating array files which can be loaded with the alice fixtures library $arrayGenerator = new \Sp\FixtureDumper\Generator\Alice\ArrayFixtureGenerator(); $generatorMap = new \PhpCollection\Map(array('class' => $generator, 'yml' => $ymlGenerator, 'array' => $arrayGenerator)); $dumper = new \Sp\FixtureDumper\ORMDumper($manager, $registry, $generatorMap); // or $dumper = new \Sp\FixtureDumper\MongoDBDumper($manager, $registry, $generatorMap); // $dumper->setDumpMultipleFiles(false); // the second argument specifies the generator type you want to use $dumper->dump('/your/workspace/src/Acme/DemoBundle/DataFixtures/ORM', 'array');
Exclusion Strategy
You can implement the interface ExclusionStrategyInterface
to define the strategy to select the entities to dump.
// ... $dumper = new \Sp\FixtureDumper\ORMDumper($manager, $registry, $generatorMap); // The entity Post and Comment won't be dumped $exclusion = new ArrayExclusionStrategy(['Post', 'Acme\DemoBundle\Entity\Comment']); $dumper->setExclusionStrategy($exclusion); $dumper->dump(...);
Options
AbstractDumper#dump
accepts a third $options
argument that is an array
with the following keys:
- namespace: The namespace for the generated class to use This options is only required when using the ClassFixtureGenerator
License
Released under the MIT License, see LICENSE.