stefanotorresi / thorr-persistence
Agnostic interfaces for a DataMapper implementation through vendor specific adapters
Requires
- php: ~5.5
- rhumsaa/uuid: ~2.8
Requires (Dev)
Suggests
- zendframework/zend-eventmanager: required to use the EventManagerAware decorator
- zendframework/zend-modulemanager: required to load the library as a ZF2 module
- zendframework/zend-servicemanager: required to use DataMapperManager
- zendframework/zend-validator: required to use entity validators
This package is auto-updated.
Last update: 2024-10-12 03:45:26 UTC
README
Agnostic interfaces for a DataMapper implementation through vendor specific adapters.
Implementations
DataMapperManager usage
This library provides an optional Zend Framework 2 plugin manager for DataMapperInterface
instances, the DataMapperManager
.
It provides a method to retrieve data mappers for your entities: DataMapperManager::getDataMapperForEntity($entity)
.
Here is an example:
$config = new DataMapperManagerConfig([ 'entity_data_mapper_map' => [ Entity::class => 'EntityDataMapperServiceName', ], 'factories' => [ 'EntityDataMapperServiceName' => function () { // return a DataMapperInterface }, ], ]); $dataMapperManager = new DataMapperManager($config); // retrieves the service configured as 'EntityDataMapperServiceName' $entityMapper = $dataMapperManager->getDataMapperForEntity(Entity::class);
To use the DataMapperManager
you have to require zendframework/zend-servicemanager
via Composer:
composer require zendframework/zend-servicemanager
Usage in a ZF2 module
When using the library as a Zend Framework 2 module, you can load the module Thorr\Persistence
and implement
DataMapperManagerConfigProviderInterface
in your modules to provide the configuration via the
getDataMapperManagerConfig()
method.
The module will also register in the main ServiceManager
a DataMapperManager
instance with its FQCN,
aliased with the DataMapperManager
name, so you can retrieve it as follows:
$serviceManager->get(DataMapperManager::class); // or $serviceManager->get('DataMapperManager');