amstaffix/alice-fixtures-smart-loader

此包已被废弃且不再维护。未建议替代包。

用于将 Alice 固定数据加载到数据库的库

0.1.7 2014-09-08 13:48 UTC

This package is not auto-updated.

Last update: 2017-08-02 14:30:05 UTC


README

该库允许加载 nelmio/alice (https://github.com/nelmio/alice) 的准备好的固定数据。

该库处于开发中,可能随时更改而不保持向后兼容性。

重要

最初,该库是为了与从工作数据库生成的固定数据一起使用而创建的,因此实体之间的关系没有保存。

因此

  • 库会遍历所有关联并添加必要的联系。(目前仅支持多对一)
  • 如果联系已经在固定数据文件中建立,则库不会替换它
  • 可能存在其他未预见的问题

安装

使用 Composer

$ composer require amstaffix/alice-fixtures-smart-loader:0.1.*

示例

<?php
use Amstaffix\AliceFixturesSmartLoader\FixturesLoader;
// ...
function(ObjectManager $om, $dir) {
    (new FixturesLoader())
        ->withManager($om)
        ->fromDir($dir)
        ->load();
}
// ...

将加载目录中的所有实体,并为每个实体设置相互之间的联系

<?php
use Amstaffix\AliceFixturesSmartLoader\FixturesLoader;
// ...
function(ObjectManager $om, $dir) {
    (new FixturesLoader())
        ->withManager($om)
        ->oneClass("Amstaffix\AliceFixturesSmartLoader\Tests\Entity\Author")
        ->fromDir($dir)
        ->load();
}
// ...

在这种情况下,将仅加载 Author 类的固定数据

<?php
use Amstaffix\AliceFixturesSmartLoader\FixturesLoader;
// ...
function(ObjectManager $om, $dir) {
    (new FixturesLoader())
        ->withManager($om)
        ->oneClass("Amstaffix\AliceFixturesSmartLoader\Tests\Entity\Book")
        ->fromDir($dir)
        ->load();
}
// ...

在这种情况下,将加载 Book 和 Author 的实体,并且将随机设置它们之间的联系。

待办事项