lichnow/alice-bundle

Symfony2 Bundle 用于使用 Alice 和 Faker 管理固定数据。

安装: 6

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

dev-dev-master 2016-01-30 03:00 UTC

This package is auto-updated.

Last update: 2024-09-22 09:49:02 UTC


README

一个用于使用 Symfonynelmio/alice 以及 fzaninotto/Faker 管理固定数据的 bundle。

目前支持 Doctrine ORMDoctrine ODMDoctrine PHPCR ODM

Package version Build Status SensioLabsInsight Dependency Status Scrutinizer Code Quality Code Coverage HHVM support

Gitter

文档

  1. 安装
  2. 基本用法
  3. 高级用法
    1. 启用数据库
    2. 固定数据参数
    3. Doctrine ORM
    4. Doctrine ODM (MongoDB)
    5. Doctrine PHPCR ODM
  4. 自定义 Faker 提供者
    1. 简单提供者
    2. 高级提供者
  5. 自定义 Alice 处理器
  6. DoctrineFixturesBundle 支持
  7. 资源

其他参考

安装

首先,根据您的项目需求安装适当的数据库管理器(如果您还没有安装),请参考此处的文档。

您可以使用 Composer 将 bundle 安装到您的项目中

composer require --dev hautelook/alice-bundle

然后,通过更新您的 app/config/AppKernel.php 文件来启用 bundle

<?php
// app/config/AppKernel.php

public function registerBundles()
{
    //...
    if (in_array($this->getEnvironment(), ['dev', 'test'])) {
        //...
        $bundles[] = new Hautelook\AliceBundle\HautelookAliceBundle();
    }

    return $bundles;
}

根据您的需求配置 bundle(示例使用默认值)

# app/config/config_dev.yml

hautelook_alice:
    db_drivers:
        orm: ~          # Enable Doctrine ORM if is registered
        mongodb: ~      # Enable Doctrine ODM if is registered
        phpcr: ~        # Enable Doctrine PHPCR ODM if is registered
    locale: en_US       # Locale to used for faker; must be a valid Faker locale otherwise will fallback to en_EN
    seed: 1             # A seed to make sure faker generates data consistently across runs, set to null to disable
    persist_once: false # Only persist objects once if multiple files are passed
    loading_limit: 5    # Maximum number of time the loader will try to load the files passed

有关本地化的更多信息,请参阅 Faker 关于本地化的文档

基本用法

假设您正在使用 Doctrine,请安装 doctrine/doctrine-bundledoctrine/data-fixtures 包,并注册这两个 bundle。然后在 AppBundle/DataFixtures/ORM 中创建一个固定数据文件

# AppBundle/DataFixtures/ORM/dummy.yml

AppBundle\Entity\Dummy:
    dummy_{1..10}:
        name: <name()>
        related_dummy: @related_dummy*
# AppBundle/DataFixtures/ORM/related_dummy.yml

AppBundle\Entity\RelatedDummy:
    related_dummy_{1..10}:
        name: <name()>

然后只需使用 doctrine 命令 php app/console hautelook_alice:doctrine:fixtures:load(或 php app/console h:d:f:l)加载您的固定数据。

如果您只想加载某个 bundle 的固定数据,请执行 php app/console h:d:f:l -b MyFirstBundle -b MySecondBundle

更多内容.
下一章: 高级用法

资源

鸣谢

此 bundle 最初由 Baldur RENSCHHauteLook 开发。现在由 Théo FIDRY 维护。

其他贡献者.

许可证

license