定制 dealnews/data-mapper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dealnews/data-mapper

最新稳定版本:3.4.0

Composer 安装命令:

composer require dealnews/data-mapper

包简介

PHP Library for implementing the Data Mapper pattern

README 文档

README

This library provides an interface and an abstract base class for creating data mapper objects.

It also provides a Repository class based on dealnews/repository which is tailored for use with Data Mapper classes.

The Data Mapper Pattern

From Wikipedia:

A Data Mapper is a Data Access Layer that performs bidirectional transfer of data between a persistent data store (often a relational database) and an in-memory data representation (the domain layer). The goal of the pattern is to keep the in-memory representation and the persistent data store independent of each other and the data mapper itself. The layer is composed of one or more mappers (or Data Access Objects), performing the data transfer. Mapper implementations vary in scope. Generic mappers will handle many different domain entity types, dedicated mappers will handle one or a few.

Why use the Data Mapper pattern?

Consider a world where an application needs to move data from one storage system to another. With data mappers, the application does not need to understand the different storage layers.

$db_mapper = new \DB\Widget\Mapper();

// Load a Widget from a database
$widget = $db_mapper->load(1);

// Save the Widget to some external storage
// like a 3rd party API
$external_mapper = new \ExternalAPI\Widget\Mapper();
$widget = $external_mapper->save($widget);

Using the Repository

The Repository allows for an application to define in one place the classes that are mapped using mappers. This reduces duplicate code and allows for a greater level of abstraction within the application.

# Application\Repository.php
$repo = new \DealNews\DataMapper\Repository();
$repo->add_mapper("Widget", new \DB\Widget\Mapper());
# Application\SomeFile.php
require "Repository.php";

$widget = $repo->new("Widget");

$widget = $repo->save("Widget", $widget);

统计信息

  • 总下载量: 572
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2019-07-05