# 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