kunstmaan / fixtures-bundle
使用此包,您可以通过yaml文件轻松地创建固定数据
Requires
- php: ^8.1
- doctrine/doctrine-fixtures-bundle: ^3.3
- fakerphp/faker: ^1.15
- kunstmaan/admin-bundle: ^7.0
- kunstmaan/media-bundle: ^7.0
- kunstmaan/menu-bundle: ^7.0
- kunstmaan/node-bundle: ^7.0
- kunstmaan/pagepart-bundle: ^7.0
- kunstmaan/utilities-bundle: ^7.0
- symfony/mime: ^5.4|^6.4
- symfony/string: ^5.4|^6.4
Requires (Dev)
- matthiasnoback/symfony-config-test: ^4.2.1
- matthiasnoback/symfony-dependency-injection-test: ^4.2.1
- phpunit/phpunit: ^9.5.5
- symfony/phpunit-bridge: ^7.0
Conflicts
- doctrine/persistence: <1.3
- 7.x-dev
- 7.1.x-dev
- 7.1.1
- 7.1.0
- 7.1.0-alpha2
- 7.1.0-alpha1
- 7.0.x-dev
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 7.0.0-alpha1
- 6.x-dev
- 6.4.x-dev
- 6.4.2
- 6.4.1
- 6.4.0
- 6.4.0-alpha2
- 6.4.0-alpha1
- 6.3.x-dev
- 6.3.1
- 6.3.0
- 6.2.x-dev
- 6.2.5
- 6.2.4
- 6.2.3
- 6.2.2
- 6.2.1
- 6.2.0
- 6.1.x-dev
- 6.1.9
- 6.1.8
- 6.1.7
- 6.1.6
- 6.1.5
- 6.1.4
- 6.1.3
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.x-dev
- 6.0.6
- 6.0.5
- 6.0.4
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.10.x-dev
- dev-master / 5.10.x-dev
- 5.10.7
- 5.10.6
- 5.10.5
- 5.10.4
- 5.10.3
- 5.10.2
- 5.10.1
- 5.10.0
- 5.9.x-dev
- 5.9.3
- 5.9.2
- 5.9.1
- 5.9.0
- 5.8.x-dev
- 5.8.1
- 5.8.0
- 5.7.x-dev
- 5.7.3
- 5.7.2
- 5.7.1
- 5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-14 17:43:07 UTC
README
您仍将使用默认的doctrine固定数据方式,但不是从Doctrine\Common\DataFixtures\AbstractFixture
类扩展,而是从Kunstmaan\FixturesBundle\Loader\FixtureLoader
类扩展。
这将是您的固定类的外观
<?php namespace Acme\SomeBundle\DataFixtures\ORM\DefaultSiteGenerator; use Doctrine\Common\DataFixtures\OrderedFixtureInterface; use Kunstmaan\FixturesBundle\Loader\FixtureLoader; class YamlFixtures extends FixtureLoader implements OrderedFixtureInterface { protected function getFixtures() { return [ __DIR__ . '/media.yml', __DIR__ . '/default.yml', ]; } /** * Get the order of this fixture * * @return integer */ public function getOrder() { return 50; } }
Yaml吗?
是的!创建固定数据从未如此简单。它受到了Nelmio/Alice包的启发。我们为什么不使用那个包呢?那是因为Nelmio/Alice非常适合“简单”实体,但我们的CMS在创建页面和页面部分时会发生很多操作。因此,我们希望从头开始而不是在其他包中修改。
那么这些yaml文件是什么样的呢?
\Kunstmaan\MediaBundle\Entity\Media: image_homepage-header: folder: image originalFilename: <getMediaPath()>homepage-header.jpg image_{some.svg, this.svg, that.svg, yes.svg, no.svg}: folder: image originalFilename: <getMediaPath()><current()> \Acme\SomeBundle\Entity\Pages\HomePage: homepage: title: <word()> parameters: page_internal_name: homepage set_online: true hidden_from_nav: false creator: <adminUser()> translations: nl: title: Home fr: title: Home \Acme\SomeBundle\Entity\Pages\ContentPage: content{1..10}: title: <word()> parameters: parent: @homepage page_internal_name: content<current()> set_online: true hidden_from_nav: false creator: <adminUser()> translations: nl: [] fr: [] \Acme\SomeBundle\Entity\Contact: contact_{ironman, blackwidow, thor, hulk, captainamerica, hawkeye}: firstName: <firstName()> lastName: <lastName()> email: <email()> function: <word()> mobile: <phoneNumber()> phone: <phoneNumber()> \Acme\SomeBundle\Entity\PageParts\HeaderPagePart: header_pp_{1..10}: title: <word()> niv: 1 parameters: page: @content<current()> context: header translations: nl: [] fr: [] \Acme\SomeBundle\Entity\PageParts\ContactPagePart: contact_pp_{1..5}: contacts: - @contact_ironman - @contact_blackwidow - @contact_thor parameters: page: @content<current()> context: main translations: nl: [] fr: [] contact_pp_{6..10}: contacts: - @contact_hulk - @contact_captainamerica - @contact_hawkeye parameters: page: @content<current()> context: main translations: nl: [] fr: []
提供者
提供者是用于向固定数据返回数据的类。例如,如果您使用<current()>
方法,则将调用Spec提供者。所以如果您想添加一些功能以轻松返回页面创建者的值,您可以添加一个包含该方法的提供者。
public function adminUser() { return 'admin'; }
默认情况下,您可以将这些类型的函数添加到您的固定类中,因为它会自动作为提供者添加。
此外,您还有Spec提供者、NodeTranslation提供者和Faker提供者。您可以通过将函数getProviders()
添加到您的固定类并返回包含您的提供者的数组来添加自己的提供者,或者您可以通过添加kunstmaan_fixtures.provider
标记来标记您的提供者。
解析器
解析器用于将yaml数据转换为实际数据。因此,类似于@content<current()>
的内容将通过不同的解析器转换为对象。默认情况下,您有Method和Reference解析器用于属性数据,以及Listed和Range解析器用于规范。如果您想添加自己的解析器,只需通过标记它们为kunstmaan_fixtures.parser.property
或kunstmaan_fixtures.parser.spec
即可。
填充器
填充器正好与名称相符。填充器将在解析所有yaml数据后填充实体。如果您想添加自己的填充器,只需通过添加kunstmaan_fixtures.populator
标记即可。
构建器
使用构建器,您可以在创建实体的过程中操纵行为。这可以在三个阶段发生:预构建、后构建和后刷新构建。在这些阶段中,您可以操纵实体或添加更多实体,例如我们可以在PageBuilder中做的那样。如果您想添加自己的构建器,只需通过标记它们为kunstmaan_fixtures.builder
即可。