# Shani Web Application Framework
Shani เป็นเฟรมเวิร์กเว็บโอเพ่นซอร์สที่ออกแบบมาเพื่อเปิดใช้งานการพัฒนาแอปพลิเคชันที่รวดเร็วด้วยความพยายามน้อยที่สุดในขณะที่ประสิทธิภาพความปลอดภัยความคิดสร้างสรรค์และแนวทางปฏิบัติในการพัฒนาเว็บแอปพลิเคชันที่ทันสมัยอยู่ร่วมกัน
ใช้ Shani เพื่อสร้างแอปพลิเคชันด้านข้างหรือเซิร์ฟเวอร์ นอกจากนี้คุณยังสามารถใช้เฟรมเวิร์กส่วนหน้าสุดโปรดของคุณในขณะที่ Shani ยืนอยู่บนแบ็คเอนด์หรือในทางกลับกัน
Shani ทำงานได้ดีบน Linux และ Mac OS อย่างไรก็ตามสำหรับผู้ใช้ Windows พวกเขาสามารถใช้ระบบย่อย Windows สำหรับ Linux (WSL)
ไม่จำเป็นต้องมีการติดตั้ง
ในการเริ่มต้นเว็บเซิร์ฟเวอร์แอปพลิเคชัน Shani ให้เรียกใช้คำสั่งต่อไปนี้บนเทอร์มินัล:
$ php index.phpแอปพลิเคชัน Shani มีโครงสร้างโครงการต่อไปนี้
/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 ไฟล์. local.alias
โปรดจำไว้ว่า ไฟล์ localhost.yml จะต้องพร้อมใช้งานก่อนที่จะสร้างไฟล์ .alias มิฉะนั้นเซิร์ฟเวอร์ของคุณจะบดขยี้
เนื้อหาไฟล์ 127.0.0.1.alias
localhost
ตัวอย่างไฟล์ไฟล์ example.local.alias
localhost
อย่างที่เราได้เห็นไฟล์ .alias ทั้งหมดจะต้องมีชื่อโฮสต์ที่พวกเขาชี้ไป นี่คือวิธีที่คุณสร้างนามแฝงในแอปพลิเคชัน Shani
อีกครั้งสมมติว่าแอปพลิเคชันของเราพร้อมใช้งานผ่าน localhost:8008 พอร์ตเริ่มต้นสำหรับเว็บเซิร์ฟเวอร์ของเราคือ 8008 สำหรับ HTTP และพอร์ต 44380 สำหรับ HTTPS เราสามารถใช้ 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 ใน URL หมายถึงไดเรกทอรี module-name ในโครงสร้างโครงการresource-name ใน URL หมายถึงคลาส ResourceName ในไดเรกทอรี module-name และไดเรกทอรี resource-name ในไดเรกทอรีมุมมองfunction-name ใน url ResourceName function-name.php functionNameชิ้นส่วน URL อื่น ๆ ยังคงไม่เปลี่ยนแปลง
ยินดีต้อนรับคำขอดึง สำหรับการเปลี่ยนแปลงครั้งใหญ่โปรดเปิดปัญหาก่อนเพื่อหารือเกี่ยวกับสิ่งที่คุณต้องการเปลี่ยนแปลง
โปรดตรวจสอบให้แน่ใจว่าได้อัปเดตการทดสอบตามความเหมาะสม
GPL-3.0