定制 xsolve-pl/model-factory-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

xsolve-pl/model-factory-bundle

Composer 安装命令:

composer require xsolve-pl/model-factory-bundle

包简介

This bundle provides a versatile skeleton for organizing model factories.

关键字:

README 文档

README

Build Status Scrutinizer Code Quality Latest Stable Version Total Downloads Monthly Downloads License

Table of contents

Introduction

This bundle wraps xsolve-pl/model-factory library and allows to compose collections of model factories declared as services with the use of tags.

See the library documentation for more details on specific use cases.

License

This bundle is under the MIT license. See the complete license in LICENSE file.

Getting started

Include this bundle in your Symfony project using Composer as follows (assuming it is installed globally):

$ composer require xsolve-pl/model-factory-bundle

For more information on Composer see its Introduction.

Afterwards you need to enable this bundle by adding a line to app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Xsolve\ModelFactoryBundle\XsolveModelFactoryBundle(),
        );

        // ...
    }
}

That's all - now you're ready to go!

Usage example

Grouping model factories into collections

To make it easy to produce models for multiple objects it is possible to group model factories into collections. If your application provides multiple APIs (or multiple API versions that are so different that they utilize completely different models) you are able to group factories in separate collections and avoid the risk of producing incorrect models.

Grouping model factories into collections is made easier by providing a dedicated compiler pass that uses tags on model factory service definitions to inject them into appropriate collections. Consider following example of services.xml file:

<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>

        <service id="example.model_factory_collection.first"
                 class="Xsolve\ModelFactoryBundle\ModelFactoryCollection\ModelFactoryCollection"
        />

        <service id="example.model_factory_collection.second"
                 class="Xsolve\ModelFactoryBundle\ModelFactoryCollection\ModelFactoryCollection"
        />

        <service id="example.model_factory.foo"
                 class="Example\FooModelFactory"
        >
            <tag name="xsolve.model_factory_bundle.model_factory"
                 model-factory-collection-id="example.model_factory_collection.first"
            />
            <tag name="xsolve.model_factory_bundle.model_factory"
                 model-factory-collection-id="example.model_factory_collection.second"
            />
        </service>

    </services>

</container>

This snippet defines two model factory collections (with ids example.model_factory_collection.first and example.model_factory_collection.second respectively). It also defines a single model factory (with id example.model_factory.foo). This service has a tag assigned with name attribute equal xsolve.model_factory_bundle.model_factory (which will result in it being processed by Xsolve\ModelFactoryBundle\DependencyInjection\CompilerPass\ModelFactoryCollectionCompilerPass) and model-factory-collection-id attribute containing service ids of respective collections.

统计信息

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

GitHub 信息

  • Stars: 13
  • Watchers: 59
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-08-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固