承接 apie/storage-metadata-builder 相关项目开发

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

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

apie/storage-metadata-builder

最新稳定版本:1.0.0-RC2

Composer 安装命令:

composer require apie/storage-metadata-builder

包简介

Composer package of the apie library: storage metadata builder

README 文档

README

storage-metadata-builder

Latest Stable Version Total Downloads Latest Unstable Version License PHP Composer

PHP Composer

This package is part of the Apie library. The code is maintained in a monorepo, so PR's need to be sent to the monorepo

Documentation

This package is a ORM agnostic package that helps/creates POPO (plain old php objects) from an Apie domain object that can be used with an ORM. The only library using it now is apie/doctrine-entity-converter that converts Apie domain objects to Doctrine entities.

Usage

You need a BoundedContextHashmap instance for all resources in all bounded contexts. Then you can easily create a builder like this:

use Apie\StorageMetadataBuilder\ChainedBootGeneratedCode;
use Apie\StorageMetadataBuilder\ChainedGeneratedCodeContext;
use Apie\StorageMetadataBuilder\ChainedPostGeneratedCodeContext;
use Apie\StorageMetadataBuilder\StorageMetadataBuilder;

$instance = new StorageMetadataBuilder(
    $boundedContextHashmap,
    new ChainedBootGeneratedCode(/* list of class instances that implement BootGeneratedCodeInterface */),
    new ChainedGeneratedCodeContext(/* list of class instances that implement RunGeneratedCodeContextInterface */),
    new ChainedPostGeneratedCodeContext(/* list of class instances that implement PostRunGeneratedCodeContextInterface */)
);
$code = $instance->generateCode();
// this property contains an array with filename => generated php files
$code->generatedCodeHashmap

It uses nette\php-generator ClassType to create classes. Creating actual files is not part of this package.

The actual conversion of a domain object to a storage DTO is done with apie/storage-metadata

Interfaces of code generators

There are 3 interfaces:

  • BootGeneratedCodeInterface: do these first to create a GeneratedCodeContext mediator object
  • RunGeneratedCodeContextInterface: adds new classes with help of ClassTypeFactory
  • PostRunGeneratedCodeContextInterface: do aggregate actions, like link the index table to all generated tables or add ORM specific attributes.

ClassTypeFactory

This factory class is made to make ClassType instances with common interfaces and properties etc.

  • ClassTypeFactory::createPrimitiveTable(string $tableName, ReflectionType $primitiveTypehint): create a storage table to store a primitive data field (string, bool, int, float, array)
  • public static function createStorageTable(string $tableName, ReflectionClass $referencedObject): create a storage table to store a class with properties, for example entities, DTO's and composite value objects.

Interfaces of generated classes

The classes being generated could have these interfaces:

  • HasIndexInterface: the storage table is used for search indexes
  • MixedStorageInterface: the storage table is used for storing mixed property fields
  • RootObjectInterface: the storage table is the root table of a domain object resource and contains references to index tables etc.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-01