定制 nabeelalihashmi/apilot-engine 二次开发

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

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

nabeelalihashmi/apilot-engine

Composer 安装命令:

composer require nabeelalihashmi/apilot-engine

包简介

Simple endpoint-in-files router for PHP

README 文档

README

Fast automatic files based router with Caching routes

alt text

WARNING

Design api carefully

Installation

Using Composer

    composer require nabeelalihashmi/apilot-engine

Manual

Just download the Apilot.php file, include in your project. Configure .htaccess.

<?php
    $apilot = new Apilot($handlers_path, $cache_path, $optional_server_basepath);
    $apiot->on404(function() {
        ...
    });
    $apilot->takeoff();
?>

.htaccess files

  • Copy extras/root.htaccess in root folder and rename it to .htaccess.
  • Copy extras/public.htaccess in public folder and rename it to .htaccess.

Routes

Make a folder for handlers. Each file in that cockpit folder corresponds to a route.

e.g.

cockpit/
    index.php -> /
    about.php -> /about
    contact.php -> contact
    ...

Each file must have at least one handler method. The name of the method must be handle.

e.g.

    function GET() {

    }

    function POST() {

    }

    function PUT() {

    }
    

Dynamic routes

To make a route accept dynamic value, use : in the route.

e.g.

    File: cockpit/users/:id/edit.php
    URI: /users/:id/edit

    function GET($id) {
        ...
    }
s
    File: cockpit/users/:id/:action.php
    URI: /users/:id/:action

    function GET($id, $action) {
        ...
    }

Optional Parameters

To make a route optional, make the parameter optional with ?.

    File: cockpit/list/:page?.php
    URI: /list/:page?

    function GET($page = 1) {
        ...
    }

Rules

  • Optional Routes must place at end
hello/:who? Good
hello/:who?/level2 Bad
hello/:who?/level2 Bad

Middleware

You can use middleware to do something before and after the route. You can use before and after appended to handler method name. before middleware must return true to continue.

function GET() {

}

function before_GET() {
    return true;
}

function after_GET() {

}

Route Not Found

Apilot will call the on404 function if the route is not found. You can use this function to redirect to 404 page or do something else.

usage:

$apilot->on404(function() {
    ...
});

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固