php对get、post方法及类自身方法调用封装

控制层核心:

    public function test($GET) {
        $page = self::wt(1);
        $id = $GET['id'];
        $table = $GET['table'];
        $data = Permission::getContentById($id, $table);
        return [0, '返回成功!', $data, $page[0], $page[1]];
    }
    public function returnPageTest() {
        return [1, 10];
    }
    public function postTest($POST) {
        return [0, '返回成功!', $POST];
    }
    public static function wt($type,...$data) {
        $fn = self::type[$type];
        empty($fn) && print_r('wt:方法不存在!') && exit();
        return self::$instance->$fn(...$data);
    }
    public static function get() {
        $get = $_GET;
        $type = $get['type'];
        $fn = self::type[$type];
        empty($fn) && print_r('get:方法不存在!') && exit();
        unset($get['type']);
        return parent::result(...self::$instance->$fn($get));
    }
    public static function post() {
        $post = json_decode(file_get_contents('php://input') , true);
        if (array_key_exists('editForm', $post) || array_key_exists('insertForm', $post) || array_key_exists('Form', $post)) {
            $type = $post["type"];
            $fn = self::type[$type];
            empty($fn) && print_r('post:方法不存在!') && exit();
            unset($post['type']);
            return parent::result(...self::$instance->$fn($post));
        } else return parent::result(-1, '提交错误!');
    }

接口层:

<?php
namespace app\interfaces;
interface PermissionInterface {
    const type = [
       0=>'test',//get请求示例demo
       1=>'returnPageTest',//function分页示例demo
       2=>'postTest',//post请求示例demo
       3=>'shareListById',//get通过sid查询单条共享事件
   ];

  /**
  * @Copyright: ©XXXXXXXXXXXXXXXX公司
  * @description: get请求示例demo
  * @param {*} $GET ?type=0&id=1&table=tb_share
  * @return JSON
  * @author: XXX
  * @Date: 2021-04-19 07:52:16
  */
  public function test($GET);
  
  /**
   * @Copyright:©XXXXXXXXXXXXXXXX公司
   * @description: 分页示例demo  
   * @param {*}  self::wt(1)
   * @return Array
   * @author: XXX
   * @Date: 2021-04-19 11:03:05
   */
  public function returnPageTest();

  /**
   * @Copyright: ©XXXXXXXXXXXXXXXX公司
   * @description: post请求示例demo 
   * @param {*} $POST {"editForm": {"aa": 11},"type": 2}
   * @return JSON
   * @author: XXX
   * @Date: 2021-04-19 11:03:09
   */
  public function postTest($POST);


}

  


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值