codeedu / zendexpr-doctrine-fixture
Zend Expressive Library that provides Doctrine Data-Fixture functionality
Installs: 7 550
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: ^7.1
- container-interop/container-interop: ~1.0
- doctrine/data-fixtures: 1.3.*
- doctrine/orm: ~2.5
Requires (Dev)
- phpunit/phpunit: 6.0.0
This package is auto-updated.
Last update: 2024-12-09 09:54:36 UTC
README
About
This library provides integration with Zend Expressive and Doctrine Data Fixture. Also support PSR-11.
Get started
Instalation
composer require codeedu/zendexpr-doctrine-fixture:0.1.1
Registering Fixtures
To register fixtures add the fixtures in your configuration.
[ 'doctrine' => [ 'fixture' => [ 'MyFixtures' => __DIR__ . '/../src/Fixture', ] ] ];
Register factory to create the command:
[ 'factories' => [ 'doctrine:fixtures_cmd:load' => \CodeEdu\FixtureFactory::class ] ];
We suggest to configure Doctrine ORM and commands with Zend Expressive using this gist. This configuration uses DoctrineModule. DoctrineModule provides easily configuration to integration Doctrine ORM in Zend Framework 2 Applications, so the approach is enjoy it.
Now in doctrine.config.php, so add doctrine:fixtures_cmd:load to:
$command = [ //....., 'doctrine:fixtures_cmd:load' ];
Usage
Command Line
Access the Doctrine command line as following
Import
./vendor/bin/doctrine-module data-fixture:import
Dependency Injection with Fixtures
This library provides inject the service container in fixtures. So add interface FixtureContainerInterface, see below:
class MyFixture implements FixtureInterface, FixtureContainerInterface { private $container; public function load(ObjectManager $manager){ $myService = $this->container->get(MyService::class); } public function getContainer() { return $this->container; } public function setContainer(ContainerInterface $container) { $this->container = $container; } }