thijmendf / groundwork
Groundwork,一个轻量级的PHP框架
v0.9.1
2022-06-05 21:52 UTC
Requires
- php: ^7.4|^8.0
- ext-fileinfo: *
- ext-json: *
- ext-mysqli: *
- altorouter/altorouter: ^2.0
- gladcodes/keygen: ^1.1
- intervention/image: ^2.6
- nesbot/carbon: ^2.50
- phpmailer/phpmailer: dev-master
- psr/container: ^2.0.2
- symfony/dotenv: 5.4.x-dev
- symfony/http-foundation: ^5.3
- symfony/mime: ^5.3
- symfony/var-dumper: ^5.3
- twig/twig: ^3.3
Requires (Dev)
- filp/whoops: ^2.14
README
一个轻量级的PHP框架
注意:Groundwork 目前处于 alpha 状态,在实施更稳定的发布结构之前,将进行重大更改。
这是 Groundwork 项目的核心库。有关更多信息,请参阅 默认 Groundwork 项目。
该框架使用各种外部包,例如,但不限于
- Twig 用于模板渲染。
- Symfony 用于 HTTP 请求/响应处理。
- Carbon 用于日期/时间。
- Altorouter 用于路由。
- TailwindCSS 用于样式。您需要使用 npm 安装它。(请参阅默认项目中的 package.json)
安装
要安装,请运行 composer require thijmendf/groundwork
初始化
为了启动框架,请将所有 HTTP 请求(除了对文件(如资源)的请求)发送到 public
文件夹中的一个单独的 PHP 文件。在那里,只需从项目根目录引入以下引导代码
// File location: ./public/index.php require "../bootstrap.php";
在该引导文件中,您可以使用以下代码来启动框架
// File location: ./bootstrap.php ini_set('display_errors', 'off'); error_reporting(E_ALL); // Require the auto-loader require __DIR__ . '../vendor/autoload.php'; use Groundwork\Server; // Start the handle server $server = Server::getInstance(__DIR__); // Handle the request $server->handle();
就这样。它将自动处理请求和响应。
默认文件结构
实现此框架的项目需要以下文件结构
+ project
|---+ App <- This is where the main source code of your project will go to
| |---+ Models <- Database models
| |
| |---+ Controllers <- View controllers
| |
| |---+ Extensions <- Extending Groundwork
| |
| |---+ Requests <- Validating form requests
| |
| |---+ Middleware <- Middleware defined in the routes
|
|---+ cache <- Caching various systems such as the templates
|
|---+ database
| |---+ migrations <- Migrations that are run once. Doesn't have to be database related
| |
| |---+ seeders <- Seeders for the database
|
|---+ public
| |---+ assets <- Place for css, js, images, fonts etc.
| |
| |---- index.php <- All requests must go here. See code above
|
|---+ resources <- Root for uncompiled assets (views, css, js etc.)
| |
| |---+ views <- Root for templates
|
|---+ routes <- Here all routers can be added.
| File names don't matter, as long as they're php files.
|---- .env <- Configuration file. see .env.example
|
|---- bootstrap.php <- Main starting point for the framework.
扩展
您还可以通过在 /App/Extensions
命名空间中创建一个类来扩展某些功能。扩展 必须 实现 Groundwork/Extensions/Extension
接口。
以下组件可以被扩展
-
App/Extensions/Renderer
用于添加 Twig 函数、过滤器等。 -
App/Extensions/Config
用于验证 .env 配置。可以使用Config::required()
或Config::optional()
验证新项目。 -
App/Extensions/Bootstrap
用于启动框架并注册任何容器实例。可以使用以下方式传递新实例$container->register('identifier', new TargetClass());
或- 作为
$container->register('identifier', 'App/Namespaces/TargetClass');
(或TargetClass::class
)。
类路径表示目标类仅在请求时才会实例化(懒加载)。
-
更多内容即将推出。
贡献
有关如何向项目贡献的信息,请参阅 贡献。