定制 albertoadolfo27/friendly_route 二次开发

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

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

albertoadolfo27/friendly_route

最新稳定版本:1.1.0

Composer 安装命令:

composer require albertoadolfo27/friendly_route

包简介

PHP Library to create HTTP routes

README 文档

README

PHP Library to create HTTP routes

Getting started

Minimum requirements

  • PHP >= 8.0

Installation

installation using composer

composer require albertoadolfo27/friendly_route

Quick Examples

Tracing routes

<?php
// Require the Composer autoloader.
require_once "vendor/autoload.php";

use FriendlyRoute\Router;

// Set the configuration.
$config = array(
    "debug"      => true,
    "projectDir" => "friendly_route"  // Set the Project Directory if you are working on the localhost. Default empty string.
);

// Instantiate a Router.
$router = new Router($config);

// Tracing routes
$router->get("/", function () {
    echo "<h1>Hello World!</h1>";
});

$router->get("/user/{username}", function ($args) {
    $user = $args["username"];
    echo "<h1>Welcome {$user}</h1>";
});

$router->notFound(function () {
    echo "<h1>404 NOT FOUND</h1>";
});

$router->run();

Allowed HTTP methods

  • GET
$router->get("/", function () {
    // Put the code to run
});

or

$router->set("GET", "/", function () {
    // Put the code to run
});
  • POST
$router->post("/", function () {
    // Put the code to run
});

or

$router->set("POST", "/", function () {
    // Put the code to run
});
  • PUT
$router->put("/", function () {
    // Put the code to run
});

or

$router->set("PUT", "/", function () {
    // Put the code to run
});
  • DELETE
$router->delete("/", function () {
    // Put the code to run
});

or

$router->set("DELETE", "/", function () {
    // Put the code to run
});

Plotting a route with more than one HTTP method

$router->set(array("GET", "POST"), "/", function () {
    // Put the code to run
});

Add array of routes to a request

$router->get(["/hello","/hi"], function () {
    // Put the code to run
});

Method not allowed

$router->methodNotAllowed(function () {
    echo "<h1>405 METHOD NOT ALLOWED</h1>";
});

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-19