okvpn/fixture-bundle
Composer 安装命令:
composer require okvpn/fixture-bundle
包简介
关键字:
README 文档
README
Intro
Symfony allows to load data using data fixtures. But these fixtures are run each time when doctrine:fixtures:load command is executed.
To avoid loading the same fixture several time, okvpn:fixtures:data:load command was created. This command guarantees that each data fixture will be loaded only once.
This command supports two types of migration files: main data fixtures and demo data fixtures. During an installation, user can select to load or not demo data.
Fixtures order can be changed with standard Doctrine ordering or dependency functionality. More information about fixture ordering can be found in doctrine data fixtures manual.
Installation
Install using composer:
composer require okvpn/fixture-bundle
And this bundle to your AppKernel:
<?php use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; class AppKernel extends Kernel { public function registerBundles() { $bundles = array( new Okvpn\Bundle\FixtureBundle\OkvpnFixtureBundle(), //... ); } public function registerContainerConfiguration(LoaderInterface $loader) { $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml'); } }
Configure directories for put data fixtures and table name in config.yml
okvpn_fixture: table: okvpn_fixture_data path_main: Migrations/Data/ORM path_demo: Migrations/Data/Demo/ORM
Base Example
Create file src/Akuma/PassBundle/Migrations/Data/ORM/TestFixture.php
<?php // src/Akuma/PassBundle/Migrations/Data/ORM/TestFixture.php namespace Akuma\PassBundle\Fixture\Data; use Akuma\PassBundle\Entity\Item; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\Persistence\ObjectManager; class TestFixture extends AbstractFixture { public function load(ObjectManager $manager) { $item = new Item(); $item->setHumidity(58.00) ->setTemp(10.8) ->setPressure(1019.23) ->setTimestamp(new \DateTime()); $manager->persist($item); $manager->flush(); } }
And run command okvpn:fixtures:data:load to load it.
Versioned fixtures
There are fixtures which need to be executed time after time. An example is a fixture which uploads countries data. Usually, if you add new countries list, you need to create new data fixture which will upload this data. To avoid this you can use versioned data fixtures.
To make fixture versioned, this fixture must implement VersionedFixtureInterface and getVersion method which returns a version of fixture data.
Example:
<?php namespace Acme\DemoBundle\Migrations\DataFixtures\ORM; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\Persistence\ObjectManager; use Okvpn\Bundle\FixtureBundle\Fixture\VersionedFixtureInterface; class LoadSomeDataFixture extends AbstractFixture implements VersionedFixtureInterface { /** * {@inheritdoc} */ public function getVersion() { return '1.0'; } /** * {@inheritdoc} */ public function load(ObjectManager $manager) { // Here we can use fixture data code which will be run time after time } }
In this example, if the fixture was not loaded yet, it will be loaded and version 1.0 will be saved as current loaded version of this fixture.
To have possibility to load this fixture again, the fixture must return a version greater then 1.0, for example 1.0.1 or 1.1. A version number must be an PHP-standardized version number string. More info about PHP-standardized version number string can be found in PHP manual.
If a fixture need to know the last loaded version, it must implement LoadedFixtureVersionAwareInterface and setLoadedVersion method:
<?php namespace Acme\DemoBundle\Migrations\DataFixtures\ORM; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\Persistence\ObjectManager; use Okvpn\Bundle\FixtureBundle\Fixture\VersionedFixtureInterface; use Okvpn\Bundle\FixtureBundle\Fixture\RequestVersionFixtureInterface; class LoadSomeDataFixture extends AbstractFixture implements VersionedFixtureInterface, LoadedFixtureVersionAwareInterface { /** * @var $currendDBVersion string */ protected $currendDBVersion = null; /** * {@inheritdoc} */ public function setLoadedVersion($version = null) { $this->currendDBVersion = $version; } /** * {@inheritdoc} */ public function getVersion() { return '2.0'; } /** * {@inheritdoc} */ public function load(ObjectManager $manager) { // Here we can check last loaded version and load data data difference between last // uploaded version and current version } }
Licence
MIT License
okvpn/fixture-bundle 适用场景与选型建议
okvpn/fixture-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 601 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「fixtures」 「data」 「Demo data」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 okvpn/fixture-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 okvpn/fixture-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 okvpn/fixture-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Testing object factory for PHP
Testing object factory for PHP
Adds the EDTF data type to Wikibase
Plugin to compare fixtures with live DB tables
A simple library that allows transform any kind of data to native php data or whatever
统计信息
- 总下载量: 601
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-13