wmsamolet / object-map
PHP library for mapping, linking, configuring objects using data repository
1.0.0
2021-11-21 22:02 UTC
Requires
- php: >=7.2.0
- ext-json: *
- wmsamolet/php-object-collections: ^1.0
Requires (Dev)
- phpunit/phpunit: ^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0
- squizlabs/php_codesniffer: ^2.0 || ^3.0
README
PHP library for mapping, linking, configuring objects using data storage
Description
This library is suitable for those who want:
- Create loosely coupled components
- Connect and configure handler classes dynamically
Documentation
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require wmsamolet/object-map
or add
"wmsamolet/object-map": "^1.0"
to the requirement section of your composer.json
file.
Basic usage
<?php use Wmsamolet\ObjectMap\Domain\Repository\Memory\ObjectElementRepository; use Wmsamolet\ObjectMap\Domain\Repository\Memory\ObjectLinkingRepository; use Wmsamolet\ObjectMap\Domain\Service\ObjectMapService; $objectMapService = new ObjectMapService( new ObjectElementRepository(), new ObjectLinkingRepository() ); class TargetObject { } class LinkedObject1 { } class LinkedObject2 { } // Add objects to map (adding information to the repository) $objectMapService->addObjectToMap(TargetObject::class, 'Target object'); $objectMapService->addObjectToMap(LinkedObject1::class, 'Linked object #1'); $objectMapService->addObjectToMap(LinkedObject2::class, 'Linked object #2'); // Link objects to class TargetObject $objectMapService->linkObjects(TargetObject::class, LinkedObject1::class); $objectMapService->linkObjects(TargetObject::class, LinkedObject2::class); // Get linked objects class name collection $classNameCollection = $objectMapService->collectLinkedObjectsClassNames( TargetObject::class ); // Get linked objects config collection ['class_name' => [...], ...] $objectConfigCollection = $objectMapService->collectLinkedObjectsConfigs( TargetObject::class );
License
PHP Object Map is licensed under the MIT License - see the LICENSE file for details