api-skeletons/doctrine-data-fixture
Composer 安装命令:
composer require api-skeletons/doctrine-data-fixture
包简介
Doctrine Data Fixtures with Grouping for Laminas
README 文档
README
This provides command line support for Doctrine Fixtures in Laminas. 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 Service Manager configurable on a per-group basis.
Releases
The 6.x release tags support PHP 7.2 and above.
Installation
Installation of this module uses composer. For composer documentation, please refer to getcomposer.org.
$ composer require api-skeletons/doctrine-data-fixture
Add this module to your application's configuration:
'modules' => [ ... 'ApiSkeletons\Doctrine\DataFixture', ],
laminas-component-installer
If you use laminas-component-installer, that plugin will install 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', 'executor' => Executor::class, 'purger' => Purger::class, '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 Laminas ServiceManager configuration. This allows complete dependency injection control of your fixtures.
The 'executor' and 'purger' keys are optional and allow for custom classes for these functions. If omitted the Doctrine ORM classes will be used.
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.
Append is 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 ApiSkeletons\Doctrine\DataFixture\Loader; // Run audit fixtures $dataFixtureManager = $application->getServiceManager() ->build('ApiSkeletons\Doctrine\DataFixture\DataFixtureManager', ['group' => 'group-name']); $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.
api-skeletons/doctrine-data-fixture 适用场景与选型建议
api-skeletons/doctrine-data-fixture 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41.59k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「doctrine」 「data-fixture」 「laminas」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 api-skeletons/doctrine-data-fixture 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 api-skeletons/doctrine-data-fixture 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 api-skeletons/doctrine-data-fixture 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Zend Framework 2 Module that provides Doctrine Data-Fixture functionality
Zend Framework 3 Module that provides Doctrine Data-Fixture functionality
Zend Framework 3 Module that provides Doctrine Data-Fixture functionality
This package provide a Geo modules for yawik.
PSR-11 Aura.DI container configurator for Laminas and Mezzio applications. Drop-in replacement for the archived laminas/laminas-auradi-config with PHP 8.4 and 8.5 support.
Make pimcore migration simple
统计信息
- 总下载量: 41.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-09