dealnews/data-mapper-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

dealnews/data-mapper-api

最新稳定版本:2.3.2

Composer 安装命令:

composer require dealnews/data-mapper-api

包简介

API wrapper around data-mapper library

README 文档

README

A simple API that can be installed in other projects that exposes the Data Mapper library in said project to other services.

Table of Contents

Requirements

Installation

composer require php-libraries/data-mapper-api

Usage

Before using this library, you will need a \DealNews\DataMapper\Repository object that maps your data mappers to object names if you have not already created one.

$repo = new \DealNews\DataMapper\Repository();
$repo->addMapper("Example", new \DealNews\Example\Mapper());

You will also need a router of some sort to route API requests to the appropriate code/action. For most cases, you can use the PageMill Router. To help with building routes for the PageMill Router, this library comes with some pre-defined routes and a helper method to make sure input data is properly formatted for the API endpoint.

Routing for just one specific endpoint (if you're only interested in using a portion of the provided endpoints/actions from this library):

$api = new \DealNews\DataMapperAPI\API();

$routes = [
    $api->getRoute('get_object_route')
];

$router = new \PageMill\Router\Router($routes);

$route = $router->match();

if (!empty($route)) {
    $api->executeAction($route['action'], $route['tokens'], 'https://example.com', $repo);
}

Routing for all provided endpoints:

$api = new \DealNews\DataMapperAPI\API();

$router = new \PageMill\Router\Router($api->getAllRoutes());

$route = $router->match();

if (!empty($route)) {
    $api->executeAction($route['action'], $route['tokens'], 'https://example.com', $repo);
}

By default, all endpoint paths have a prefix of /api. However, you can change this by passing a different prefix to either getRoute() or getAllRoutes() methods. Example:

$api = new \DealNews\DataMapperAPI\API();

$router = new \PageMill\Router\Router($api->getAllRoutes('/different-api-path-prefix'));

$route = $router->match();

if (!empty($route)) {
    $api->executeAction($route['action'], $route['tokens'], 'https://example.com', $repo);
}

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting merge requests for this project.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2024-12-31