citguru/bryss

Bryss 是一个帮助您快速编写简单而强大的 RESTful API 的 PHP 微型框架。

dev-master 2020-08-24 16:47 UTC

This package is auto-updated.

Last update: 2024-09-25 01:32:16 UTC


README

Bryss

Bryss 是一个 PHP 微型框架,它可以帮助您快速编写简单而强大的 RESTful API,灵感来自 Express 和 Slim(认真阅读源代码)。Bryss 是从头开始构建的,目前没有使用任何依赖。

  • 这仍然处于早期开发阶段,请谨慎使用 *

安装

建议您使用 Composer 安装 Bryss。

$ composer require citguru/bryss:dev-master

该项目仍在开发中,目前还没有稳定版本。您可以使用 :dev-master 标签进行安装。一旦有稳定版本发布,您应该可以不使用它来安装

这将安装 Bryss。Bryss 支持 PHP 版本从 5.3.0 到最新版本。

您也可以直接将此存储库克隆到您的项目文件夹中,并要求所需的类。

使用方法

Bryss 框架的简单 HelloWorld 实现。

<?php

// public/index.php

use Bryss\App;

require __DIR__ . '/../vendor/autoload.php';

$app = App::create();


$app->get("/hello", function($req, $res){
    return $res->json(array(
        "message"=>"Hello World"
    ));
});

$app->get('/hello-xml', function($req, $res, $args) {
  return $res->xml(array(
    "message" => "Hello World",
    "author" => "Ilori Stephen A <stephenilori458@gmail.com>"
  ));
});

$app->get("/hello/:name", function($req, $res){
    $name = $req->params["name"];
    return $res->json(array(
        "message"=>"Hello World, ".$name
    ), 201);
});
?>

您可以使用内置的 PHP 服务器快速测试此功能

$ php -S localhost:8000 -t public

访问 https://:8000/hello/https://:8000/hello-xml/https://:8000/hello/:name 将返回

{
    "message": "Hello World"
}
<root>
  <message>Hello World</message>
  <author>Ilori Stephen A <stephenilori458@gmail.com></author>
</root>
{
    "message": "Hello World, <name>"
}

部署

如果您在自己的服务器或共享主机上设置了 Apache/Nginx 和 PHP,您可以使用 .htaccess 将所有请求路由到一个入口文件,通常是 index.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]

或者

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^$ public/ [L]
   RewriteRule (^[^/]*$) public/$1 [L]
</IfModule>

这意味着您需要将您的 Bryss 项目以及所有其他文件上传到 public 或您想要使用的任何文件夹(您需要在 htaccess 中将其切换出来)以使用它。您可能需要使用 FTP 来上传它。

文档

即将推出... 目前,请查阅 public/index 了解如何使用。

贡献

请参阅 CONTRIBUTION 了解详细信息。

安全

如果您发现与安全相关的问题,请通过电子邮件联系我: oyetoketoby80@gmail.com

许可

版权 (c) 2020 Oyetoke Toby (twitter: @oyetokeT)

Bryss 框架采用 MIT 许可证。有关更多信息,请参阅 许可文件