fyyb/express
Composer 安装命令:
composer require fyyb/express
包简介
PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
关键字:
README 文档
README
PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
Getting started
Installation
Assuming you already have composer knowledge, create a directory to store your application and make it your working directory.
$ composer require fyyb/express
This will include in composer autoload all the necessary dependencies. Requires PHP 7.0 or later!
Usage example
After installing, create the .htacces, config.php and index.php files at the root of your project.
To keep your code separate from the configuration files, we suggest that you use a folder/file structure similar to the one below:
.
├─ App/
│ └── ...
├─ vendor/
│ └── ...
├─ .htaccess
├─ config.php
├─ index.php
└─ composer.json
Don't forget to add your application's namespace in the autoload of the composer.json.
"autoload": { "psr-4": { "App\\": "App/" } },
.htaccess
To use fyyb/express, it is necessary to redirect all navigation to the root file (index.php), where all traffic must be handled. The example below shows how:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA]
config.php
File where the variables/constants of the project will be defined. If your project directory is different from the root, configure the BASE_DIR constant for the correct operation in identifying the routes.
<?php const BASE_DIR = '/ path / to / project /'; ...
Hello world
See how easy it is, in your index.php, insert the code below:
<?php require __DIR__ . "/config.php"; require __DIR__ . "/vendor/autoload.php"; use Fyyb\Router; use Fyyb\Request; use Fyyb\Response; $app = Router::getInstance(); $app->get('/', function(Request $req, Response $res) { $res->send('Hello World!'); }); $app->run();
This app responds with "Hello, world!" for requests to the root URL (/) or route. For all other paths, it will respond with a 404 not found.
Simple routing
Routing refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (GET, POST, and so on).
Each route can have one or more handler functions, which are executed when the route is matched.
Route definition takes the following structure:
$app->METHOD(PATH, HANDLER)
Where:
- $app is an instance of fyyb/express.
- METHOD is an HTTP request method, in lowercase.
- PATH is a path on the server.
- HANDLER is the function executed when the route is matched.
The following examples illustrate defining simple routes. Respond with Hello World! on the homepage:
$app->get('/', function (Request $req, Response $res) { $res->send('Hello World!'); });
Respond to POST request on the root route (/), the application’s home page:
$app->post('/', function (Request $req, Response $res) { $res->send('Got a POST request'); });
Respond to PUT request on the root route (/), the application’s home page:
$app->put('/', function (Request $req, Response $res) { $res->send('Got a PUT request'); });
Respond to DELETE request on the root route (/), the application’s home page:
$app->delete('/', function (Request $req, Response $res) { $res->send('Got a DELETE request'); });
Respond to a GET, POST, PUT and DELETE request to the /user route:
$app->any('/user', function (Request $req, Response $res) { $res->send('Got a GET, POST, PUT and DELETE request at /user'); });
Or customize the methods with map function
$app->map([METHOD], PATH, HANDLER)
Where:
- $app is an instance of fyyb/express.
- map is a routing function.
- [METHOD] is an array of HTTP request methods.
- PATH is a path on the server.
- HANDLER is the function performed when the route is matched.
Respond to a GET and POST request to the /test route:
$app->map(['GET', 'POST'], '/test', function (Request $req, Response $res) { $res->send('Got a GET and POST request at /test'); });
fyyb/express 适用场景与选型建议
fyyb/express 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 54 次下载、GitHub Stars 达 3, 最近一次更新时间为 2020 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「api」 「micro」 「router」 「Fyyb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fyyb/express 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fyyb/express 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fyyb/express 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Anax htmlform module.
Micro Active Record library in PHP, support chain calls, events, and relations.
A PSR-7 compatible library for making CRUD API endpoints
Onix Micro Framework
PHP classes for database handling upon PDO
统计信息
- 总下载量: 54
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-23