<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ticketpark / doctrine-fixtures-autoloader 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);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.