luthier framework
Version 0.1.1
警告:正在開發!
Luthier Framework是一種快速構建API和小型網站的多功能PHP微型框架。當我們說“微型”時,我們的意思是真正的微觀:實際上,只需要作曲家和一個.php文件才能開始。
與作曲家獲取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
即將推出!
如果您喜歡我們的工作,請考慮在Patreon上支持我們