luthier / 框架
多功能的PHP微框架,用于快速构建API和网站
0.1.1
2019-02-14 17:30 UTC
Requires
- php: >=7.1.8
- envms/fluentpdo: ^1.1
- filp/whoops: ^2.2
- monolog/monolog: ~1.0
- pimple/pimple: ~3.0
- spatie/array-to-xml: ~2.0
- symfony/config: ~3.4|~4.0
- symfony/console: ^4.0
- symfony/dotenv: ^4.0
- symfony/event-dispatcher: ^4.0
- symfony/http-foundation: ^4.0
- symfony/http-kernel: ^4.0
- symfony/routing: ^4.0
- symfony/translation: ^4.0
- symfony/validator: ^4.0
Requires (Dev)
- illuminate/view: ~5.0
- league/plates: ~3.0
- phpunit/phpunit: ^7
- twig/twig: ^2.0
This package is auto-updated.
Last update: 2024-09-15 05:54:55 UTC
README
警告:处于开发中!
Luthier框架是一个多功能的PHP微框架,用于快速构建API和小型网站。当我们说“微”时,我们的意思是真正的微:实际上,只需Composer和单个.php文件即可开始。
特性
- 基于Symfony组件
- 易于学习和扩展
- 强大的灵活路由器,支持中间件
- CSRF保护
- JSON和XML响应助手
- 带有翻译错误消息的验证器
- 依赖注入容器
- 命令行界面命令创建
- 内置纯PHP模板引擎,支持Twig和Blade集成
要求
- PHP >= 7.1.8
- Composer
安装
使用composer获取Luthier框架
composer require luthier/framework
使用方法
基本示例
<?php # your_app/index.php require 'vendor/autoload.php'; $app = new Luthier\Framework(); $app->get('/', function(){ $this->response->write("Hello world!"); }); $app->group('api', function(){ $this->get('/', function(){ json_response(['message' => 'Welcome to Luthier Framework!']); }); $this->get('about', function(){ json_response(['version' => Luthier\Framework::VERSION]); }); }); $app->run();
定义路由
$app->get('foo/', function(){ // Default template engine (will search for /foo.php file) view('foo'); }); $app->post('bar/', function(){ view('bar'); }); $app->match(['get','post'], 'baz/', function(){ view('baz'); });
路由参数
$app->get('hello/{name}', function($name){ $this->response->write("Hello $name!"); }); // Optional parameters $app->get('about/{category?}', function($category = 'animals'){ $this->response->write("Category: category"); }); // Regex parameters $app->get('website/{((en|es|fr)):lang}', function($lang){ $this->response->write($lang); });
路由中间件
// Global middleware: $app->middleware(function($request, $response, $next){ $response->write('Global <br>'); $next($request, $response); }); // Global middleware (but not assigned to any route yet) $app->middleware('test', function($request, $response, $next){ $response->write('Before route<br>'); $next($request, $response); $response->write('After route <br>'); }); $this->get('/', function(){ $this->response->write('Route <br>') })->middleware('test'); // <- assign the 'test' middleware to this route
文档
即将推出!
相关项目
- Luthier CI:为CodeIgniter 3框架提供改进的路由、中间件支持、认证工具等
- SimpleDocs:使用Markdown文件动态文档库的PHP库
捐赠
如果您喜欢我们的工作,请考虑在Patreon上支持我们