https://github.com/codeedu/zendexpr-doctrine-fixture
Zend Expressive Library that provides Doctrine Data-Fixture functionality
https://github.com/codeedu/zendexpr-doctrine-fixture
Last synced: about 1 year ago
JSON representation
Zend Expressive Library that provides Doctrine Data-Fixture functionality
- Host: GitHub
- URL: https://github.com/codeedu/zendexpr-doctrine-fixture
- Owner: codeedu
- Created: 2016-06-09T00:56:56.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2020-06-08T23:48:50.000Z (about 6 years ago)
- Last Synced: 2025-04-12T18:16:26.661Z (about 1 year ago)
- Language: PHP
- Size: 13.7 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/codeedu/zendexpr-doctrine-fixture)
## About
This library provides integration with Zend Expressive and Doctrine Data Fixture. Also support PSR-11.
## Get started
##### Instalation
```sh
composer require codeedu/zendexpr-doctrine-fixture:0.1.1
```
##### Registering Fixtures
To register fixtures add the fixtures in your configuration.
```php
[
'doctrine' => [
'fixture' => [
'MyFixtures' => __DIR__ . '/../src/Fixture',
]
]
];
```
Register factory to create the command:
```php
[
'factories' => [
'doctrine:fixtures_cmd:load' => \CodeEdu\FixtureFactory::class
]
];
```
We suggest to configure Doctrine ORM and commands with Zend Expressive using this [gist](https://gist.github.com/argentinaluiz/a14df7b1ef73cc111b280e417f84ba92).
This configuration uses [DoctrineModule](https://github.com/doctrine/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:
```php
$command = [
//.....,
'doctrine:fixtures_cmd:load'
];
```
## Usage
#### Command Line
Access the Doctrine command line as following
#### Import
```sh
./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:
```php
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;
}
}
```