2017 © Pedro Peláez
 

symfony-bundle fixtures-bundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

image

kunstmaan/fixtures-bundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  • Wednesday, August 10, 2016
  • by Kunstmaan
  • Repository
  • 6 Watchers
  • 0 Stars
  • 50 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 30 Versions
  • 0 % Grown

The README.md

How to use the FixturesBundle

You will still use the default doctrine fixtures way but instead of extending from the Doctrine\Common\DataFixtures\AbstractFixture class, you will instead extend from the Kunstmaan\FixturesBundle\Loader\FixtureLoader class., (*1)

This is what your fixture class will look like:, (*2)

<?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 you say?

Yes! Creating fixtures will has never been this easy. It's inspired by the Nelmio/Alice bundle. Why don't we use that bundle? That's because Nelmio/Alice is great for "simple" entities, but with our CMS alot of stuff happens during the creation of pages and pageparts. For this reason we wanted to start from scratch instead of hacking our way into another bundle., (*3)

So how do these yaml files look like?, (*4)

\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: []

Providers

Providers are classes that can be used to return data to a fixture. For example, if you use the <current()> method, the Spec provider will be called upon. So if you want to add some functionality to easily return the value of the page creator, you can add a Provider that contains the method, (*5)

public function adminUser()
{
    return 'admin';
}

By default you can add these kind of methods to your fixture class as it's automatically added as a provider., (*6)

Furthermore you have the Spec provider, NodeTranslation provider and Faker providers. You can add your own by adding the function getProviders() to your fixture class and returning an array containing your providers or you can tag your providers with kunstmaan_fixtures.provider., (*7)

Parsers

Parsers are used to translate the yaml data into actual data. So something like @content<current()> will be transformed to an object by different parsers. By default you have the Method and the Reference parser for property data and the Listed and Range parser for specs. If you want to add your own parser, you can simply to that by tagging them with kunstmaan_fixtures.parser.property or kunstmaan_fixtures.parser.spec, (*8)

Populators

Does exactly what the name says. Populators will populate the entities once all the yaml data is parsed. If you want to add your own populator, simply tag it with kunstmaan_fixtures.populator, (*9)

Builders

With builders you can manipulate the behaviour during the creation of your entity. This can happen in three stages, preBuild, postBuild and postFlushBuild. During these stages you can manipulate your entity or add more entities like we do in the PageBuilder for instance. If you want to add your own builder, simply tag it with kunstmaan_fixtures.builder, (*10)

The Versions

10/08 2016

dev-master

9999999-dev https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

10/08 2016

dev-revert-1243-hotfix/generator-translations

dev-revert-1243-hotfix/generator-translations https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

10/08 2016

dev-revert-1302-bugfix/multidomain

dev-revert-1302-bugfix/multidomain https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

10/08 2016

dev-revert-1336-fix#twig-get-name

dev-revert-1336-fix#twig-get-name https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

10/08 2016

dev-sf3

dev-sf3 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

15/02 2016

3.5.1

3.5.1.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

15/02 2016

4.0.0-RC1

4.0.0.0-RC1 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

09/02 2016

3.5.x-dev

3.5.9999999.9999999-dev https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

09/02 2016

3.5.0

3.5.0.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

25/01 2016

dev-fix-sensiolabs-insight

dev-fix-sensiolabs-insight https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

03/11 2015

3.4.x-dev

3.4.9999999.9999999-dev https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

03/11 2015

3.4.2

3.4.2.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

09/10 2015

3.4.1

3.4.1.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

05/10 2015

3.4.0

3.4.0.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

31/08 2015

3.3.x-dev

3.3.9999999.9999999-dev https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

31/08 2015

3.3.0

3.3.0.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

31/08 2015

3.3.1

3.3.1.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

31/08 2015

3.3.2

3.3.2.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

31/08 2015

3.3.3

3.3.3.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

31/08 2015

3.3.4

3.3.4.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

06/08 2015

3.2.x-dev

3.2.9999999.9999999-dev https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

06/08 2015

3.2.4

3.2.4.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

06/08 2015

3.2.4.1

3.2.4.1 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

06/08 2015

3.2.5

3.2.5.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

06/08 2015

3.2.6

3.2.6.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

19/07 2015

3.2.2

3.2.2.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

19/07 2015

3.2.3

3.2.3.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

06/07 2015

3.2.0

3.2.0.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

06/07 2015

3.2.1

3.2.1.0 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan

06/07 2015

3.2.1.1

3.2.1.1 https://github.com/Kunstmaan/FixturesBundle

With this bundle you'll be able to create fixtures through yaml files in an easy way

  Sources   Download

MIT

The Requires

 

fixtures yaml kunstmaan