apie / storage-metadata-builder
Composer package of the apie library: storage metadata builder
Installs: 6 523
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.3
- apie/core: dev-main
- apie/storage-metadata: dev-main
- nette/php-generator: ^4.1.5
- nikic/php-parser: ^5.3.1
Requires (Dev)
- apie/fixtures: dev-main
- phpspec/prophecy-phpunit: ^2.2
- phpunit/phpunit: ^11.5.2
Conflicts
- nette/utils: 3.*
This package is auto-updated.
Last update: 2025-03-18 22:52:27 UTC
README
storage-metadata-builder
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.