承接 docnet/php-japi 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

docnet/php-japi

Composer 安装命令:

composer require docnet/php-japi

包简介

Simple framework for building HTTP JSON APIs in PHP. 2.

README 文档

README

Build Status Coverage Status

PHP JSON API Library

Version 2 of our library for building HTTP JSON APIs in PHP.

Some major changes in version 2

  • Adopt better code practices, allowing for Dependency Injection
  • Adopt our new "Single Responsibility Controller" approach
  • Decouple Router from JAPI container
  • Use PSR logging
  • Adopt PHP 5.4 minimum version

As we expand our Service Orientated Architecture (SOA) at Docnet, we're using this more and more - so I hope it's useful to someone else ;)

Intended to use HTTP status codes wherever possible for passing success/failure etc. back to the client.

Single Responsibility Controller

We've adopted a new (for us) take on routing and controller complexity in 2.0. As such, where previously, you might have had multiple actions (methods) on the same class like this:

  • BasketController::fetchDetailAction()
  • BasketController::addAction()
  • BasketController::removeAction()
  • BasketController::emptyAction()

Now this would be 4 name-spaced classes, like this

  • Basket\FetchDetail
  • Basket\Add
  • Basket\Remove
  • Basket\Empty

This allows for

  • Greater code modularity
  • Smaller classes
  • Much easier Dependency Injection via __construct() as each "action" is it's own class.

You can still share common code via extension/composition - whatever takes your fancy!

JAPI will call the dispatch() method on your controller.

SOLID Routing

The bundled router will accept any depth of controller namespace, like this

  • /one => One
  • /one/two => One\Two
  • /one/two/three => One\Two\Three

When you construct the Router, you can give it a "root" namespace, like this:

$router = new \Docnet\JAPI\SolidRouter('\\Docnet\\App\\Controller\\');

Which results in this routing:

  • /one/two => \Docnet\App\Controller\One\Two

Static Routes

If you have some static routes you want to set up, that's no problem - they also bypass the routing regex code and so make calls very slightly faster.

Add a single custom route

$router = new \Docnet\JAPI\SolidRouter();
$router->addRoute('/hello', '\\Some\\Controller');

Or set a load of them

$router = new \Docnet\JAPI\SolidRouter();
$router->setRoutes([
    '/hello' => '\\Some\\Controller',
    '/world' => '\\Other\\Controller'
]);

Installation

Here's the require line for Composer users (during 2-series development)...

"docnet/php-japi": "2.0.*@dev"

...or just download and use the src folder.

Bootstrapping

Assuming...

  • You've got Apache/whatever set up to route all requests to this file
  • An auto-loader is present (like the Composer example here) or you've included all files necessary

...then something like this is all the code you need in your index.php

(new \Docnet\JAPI())->bootstrap(function(){

    $obj_router = new \Docnet\JAPI\SolidRouter();
    $obj_router->route();

    $str_controller = $obj_router->getController();
    return new $str_controller();

});

See the examples folder for a working demo (api.php).

Coding Standards

Desired adherence to PSR-2. Uses PSR-3 logging.

docnet/php-japi 适用场景与选型建议

docnet/php-japi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.87k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2014 年 01 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「json」 「http」 「api」 「docnet」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 docnet/php-japi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 docnet/php-japi 我们能提供哪些服务?
定制开发 / 二次开发

基于 docnet/php-japi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 16.87k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 10
  • Forks: 14
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2014-01-27