承接 ilias/rhetoric 相关项目开发

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

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

ilias/rhetoric

Composer 安装命令:

composer require ilias/rhetoric

包简介

Package addressed to handling routes with PHP

关键字:

README 文档

README

Maintainer Package Source Code Software License

This PHP router system allows you to define and manage your application's routes in a simple and organized manner, inspired by Laravel's routing system.

Installation

To install the package, add it to your composer.json file:

{
  "require": {
    "ilias/rhetoric": "1.0.0"
  }
}

Or simply run the terminal command

composer require ilias/rhetoric

Then, run the following command to install the package:

composer install

Usage

Step 1: Define Your Routes

Create a file to define your routes, for example, in your project root folder, routes.php:

<?php

use Ilias\Rhetoric\Router\Router;

Router::get("/", IndexController::class . "@handleApiIndex");
Router::get("/favicon.ico", IndexController::class . "@favicon");

Router::get("/asset", AssetController::class . "@instruction");

Router::group(['prefix' => '/asset'], function ($router) {
  $router->group(['prefix' => '/type/{type}'], function ($router) {
    $router->get("/name/{name}", AssetController::class . "@getAssetByName");
    $router->get("/id/{id}", AssetController::class . "@getAssetById");
  });
});

Router::get("/debug", DebugController::class . "@showEnvironment");

Step 2: Set Up Your Router

In your application's entry point, typically index.php, set up the router to handle incoming requests:

<?php

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/routes.php';

use Ilias\Rhetoric\Router\Router;

Router::setup();

Step 3: Create Controllers

Create your controller classes to handle the requests. For example, create IndexController.php:

<?php

namespace Ilias\Rhetoric\Controller;

class IndexController
{
  public function handleApiIndex()
  {
    echo "Welcome to the API!";
  }

  public function favicon()
  {
    // Handle favicon request
  }
}

Similarly, create other controller classes like AssetController.php and DebugController.php as needed.

Step 4: Handling Middleware (Optional)

If you want to use middleware, create a middleware class implementing Ilias\Rhetoric\Middleware\Middleware:

<?php

namespace Ilias\Rhetoric\Middleware;

use Ilias\Rhetoric\Middleware\Middleware;

class ExampleMiddleware implements Middleware
{
  public static function handle()
  {
    // Middleware logic here
  }
}

Then, apply middleware to your routes or route groups:

Router::get("/protected", IndexController::class . "@protectedMethod", [ExampleMiddleware::class]);

Router::group(['prefix' => '/admin', 'middleware' => [ExampleMiddleware::class]], function ($router) {
  $router->get("/dashboard", AdminController::class . "@dashboard");
});

Step 5: Dispatching Routes

Using the Request static method, dispatch(), you can handle the current route:

<?php

Request::dispatch($requestMethod, $requestUri);

Dynamic params

Using the Request static attribute, $params, you can access an associative array:

<?php

Router::get("/user/{username}/config", Authenticate::class . "@userConfigurations");

When you access the route http://your.dev.api.com/user/iloElias/config, the params will be stored in Request::$params as:

echo Request::$params["username"] //"iloElias"

Explanations

  • ::class

    Is recommended to use the static reference to your class, so te code does know exactly which class to use

ilias/rhetoric 适用场景与选型建议

ilias/rhetoric 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 114 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 07 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 ilias/rhetoric 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-11