定制 funeralzone/valueobject-generator 二次开发

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

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

funeralzone/valueobject-generator

Composer 安装命令:

composer require funeralzone/valueobject-generator

包简介

A generator for immutable Value Objects

README 文档

README

Upgrade notes for V0 to V1

Everything is a model

There is no longer a strong bias toward Event Sourcing so the concept of events, commands, queries and deltas has been removed and the onus of implementing these placed on the types/template library.

The practical upshots of this change are as follows:

events, commands, queries and deltas

  • Top level items for events, commands, queries and deltas have been removed; every model lives under the model top-level item
  • When creating events, commands, queries and deltas there is no deltas property; use must define children models that happen to implement delta behaviour
  • events, commands, queries and deltas are now dedicated types - Event, Command, Query and Delta respectively

Seeding models from Prooph meta data

The Event, Command, Query and Delta types include a fromMetaDataKey property that allows you to define a Prooph metadata key to seed from

- name: ExampleEvent
  type: Event
  children:
    - name: ExampleEventAggregateId
      type: Uuid
      propertyName: id
      fromMetaDataKey: _aggregateId

Deltas seeded with the root payload

Deltas can no longer automatically receive the root payload of a command/event.

In V0 you could optionally supply a useRootData flag in the definition which meant the delta received the entire payload of the event or command rather than just its specific property. This is no longer possible.

In order to re-create this behaviour you can bundle up the necessary properties within the Prooph resolver and add a fabricated array property to the command/events payload.

Sets no longer accept child models

In V0 sets would require a single child model which inferred the type of contents the Set would accept. This is no longer possible.

In V1 you must explicitly define the type of model a Set can contain by setting the modelToEnforce property. This property must reference a valid model.

- name: OrganisationalUnitId
  type: Uuid

- name: OrganisationalUnitIds
  type: Set
  modelToEnforce: OrganisationalUnitId

Decorators

Decorators have had a overhaul:

  • you can now have multiple decorators per model
  • you do not define their target, i.e. the nullDecorator, nonNUllDecorator and nullableDecerator properties are defunct
  • they are hook based, allowing decorators to be tied into different actions within a model

Available hooks:

  • constructor - executes during the constructor of a model and receives all arguments used to instantiate the object
decorators:
- path: Funeralzone\FAS\Common\ValueObjects\Decorators\DecoratorOne
  hooks:
  - type: constructor
    method: methodToCallOnConstructOne
  
- path: Funeralzone\FAS\Common\ValueObjects\Decorators\DecoratorTwo
  hooks:
  - type: constructor
    method: methodToCallOnConstructTwo

Example definition

namespace: ValueObjects

model:

  # External models
  # ==========================

  - name: EntityId
    type: String
    namespace: Funeralzone\FAS\DomainEntities
    testing:
      fromNative: "'1'"
      constructor: "'1'"

  # Data models
  # ==========================
  - name: TenantId
    type: Uuid
    
  - name: BereavedId
    type: Uuid

  - name: ContactId
    type: Uuid

  - name: DirectoryListingId
    type: Uuid

  - name: MediaId
    type: String
    decorators:
    - path: Funeralzone\FAS\Common\ValueObjects\Decorators\MediaIdDecoratorTrait
      hooks:
      - type: constructor
        method: decoratorConstruct

  - name: MediaUploadRequestId
    type: String

  - name: ProductId
    type: Uuid

  - name: ServiceId
    type: Uuid

  - name: StaffMemberId
    type: Uuid

  - name: PackageId
    type: Uuid

  # Telephones
  # --------------------------

  - name: TelephoneNumber
    type: String

  - name: TelephoneCountryCode
    type: String

  - name: Telephone
    type: Telephone

  - name: TelephoneType
    type: Enum
    values:
      - WORK
      - HOME
      - MOBILE
      - FAX

  # Address
  # --------------------------

  - name: AddressLine1
    type: String

  - name: AddressLine2
    type: String

  - name: Town
    type: String

  - name: County
    type: String

  - name: PostCode
    type: String

  - name: CountryCode
    type: ISOAlpha2CountryCode

  - name: GeoLocation
    type: Composite
    children:
      - name: AddressData
        type: String
        propertyName: data
      - name: Geometry
        type: Composite
        propertyName: geometry
        children:
          - name: Latitude
            type: Float
            propertyName: lat
            decorators:
            - path: Funeralzone\FAS\Common\ValueObjects\Decorators\LatitudeDecoratorTrait
              hooks:
              - type: constructor
                method: decoratorConstruct
            testing:
              fromNative: '50.9'
              constructor: '50.9'
          - name: Longitude
            type: Float
            propertyName: lng
            testing:
              fromNative: '50.9'
              constructor: '50.9'
            decorators:
            - path: Funeralzone\FAS\Common\ValueObjects\Decorators\LongitudeDecoratorTrait
              hooks:
              - type: constructor
                method: decoratorConstruct

  # Identity interface
  # --------------------------

  - name: IdentityInterfacePolicyMembership
    type: String

  - name: IdentityInterfacePolicyScope
    type: String

  - name: IdentityInterface
    type: Composite
    children:
      - name: IdentityInterfaceType
        type: Enum
        propertyName: type
        values:
          - STAFF_MEMBER
          - DEVELOPER
      - name: IdentityInterfaceName
        type: String
        propertyName: name
      - name: IdentityInterfaceImage
        type: String
        propertyName: image
      - name: IdentityInterfaceEmail
        type: Email
        propertyName: email
      - name: IdentityInterfacePolicy
        type: Composite
        propertyName: policy
        children:
          - name: IdentityInterfacePolicyMemberships
            type: Set
            propertyName: memberships
            modelToEnforce: IdentityInterfacePolicyMembership

          - name: IdentityInterfacePolicyScopes
            type: Set
            propertyName: scopes
            modelToEnforce: IdentityInterfacePolicyScope

  # Other
  # --------------------------

  - name: Note
    type: Entity
    children:
    - name: EntityId
      propertyName: id
    - name: NoteTimeCreated
      type: RFC3339
      propertyName: timeCreated
    - name: NoteContent
      type: String
      propertyName: content
    - name: NoteAuthorId
      type: Uuid
      propertyName: authorId

  - name: Notes
    type: EntitySet
    modelToEnforce: Note

  - name: Name
    type: Composite
    children:
      - name: NameTitle
        type: String
        propertyName: title
      - name: GivenName
        type: String
        propertyName: givenName
      - name: FamilyName
        type: String
        propertyName: familyName

  - name: PersonPhone
    type: TelephoneContact
    typeValues:
    - WORK
    - HOME
    - MOBILE
    - FAX

  - name: PersonEmail
    type: Email

  - name: Person
    type: Composite
    children:
      - name: Name
        propertyName: name

      - name: PersonAddress
        type: Address
        propertyName: address

      - name: PersonPhones
        type: Set
        propertyName: phones
        modelToEnforce: PersonPhone

      - name: PersonEmails
        type: Set
        propertyName: emails
        modelToEnforce: PersonEmail

      - name: MediaId
        propertyName: image

  - name: DirectoryListingIds
    type: Set
    modelToEnforce: DirectoryListingId

  - name: OrganisationalUnitId
    type: Uuid

  - name: OrganisationalUnitIds
    type: Set
    modelToEnforce: OrganisationalUnitId

  - name: EstimateId
    type: Uuid

  - name: EstimateIds
    type: Set
    modelToEnforce: EstimateId

  - name: Tag
    type: String
    decorators:
    - path: Funeralzone\FAS\Common\ValueObjects\Decorators\TagDecoratorTrait
      hooks:
      - type: constructor
        method: decoratorConstruct

  - name: Tags
    type: Set
    decorators:
    - path: Funeralzone\FAS\Common\ValueObjects\Decorators\TagsDecoratorTrait
    modelToEnforce: Tag

  - name: PaginationInput
    type: Composite
    children:
      - name: PaginationInputPage
        type: Integer
        propertyName: page
      - name: PaginationInputNodesPerPage
        type: Integer
        propertyName: nodesPerPage

  - name: StaffRoleId
    type: Uuid

  - name: StaffRoleIds
    type: Set
    modelToEnforce: StaffRoleId

  - name: DeveloperId
    type: Uuid

  - name: DeveloperIds
    type: Set
    modelToEnforce: DeveloperId

  - name: PersonDelta
    type: Delta
    children:
      - name: Name
        propertyName: name
      - name: PersonAddress
        propertyName: address
      - name: PersonPhones
        propertyName: phones
      - name: PersonEmails
        propertyName: emails
      - name: MediaId
        propertyName: image

funeralzone/valueobject-generator 适用场景与选型建议

funeralzone/valueobject-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.99k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 funeralzone/valueobject-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 funeralzone/valueobject-generator 我们能提供哪些服务?
定制开发 / 二次开发

基于 funeralzone/valueobject-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2018-06-11