xaerobiont / transfer-container
3.0.0
2022-12-11 14:54 UTC
Requires
- php: ^8.2
- ext-mbstring: *
- ext-zlib: *
Requires (Dev)
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^5
README
PHP container for transferring DTO between services
Goals
- Allows to transfer different DTOs into single package
- Provides mapping mechanism. I.e. when sender and receiver has different DTO namespace or even classes
- Compress data packs
- Very simple, lightweight and vendor-independent
Installation
{ "require": { "xaerobiont/transfer-container": "^2" } }
Usage
For more detailed usage examples see /tests
use Xaerobiont\TransferContainer\Transferable; use Xaerobiont\TransferContainer\TransferContainer; class MyDTO implements Transferable {} class YourDTO implements Transferable {} class ThemDTO implements Transferable {} $package = []; for ($i = 1; $i <= 100; $i++) { $package[] = new MyDTO(); $package[] = new YourDTO(); $package[] = new ThemDTO(); } $container = new TransferContainer(); $container->put($package); $transfer = $container->pack(); $container->clear(); // receiver side $map = [ YourDTO::class => OtherDTO::class ]; foreach (TransferContainer::unpack($transfer, $map) as $item) { // $item is MyDTO/OtherDTO/ThemDTO object }