# Shani Web Application Framework
Shaniは、パフォーマンス、セキュリティ、創造性、最新のWebアプリケーション開発の実践を共存しながら、最小限の労力で迅速なアプリケーション開発を可能にするように設計されたオープンソースWebフレームワークです。
Shaniを使用して、Cilent側またはサーバー側のアプリケーションを構築します。また、 Shaniがバックエンドに立つ間、またはその逆になっている間、お気に入りのフロントエンドフレームワークを使用することもできます。
ShaniはLinuxとMac OSでうまく動作しますが、Windowsユーザーの場合、Linux(WSL)にWindowsサブシステムを使用できます。
インストールは必要ありません。
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)
バージョン1.0( v1 )を持つdemo呼ばれるアプリケーションを作成すると仮定します。当社のアプリケーションには、 greetingsと呼ばれる1つのモジュールと、 Hello.phpと呼ばれる1つのリソースファイルがあります。
次に、リソースファイルの次の例をご覧ください。
<?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
次のステップは、アプリケーションをWebで利用できるように登録することです。これを行うには/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 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アプリケーションでエイリアス(ES)を作成する方法です。
繰り返しますが、アプリケーションが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 ApplicationはKebabからCamel Case Conversionを使用して、URLを有効な名前に変換します。
module-nameプロジェクト構造のmodule-nameディレクトリを表します。resource-name module-nameディレクトリのResourceNameクラスを表し、ビューディレクトリのresource-nameディレクトリを表しますfunction-name ResourceNameクラスファイルのfunctionNameを表し、 function-name.phpビュービューディレクトリのviewを表します他のURLパーツは変更されていません。
プルリクエストは大歓迎です。大きな変更については、最初に問題を開いて、何を変えたいかを議論してください。
必要に応じて、必ずテストを更新してください。
GPL-3.0