承接 somnambulist/read-models-bundle 相关项目开发

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

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

somnambulist/read-models-bundle

最新稳定版本:3.1.0

Composer 安装命令:

composer require somnambulist/read-models-bundle

包简介

Symfony integration for somnambulist/read-models

README 文档

README

GitHub Actions Build Status Issues License PHP Version Current Version

Integrates read-models into Symfony via a bundle.

Installation

Install using composer, or checkout / pull the files from github.com.

  • composer require somnambulist/read-models-bundle
  • add the bundle class to config/bundles.php as the last bundle
    • Note: if not configured last, then any custom doctrine types may not be assigned to the type caster as the Manager will boot too soon.
  • add a config file (config/packages/somnambulist.yaml) with the configuration
  • map any custom casters via the services.yaml and tags
  • make some models
  • load some data: <model>::find()

An example config in config/packages/somnambulist.yaml could be:

somnambulist_read_models:
    connections:
        'default': 'doctrine.dbal.default_connection'
        'App\Models\User': 'doctrine.dbal.user_connection'
    subscribers:
        request_manager_clearer: true
        messenger_manager_clearer: true

There are 2 event subscribers that are auto-registered:

  • identity map clear on kernel request, terminate
  • messenger clear on message handled / failed

If messenger is not installed, the listener will be disabled automatically.

Connections

Each model type can have a custom connection by using the fully qualified class name as the key. When referencing the Doctrine connections, be sure to leave off the @ prefix if copying from elsewhere.

Note that if the default is not specified, then the currently configured Doctrine default will be auto-registered.

Adding Attribute Casters

Add attribute casters as services and tag them with: somnambulist.read_models.type_caster to have them automatically registered with the Managers attribute caster instance.

To use the attribute-model generic type casters, and them as services and configure as needed:

services:
    app.type_casters.some_service_identity:
        class: Somnambulist\Components\AttributeModel\TypeCasters\ExternalIdentityCaster
        arguments:
            $providerAttribute: 'some_service_name' 
            $identityAttribute: 'some_service_id'
            $remove: true 
            $types:
                -
                    some_service_id
        tags: ['somnambulist.read_models.type_caster']

    app.type_casters.my_value_object:
        class: Somnambulist\Components\AttributeModel\TypeCasters\SimpleValueObjectCaster
        arguments:
            $class: 'App\\Entities\\SomeEntityValueObject' 
            $types:
                -
                    short_name
        tags: ['somnambulist.read_models.type_caster']

Or if you don't need configuration, or have your own; use a resource:

services:
    App\TypeCasters\:
        resource: '../../src/TypeCasters/'
        tags: ['somnambulist.read_models.type_caster']

The attribute names should be the array key names that the values are expected to appear in from the data source. For example: if a Product model accesses a products table that has unit_value and unit_cur fields, this could be converted to a Money object by using the MoneyCaster:

services:
    app.type_casters.product_money_caster:
        class: Somnambulist\Components\AttributeModel\TypeCasters\MoneyCaster
        arguments:
            $amtAttribute: 'unit_value' 
            $curAttribute: 'unit_cur'
            $remove: true 
            $types:
                -
                    product_price
        tags: ['somnambulist.read_models.type_caster']

Then the caster can be referenced in the casts as: 'price' => 'product_price' and the unit_value and unit_cur attributes will be removed in favour of the single "price" attribute that will be a Money value object. If the originals should be left in place, set $remove to false.

Additional casters can be added at any time; and existing casters may be overridden by re-using an existing type name however this is discouraged. Note that once a type is registered it cannot be removed.

Usage

See read-models for detailed docs on usage and attribute-models for more on the attribute caster.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-09-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固