2017 © Pedro Peláez
 

library fixtures-autoload-bundle

Simplifies loading doctrine fixtures

image

ticketpark/fixtures-autoload-bundle

Simplifies loading doctrine fixtures

  • Sunday, December 25, 2016
  • by ticketpark
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4,835 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

TicketparkDoctrineFixturesAutoloader

Build Status, (*1)

This library simplifies loading Doctrine fixtures., (*2)

Installation

Add TicketparkDoctrineFixturesAutoloader to your composer.json:, (*3)

{
    "require": {
        "ticketpark/doctrine-fixtures-autoloader"
    }
}

Usage

``` php <?php, (*4)

namespace Acme\Bundle\SomeBundle\DataFixtures\ORM;, (*5)

use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\Persistence\ObjectManager; use Ticketpark\Doctrine\DataFixtures\Autoloader\Autoloader;, (*6)

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' ), );, (*7)

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

}, (*8)


In a second fixture class, references will be available based on the entity name and the optional `_reference` value: ``` php <?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); } }

Overwriting setter method names

In some cases you might want to override the setter methods. for instance because your method is named addCurrency instead of addCurrencie as the autoloader by default would asume. In this case, simply use the additional setterMethods parameter:, (*9)

``` php <?php, (*10)

namespace Acme\Bundle\SomeBundle\DataFixtures\ORM;, (*11)

use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\Persistence\ObjectManager; use Ticketpark\Doctrine\DataFixtures\Autoloader\Autoloader;, (*12)

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

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

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

}, (*14)


### Treat arrays as singles Another option to treat an array like a single element and inject the full array into a setter is by using the `$treatAsSingle` method parameter. ``` php <?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); } }

Provide class name

By default, the library tries to guess your entity namespace based on standard data fixture naming conventions. However, you can also define the namespace of your entity manually:, (*15)

``` php <?php, (*16)

namespace Acme\Bundle\SomeBundle\DataFixtures\ORM;, (*17)

use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\Persistence\ObjectManager; use Ticketpark\Doctrine\DataFixtures\Autoloader\Autoloader;, (*18)

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); } } ```, (*19)

License

This bundle is under the MIT license. See the complete license in the bundle:, (*20)

Resources/meta/LICENSE

The Versions

25/12 2016

dev-master

9999999-dev

Simplifies loading doctrine fixtures

  Sources   Download

MIT

The Requires

 

The Development Requires

database doctrine fixtures

07/12 2015

1.0

1.0.0.0

Simplifies loading doctrine fixtures

  Sources   Download

MIT

The Requires

 

The Development Requires

database doctrine fixtures

05/12 2015

0.2.1

0.2.1.0

This bundle simplifies loading doctrine fixtures

  Sources   Download

MIT

The Requires

 

doctrine fixtures

24/02 2015

0.2

0.2.0.0

This bundle simplifies loading doctrine fixtures

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

doctrine fixtures

16/06 2014

0.1

0.1.0.0

This bundle simplifies loading doctrine fixtures

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

doctrine fixtures