PHP code example of ticketpark / fixtures-autoload-bundle

1. Go to this page and download the library: Download ticketpark/fixtures-autoload-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ticketpark / fixtures-autoload-bundle example snippets

 php


namespace Acme\Bundle\SomeBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Ticketpark\Doctrine\DataFixtures\Autoloader\Autoloader;

class LoadCountryData extends AutoLoader implements FixtureInterface
{
    public function load(ObjectManager $manager)
    {
        $data = array(
            array(
                '_reference'    => 'CH',
                'shortCode'     => 'CH',
                'name'          => 'Switzerland'
            ),
            array(
                '_reference'    => 'AT',
                'shortCode'     => 'AT',
                'name'          => 'Austria'
            ),
        );

        $this->autoload($data, $manager);
    }
}
 php


namespace Acme\Bundle\SomeBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Ticketpark\Doctrine\DataFixtures\Autoloader\Autoloader;

class LoadUserData extends AutoLoader implements FixtureInterface, DependentFixtureInterface
{
    public function getDependencies()
    {
        return array(
            'Acme\Bundle\SomeBundle\DataFixtures\ORM\LoadCountryData'
        );
    }
    
    public function load(ObjectManager $manager)
    {
        $data = array(
            array(
                // The string `country_CH` references the element
                // created in the 'Country' entity with 'CH' as its
                // _reference value.
                'country' => $this->getReference('country_CH'),
                'name'    => 'Tom Swissman'
            )
        );

        $this->autoload($data, $manager);
    }
}
 php


namespace Acme\Bundle\SomeBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Ticketpark\Doctrine\DataFixtures\Autoloader\Autoloader;

class LoadCurrencyData extends AutoLoader implements FixtureInterface
{
    public function load(ObjectManager $manager)
    {
        $data = array(
            array(
                'currencies' => array(
                    'USD', 'EUR', 'CHF'
                )
            ),
        );

        $setterMethods = array(
            'currencies' => 'addCurrency'
        );

        $this->autoload($data, $manager, $setterMethods);
    }
}
 php


namespace Acme\Bundle\SomeBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Ticketpark\Doctrine\DataFixtures\Autoloader\Autoloader;

class LoadCurrencyData extends AutoLoader implements FixtureInterface
{
    public function load(ObjectManager $manager)
    {
        $data = array(
            array(
                'currencies' => array(
                    'USD', 'EUR', 'CHF'
                )
            ),
        );

        // this will cause a call to setCurrencies() with the full currencies array
        $treatAsSingles = array('currencies');
        $this->autoload($data, $manager, array(), $treatAsSingles);
    }
}
 php


namespace Acme\Bundle\SomeBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Ticketpark\Doctrine\DataFixtures\Autoloader\Autoloader;

class LoadCountryData extends AutoLoader implements FixtureInterface
{
    public function load(ObjectManager $manager)
    {
        $data = array(
            array(
                'shortCode'     => 'CH',
                'name'          => 'Switzerland'
            ),
        );
        $this->setEntityClass('My\Custom\Namespace\Country');
        $this->autoload($data, $manager);
    }
}