feeltr/fixture-loader-bundle

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

数据库迁移期间的 Doctrine fixtures 加载器

安装: 142

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 0

开放问题: 0

类型:symfony-bundle

0.3 2016-01-24 15:58 UTC

This package is not auto-updated.

Last update: 2018-04-28 12:32:32 UTC


README

此包允许你在数据库迁移期间执行 Doctrine fixtures

安装

首先使用 composer 安装包

$ composer require feeltr/fixture-loader-bundle

安装包后,在 app/AppKernel.php 中添加此包

// AppKernel::registerBundles()
$bundles = array(
    // ...
    new Feeltr\Bundle\FixtureLoaderBundle\FixtureLoaderBundle(),
    // ...
);

使用方法

通过扩展 FixtureLoaderMigration 来在迁移期间访问 fixtures 加载器

<?php

namespace Application\Migrations;

use Feeltr\Bundle\FixtureLoaderBundle\Component\FixtureLoaderMigration;

class Version20150809022933 extends FixtureLoaderMigration
{
    /**
     * @param Schema $schema
     */
    public function up(Schema $schema)
    {
        // ...
    }

    /**
     * @param Schema $schema
     */
    public function down(Schema $schema)
    {
        // ...
    }

    /**
     * @param Schema $schema
     */
    public function postUp(Schema $schema)
    {
        $this->loadFixtures([
            new Fixture(),
            ...
        ]);
    }
}

此外,您还可以使用服务容器中定义的 fixtures 加载器

$fixtureLoader = $this->container->get('feeltr_fixture_loader');
$fixtureLoader->load([new Fixture()]);

最后,您可以通过在 app/config/config.yml 中的 symfony 包配置中禁用日志。默认情况下,日志是启用的。

feeltr_fixture_loader:
    logging: false