定制 wronx/lumen-rest-object-fetch-middleware 二次开发

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

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

wronx/lumen-rest-object-fetch-middleware

Composer 安装命令:

composer require wronx/lumen-rest-object-fetch-middleware

包简介

Simple Lumen middleware for simple fetching simple objects in simple REST API endpoints

README 文档

README

IMPORTANT: This package is a work in progress, it it not stable by any means.
Use responsibly! Or don't use at all and wait for v1.0.

The purpose of this project

It was created to avoid repetitive 404 (and other) checks when hitting CRUD endpoints of API.

Is it any good?

Yes

(well, it will be in stable version... I hope...)

Installation

  1. Install the package with Composer:
composer require wronx/lumen-rest-object-fetch-middleware
  1. Enable it in bootstrap/app.php:
$app->routeMiddleware([
// ...
                          'object' => WRonX\RestObjectFetch\RestObjectFetchMiddleware::class,
                      ]);

Usage

  1. In routes/web.php assign it to route which requires id parameter, giving it model's class name:
$router->group([
                   'prefix'     => '/something/{id:[0-9]+}',
                   'middleware' => 'object:Something', // <--- HERE
               ],
    function() use ($router) {
        $router->get('', [
            'as'   => 'show_something',
            'uses' => 'SomethingController@show',
        ]);
        
        $router->patch('', [
            'as'   => 'edit_something',
            'uses' => 'SomethingController@update',
        ]);
        
        $router->delete('', [
            'as'   => 'delete_something',
            'uses' => 'SomethingController@destroy',
        ]);
    });
  1. In Controller methods that are covered by this middleware you don't have to check if object exists and you don't have to fetch it again from DB:
    public function show(Request $request) {
        $something = $request->attributes->get('fetchedObject');
        
        return new JsonResponse($something);
    }

Contributing

If you want to contribute, please wait. Until stable version arrives I want to shape this package in my specific way. Later on, pull requests will be welcome.

License:

Copyright © 2016 github.com/WRonX
This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://www.wtfpl.net/ for more details

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: WTFPL
  • 更新时间: 2018-07-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固