承接 ticketpark/doctrine-fixtures-autoloader 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ticketpark/doctrine-fixtures-autoloader

最新稳定版本:1.0

Composer 安装命令:

composer require ticketpark/doctrine-fixtures-autoloader

包简介

Simplifies loading doctrine fixtures

README 文档

README

Build Status

This library simplifies loading Doctrine fixtures.

Installation

Add TicketparkDoctrineFixturesAutoloader to your composer.json:

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

Usage

<?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);
    }
}

In a second fixture class, references will be available based on the entity name and the optional _reference value:

<?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:

<?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);
    }
}

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

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:

<?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);
    }
}

License

This bundle is under the MIT license. See the complete license in the bundle:

Resources/meta/LICENSE

统计信息

  • 总下载量: 104.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固