# Shani Web Application Framework
Shani是一個開源Web框架,旨在以最少的努力來實現快速的應用程序開發,而性能,安全性,創造力和現代Web應用程序開發實踐共存。
使用Shani構建纖毛端或服務器端應用程序。您也可以使用自己喜歡的前端框架,而Shani站在後端,反之亦然。
Shani在Linux和Mac OS上運行良好,但是對於Windows用戶,他們可以將Windows子系統用於Linux(WSL)。
無需安裝。
要啟動Shani應用程序Web服務器,請在終端上運行以下命令:
$ php index.phpShani應用程序具有以下項目結構
/root
apps/ (Contains user applications. Create your applications here)
config/ (Contains important server and hosts configurations)
hosts/ (Contains host configurations files (hostname.yml). Register your application here)
localhost.yml (can be customized)
ssl/ (Contains server ssl certificate files for)
mime.yml
server.yml (Server configuration are written here, and can be customized.)
gui/ (Contains support for GUI building)
assets/ (Contains static files e.g: .css, .js,fonts etc shared by all applications)
html/ (Contains html templates comes with framework)
library/ (Contains files comes with framework that can be used directly by user application)
shani/ (Contains core framework files)
index.php (The entry point of a Shani application)
典型的用戶應用程序文件夾結構可能顯示為以下內容:
apps/
demo/
v1/
modules/ (Can be renamed)
module1_name/ (Can be desired module name)
src/ (Can be renamed)
get/ (This is the request method as directory)
Resource.php (Can be any resource file)
views/ (can be renamed)
resource/ (All lowercase, must match resource file name)
lang/ (Can be renamed)
resource/ (All lowercase, must match resource file name)
breadcrumb/(Can be renamed)
resource/ (All lowercase, must match resource file name)
functions/ (can be renamed)
function-name.php (Must match function name in resource file class)
resource.php (must match module name)
module1_name.php (must match module name)
假設我們要創建一個名為demo的應用程序,其中版本為1.0( v1 )。我們的應用程序具有一個稱為greetings的模塊,一個名為Hello.php的資源文件。
現在,查看資源文件的以下示例:
<?php
namespace apps demo v1 modules greetings web get {
use shani engine http App ;
final class Hello
{
private App $ app ;
public function __construct ( App & $ app )
{
$ this -> app = $ app ;
}
/**
* Display greetings from Shani.
*/
public function world ()
{
//sending output to user agent using default view file (world.php)
$ this -> app -> render ();
}
}
}創建查看文件:( apps/demo/v1/modules/greetings/views/hello/world.php )
<h1>Hello From Shani</h1>考慮到上面的示例,我們的應用程序文件夾結構將是這樣:
apps/
demo/
v1/
modules/
greetings/
src/
get/
Hello.php
views/
hello/
world.php
下一步是註冊我們的應用程序,以便可以在網絡上使用。您可以通過轉到/config/hosts/並創建一個稱為localhost.yml的配置文件來做到這一點。您可以選擇任何名稱。
記住!每個應用程序必須具有自己的配置文件
以下是Shani隨附的默認應用程序配置
# A user application must have atleast one version.
VERSIONS :
" 1.0 " :
# Environment variables are customs, you can create any e.g DEV, TEST, PROD or any
# Must extends shaniadvisorsConfiguration
ENVIRONMENTS :
DEV : appsdemov1configSettings
# Active environment can any one of the provided above.
ACTIVE_ENVIRONMENT : DEV
DEFAULT_LANGUAGE : sw
# Whether an application is running or not
RUNNING : true
" 2.0 " :
ENVIRONMENTS :
DEV : appsdemov2configSettings
ACTIVE_ENVIRONMENT : DEV
DEFAULT_LANGUAGE : sw
RUNNING : true
# The default application version
DEFAULT_VERSION : " 2.0 "讓我們自定義此文件以滿足我們的應用程序需求:
VERSIONS :
" 1.0 " :
ENVIRONMENTS :
DEV : appsdemov1configDevSettings
TEST : appsdemov1configTestSettings
PROD : appsdemov1configProdSettings
ACTIVE_ENVIRONMENT : DEV
DEFAULT_LANGUAGE : sw
RUNNING : true
DEFAULT_VERSION : " 1.0 "下一步是創建這些配置類文件。我們將在apps/demo/v1/config/下創建它們。有些內容可能是這樣:
<php
namespace apps demo v1 config {
use shani advisors Configuration ;
use shani engine http App ;
final class DevSettings extends Configuration
{
public function __construct ( App & $ app , array & $ configurations )
{
parent :: __construct ( $ app , $ configurations );
}
//Add all unimplemented methods here
}
}讓我們假設我們的應用程序可以通過http://localhost:8008提供,我們還希望通過http://127.0.0.1:8008和http://example.local或更多...
出現了別名的概念,是當應用程序可通過多個主機名提供時。就像我們創建localhost.yml文件一樣,我們將創建127.0.0.1.alias文件和example.local.alias文件。
請記住文件localhost.yml必須在創建.alias文件之前可用,否則您的服務器會壓碎
127.0.0.1.alias文件內容
localhost
example.local.alias文件內容
localhost
如我們所見,所有.alias文件必須包含他們指向的主機名。這就是您在Shani應用程序中創建別名的方式。
同樣,讓我們假設我們的應用程序可通過localhost:8008獲得。我們的Web服務器的默認端口為HTTP的8008 ,HTTPS的端口44380 。我們可以使用以下URL來調用我們的功能world 。
$ curl http://localhost:8008/greetings/0/hello/0/world恭喜!您已經完成了成為Shani開發人員的第一步。
Shani應用程序遵循以下URL模式
http://hostname[:port]/module-name/param1/resource-name/param2/function-name[/more-params][?query=q1]
分解上面的模式,我們可以看到
module-name表示用戶請求的當前資源模塊。這是一個目錄,該模塊下的所有子資源均位於該目錄中。param1和param2是資源標識符,可以是數字,字符串或任何東西resource-name或某個名為controller-name是一個子資源。這是應用程序的實際實施,function-name是資源類定義中可用的函數名稱。函數名稱後,您可以添加更多參數或附加查詢字符串例子:
http://localhost:8008/products/201/sales/10/details
Shani應用程序使用烤肉串將其轉換為駱駝盒轉換,將URL轉換為有效名稱。
module-name表示項目結構中的module-name目錄。resource-name代表module-name中的ResourceName類,而View Directory中的resource-name目錄表示function-name代表ResourceName類文件中的functionName ,而function-name.php視圖中的函數名稱其他URL零件保持不變。
歡迎拉動請求。對於重大更改,請先開設一個問題,以討論您想更改的內容。
請確保及時更新測試。
GPL-3.0