playground/doctrine-data-fixture-module

Laminas 模块,提供 Doctrine Data-Fixture 功能

1.1.4 2022-06-08 07:45 UTC

This package is auto-updated.

Last update: 2024-09-08 12:54:42 UTC


README

简介

这是从 Houndog/DoctrineDataFixtureModule 分支出来的。

DoctrineDataFixtureModule 模块旨在将 Doctrine2 ORM Data Fixtures 与 Zend Framework 3 集成。

安装

此模块的安装使用 composer。有关 composer 文档,请参阅 getcomposer.org

$ php composer.phar require dkorsak/doctrine-data-fixture-module

然后打开 config/application.config.php 并将 DoctrineModuleDoctrineORMModuleDoctrineDataFixtureModule 添加到您的 modules

注册 Fixtures

要使用 Doctrine 模块注册 fixtures,请在配置中添加 fixtures。

<?php
return array(
    'doctrine' => array(
        'fixture' => array(
            'ModuleName' => __DIR__ . '/../src/ModuleName/Fixture',
        )
    )
);

用法

默认

./vendor/bin/doctrine-module orm:fixtures:load 

使用截断而不确认清除数据

./vendor/bin/doctrine-module orm:fixtures:load -n --purge-with-truncate 

添加数据而不是删除

./vendor/bin/doctrine-module orm:fixtures:load -n --append

如何将容器注入 fixtures 文件

<?php

namespace Application\DataFixtures;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use DoctrineDataFixtureModule\ContainerAwareInterface;
use DoctrineDataFixtureModule\ContainerAwareTrait;

class LoadUser implements FixtureInterface, ContainerAwareInterface
{
    use ContainerAwareTrait;

    /**
     * @param ObjectManager $manager
     */
    public function load(ObjectManager $manager)
    {
        $myService = $this->container->get('my_service');        
    }
}