david-prv/quickyphp

手工制作的PHP微框架

安装: 14

依赖: 0

建议者: 0

安全: 0

星星: 6

关注者: 1

分支: 1

开放问题: 1

类型:项目

dev-main 2024-10-01 13:52 UTC

This package is auto-updated.

Last update: 2024-10-01 13:52:35 UTC


README

PHPStan PHPMD PHPCS

一个用于简单快速Web应用的PHP微框架

重要

该项目在近期内不会收到任何重大更新。由于我没有足够的时间,我已无限期暂停开发。QuickyPHP尚未停止开发,只是开发被推迟了。

👉 已迁移到 https://codeberg.org/david-prv/QuickyPHP

动机

我开始这个项目是因为我想拖延大学的重点工作。这不是玩笑。但这变成了一种几天的轻微痴迷。我发现开发自己的PHP微框架非常有趣,以至于我一直在阅读文档和文章,观看教程。

该框架旨在尽可能简单,以便任何人都能根据自己的需求轻松定制。我还尝试了我在其他项目中从未使用过但在大学里发现或了解的技术(例如方法分发器或反射类)。此外,该项目部分与ChatGPT(OpenAI)合作完成,这也是一个难忘的实验。

我从其他开源项目中获得了关于如何实现简单PHP框架的想法。以下是一些选择(如果你仔细阅读,你会很快看到我的框架及其结构的相似之处)

示例应用程序

一个由该框架驱动的简单Web应用程序

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

use Quicky\Http\Request;
use Quicky\Http\Response;
use Quicky\App;

$app = App::create();

App::route("GET", "/", function(Request $request, Response $response) {
    $response->write("Hello World");
    return $response;
});

$app->run();

更多功能

灵活的工厂

你可以使用内置的AppFactory轻松构建复杂的应用程序配置!

$app = AppFactory::empty()
  ->catch("exception", function (Throwable $exception) { ... })
  ->state("development")
  ->middleware(RateLimitMiddleware::class, 1, 5)
  ->alias("sayHello", function () { echo "Hello World"; })
  ->build();

自动分发

该框架将自动搜索正确的方法进行分发,对于任何静态调用。

use Quicky\Interfaces\DispatchingInterface;

class MyTest implements DispatchingInterface
{
  private array $dispatching;

  public function __construct()
  {
    $this->dispatching = array("test");
  }

  public function dispatches(string $method): bool
  {
    return in_array($method, $this->dispatching);
  }

  public function test(): void
  {
    echo "I'm a test";
  }
}

安全路由

使用安全敏感的中间件保护您的应用程序,以防止基本攻击模式。

use Quicky\Middlewares\RateLimitMiddleware;
use Quicky\Middlewares\CORSMiddleware;
use Quicky\Middlewares\LoggingMiddleware;

// Routes can be accessed once every 5 seconds
App::use("middleware", new RateLimitMiddleware(1, 5));

// This route additionally sets special CORS headers & enables logging
App::route("GET", "/admin", function (Request $request, Response $response) {
  $response->render("admin.dashboard");
  return $response;
})
->middleware(new CORSMiddleware())
->middleware(new LoggingMiddleware());

要求

QuickyPHP需要PHP 7.4+或PHP 8(检查兼容性)以及支持Rewrite规则的Web服务器。
注意:需要Composer版本2来查找和安装包。

安装

下载文件

通过Composer

通过命令行安装项目

composer create-project david-prv/quickyphp

通过GitHub

创建项目文件夹:下载git仓库

git clone https://github.com/david-prv/QuickyPHP.git

安装要求

不安装开发要求

composer install

如果您想跳过开发依赖项,请使用--no-dev标签。如果您还想跳过平台要求检查,请使用--ignore-platform-reqs标签,但请注意不建议这样做。

CLI用法

启动本地PHP开发服务器

php quicky-cli start [<address> [<port>]]

e.g. php quicky-cli start localhost 3000

清除日志

php quicky-cli clear logs

清除缓存

php quicky-cli clear cache

恢复默认配置

php quicky-cli config restore

更新配置

php quicky-cli config set <field> <value>

e.g. php quicky-cli config set project.env production

贡献

请随时为此项目做出贡献。我总是很高兴看到新的和新鲜的想法。
了解更多

支持

如果您喜欢我所做的工作,请随时购买一杯咖啡以支持我的工作。
早上早些时候编程没有一杯好咖啡是非常困难的。

点击此处支持我

buy me a coffee!

许可证

GPL发布,作者@david-prv

image