Agnostic interfaces for a DataMapper implementation through vendor specific adapters.
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
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');