api-skeletons/zf-doctrine-data-fixture 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

api-skeletons/zf-doctrine-data-fixture

最新稳定版本:5.0.9

Composer 安装命令:

composer require api-skeletons/zf-doctrine-data-fixture

包简介

Doctrine Data Fixture Console Route with Service Manager configured Fixtures

README 文档

README

Build status Gitter Patreon Total Downloads

This provides command line support for Doctrine Fixtures in Zend Framework 2. Often projects will have multiple sets of fixtures for different object managers or modules such as from a 3rd party API. When this is the case a tool which can run fixtures in groups is needed. Additionally dependency injection must be available to the fixtures. To accomplish these needs this module uses a Zend Service Manager configurable on a per-group basis.

Releases

The 4.x release tags support PHP 5.6 and 7.0.

The 5.x release tags support PHP 7.1 and above.

Installation

Installation of this module uses composer. For composer documentation, please refer to getcomposer.org.

$ composer require api-skeletons/zf-doctrine-data-fixture ^2.0

Add this module to your application's configuration:

'modules' => [
   ...
   'ZF\Doctrine\DataFixture',
],

zf-component-installer

If you use zf-component-installer, that plugin will install zf-doctrine-data-fixture as a module for you.

Configuration

This module builds on top of Doctrine configuration. The configuration in a module which implements fixtures is:

return [
    'doctrine' => [
        'fixture' => [
            'group1' => [
                'object_manager' => 'doctrine.entitymanager.orm_default',
                'invokables' => [
                    'ModuleName\Fixture\FixtureOne' => 'ModuleName\Fixture\FixtureOne',
                ],
                'factories' => [
                    'ModuleName\Fixture\FixtureTwo' => 'ModuleName\Fixture\FixtureTwoFactory',
                ]
            ],
            'group2' => [
                'object_manager' => 'doctrine.entitymanager.orm_zf_doctrine_audit',
                ...
            ],
        ],
    ],
];

Each group is a Zend ServiceManager configuration. This allows complete dependency injection control of your fixtures.

Listing Fixtures

index.php data-fixture:list [<group>]

List all object managers and their groups, list all groups for a given object manager, or specify object manager and group to list all fixtures for a group.

Executing Fixtures from Command Line

index.php data-fixture:import <group> [--purge-with-truncate] [--do-not-append]

The <group> is required.

The default was to not append and this was constantly overridden with --append. Append is now to the default option. This is inversed with the new --do-not-append

Options:

--purge-with-truncate if specified will purge the object manager's tables before running fixtures.

--do-not-append will delete all data in the database before running fixtures.

Executing Fixtures from Code

For unit testing or other times you must run your fixtures from within code you must fetch the DataFixtureManager with build and pass the group name to the service manager then load the fixtures into the Loader manually.

use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use ZF\Doctrine\DataFixture\Loader;

// Run audit fixtures
$dataFixtureManager = $application->getServiceManager()
    ->build('ZF\Doctrine\DataFixture\DataFixtureManager', ['group' => 'zf-doctrine-audit']);

$loader = new Loader($dataFixtureManager);
$purger = new ORMPurger();
$executor = new ORMExecutor($auditEntityManager, $purger);

foreach ($dataFixtureManager->getAll() as $fixture) {
    $loader->addFixture($fixture);
}

$executor->execute($loader->getFixtures(), true);

Getting Help

index.php data-fixture:help

Important Notes

  • You can only run one group at a time from the command line. If you need to run more create a script to run them in sequence.
  • The ServiceManager is injected into each DataFixtureManager at getServiceLocator() so you can use instantiators which run from that level. This makes the DataFixtureManager work like a plugin manager defined with $serviceListener->addServiceManager().
  • You cannot use abstract factories. Each fixture must be individually configured.

History

Version 1.0 of this module grouped groups by partial object manager alias. This limited grouping of 3rd party fixtures and the flexibility of using ODM.

This module is a near complete rewrite of hounddog/doctrine-data-fixture-module. All the patterns have changed and the code was reduced. That module served me and the community well for a long time.

统计信息

  • 总下载量: 23.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 1
  • Forks: 70
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-06-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固