Mardira Framework هو وحدة تحكم نموذج PHP Framework تستند إلى بناء تطبيقات الويب وواجهة برمجة التطبيقات. إنه مصمم ليكون بسيطًا وسريعًا.
mardira-framework
├── App
│ ├── Controllers
│ │ ├── AuthController.php
│ ├── Core
│ │ ├── Commands
│ ├── Database
│ │ ├── Migrations
│ │ │ ├── 2023_01_31_xxxxxx_create_table_users.php
│ │ │ ├── 2023_01_31_xxxxxx_create_table_roles.php
│ │ ├── Seeders
│ │ │ ├── GlobalSeeder.php
│ ├── Helpers
│ ├── Middleware
│ ├── Models
│ ├── Packages
│ ├── Routes
│ │ ├── Api.phpيمكنك إنشاء مشروع جديد باستخدام الملحن
composer create-project mardira/mardira-framework < your_project_name >أو يمكنك استنساخ هذا المشروع
git clone https://github.com/Bootcamp-STMIK-Mardira-Indonesia/mardira-framework.gitثم ، قم بتثبيت التبعيات باستخدام الملحن
composer installأو
composer updatephp mardira serveأو
php mardira serve --port= < your_port >يمكنك إنشاء ملف .env باستخدام الأمر
php mardira make:envphp mardira make:controller ControllerNamephp mardira make:model ModelNamephp mardira make:route route_name --controller=ControllerNamephp mardira make:migration create_table_table_nameإذا لم تكن قاعدة البيانات موجودة ، فستقوم تلقائيًا بإنشاء قاعدة بيانات من .env
php mardira migratephp mardira migrate:refreshphp mardira migrate:refresh --seedphp mardira make:seeder SeederNamephp mardira db:seedphp mardira db:seed --class=SeederNamephp mardira make:authphp mardira make:auth --refreshphp mardira updateإنشاء وحدة تحكم استخدم
php mardira make:controller ControllerName
<?php
namespace App Controllers ;
use App Core Controller ;
class HomeController extends Controller
{
public function index ()
{
$ this -> response ( 200 ,[
' message ' => ' Hello World '
]);
}
}لاستخدام وحدة التحكم ، يمكنك إضافة مسار في
App/Routes/Api.php
<?php
use App Core Route ;
use App Controllers HomeController ;
Route:: get ( ' /home ' , [HomeController::class, ' index ' ]);يمكنك استخدام الاستجابة في وحدة التحكم
$ this -> response ( 200 ,[
' message ' => ' Hello World '
]);عودة json توقع
{
"message" : " Hello World "
}مثال رد فعل آخر 409
$ this -> response -> json ( 409 ,[
' message ' => ' Conflict '
]);إنشاء نموذج استخدم
php mardira make:model ModelName، هنا نموذج مثال
<?php
namespace App Models ;
use App Core Model ;
class User extends Model
{
protected $ table = ' users ' ;
protected $ primaryKey = ' id ' ;
}لاستخدام النموذج ، يمكنك إضافة نموذج في
App/Controllers/ControllerName.php
<?php
namespace App Controllers ;
use App Core Controller ;
use App Models User ;
class HomeController extends Controller
{
public function index ()
{
$ user = User:: all ();
$ this -> response ( 200 ,[
' message ' => ' Hello World ' ,
' data ' => $ user
]);
}
}إنشاء ترحيل استخدم
php mardira make:migration create_table_table_name، إليك مثال على ذلك الترحيل
<?php
namespace App Database Migrations ;
use App Core Migration ;
return new class extends Migration
{
public function up ()
{
$ this -> schema -> create ( ' users ' , function ( $ table ) {
$ table -> increment ( ' id ' );
$ table -> string ( ' name ' , 50 );
$ table -> string ( ' email ' , 50 )-> unique ();
$ table -> string ( ' password ' , 64 );
$ table -> timestamps ();
});
}
public function down ()
{
$ this -> schema -> dropIfExists ( ' users ' );
}
}إنشاء البذور استخدم
php mardira make:seeder SeederName، هنا مثال على البذور
<?php
namespace App Database Seeders ;
use App Core Seeder ;
use App Core QueryBuilder as DB ;
class UserSeeder extends Seeder
{
public function run ()
{
$ data = [
[
' name ' => ' Administrator ' ,
' username ' => ' admin ' ,
' email ' => ' [email protected] ' ,
' password ' => password_hash ( ' password ' , PASSWORD_DEFAULT ),
' role_id ' => 1 ,
],
[
' name ' => ' User ' ,
' username ' => ' user ' ,
' email ' => ' [email protected] ' ,
' password ' => password_hash ( ' password ' , PASSWORD_DEFAULT ),
' role_id ' => 2 ,
]
];
DB :: table ( ' users ' )-> insert ( $ data );
}
}إنشاء برامج الوسيطة استخدم
php mardira make:middleware MiddlewareName، إليك مثال على الوسيطة
<?php
namespace App Middleware ;
use App Core Middleware ;
use App Core Auth ;
class AuthMiddleware extends Middleware
{
public function handle ()
{
if (Auth:: check ()) {
return $ next ();
}
return $ this -> response ( 401 , [ ' message ' => ' Unauthorized ' ]);
}
}لاستخدام الوسيطة ، يمكنك إضافة برامج وسيطة في الطريق
Router:: get ( ' /schedules ' , [ScheduleController::class, ' index ' ], [AuthMiddleware::class]);يمكنك إضافة مسار في
App/Routes/Api.php
<?php
use App Core Route ;
Router:: get ( ' /home ' , [HomeController::class, ' index ' ]);يمكنك إضافة مجموعة الطريق في
App/Routes/Api.php
<?php
use App Core Route ;
Router:: controller (ProductController::class)-> group ( function () {
Router:: post ( ' /products/store ' , ' store ' );
}); use App Core QueryBuilder as DB ; DB :: table ( ' users ' )-> select ( ' name ' , ' email ' )-> get (); // equal
DB :: table ( ' users ' )-> where ( ' id ' , 1 )-> get ();
DB :: table ( ' users ' )-> where ( ' id ' , 1 , ' > ' )-> get ();
DB :: table ( ' users ' )-> where ( ' id ' , 1 , ' < ' )-> get ();
DB :: table ( ' users ' )-> where ( ' id ' , 1 , ' >= ' )-> get ();
DB :: table ( ' users ' )-> where ( ' id ' , 1 , ' <= ' )-> get ();
DB :: table ( ' users ' )-> where ( ' id ' , 1 , ' != ' )-> get ();
DB :: table ( ' users ' )-> where ( ' id ' , 1 , ' <> ' )-> get ();
// like
DB :: table ( ' users ' )-> where ( ' name ' , ' admin ' , ' like ' )-> get ();
DB :: table ( ' users ' )-> where ( ' name ' , ' admin ' , ' not like ' )-> get (); DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 )-> get ();
DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 , ' > ' )-> get ();
DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 , ' < ' )-> get ();
DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 , ' >= ' )-> get ();
DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 , ' <= ' )-> get ();
DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 , ' != ' )-> get ();
DB :: table ( ' users ' )-> orWhere ( ' id ' , 1 , ' <> ' )-> get (); DB :: table ( ' users ' )-> whereIn ( ' id ' , [ 1 , 2 , 3 ])-> get ();
DB :: table ( ' users ' )-> whereNotIn ( ' id ' , [ 1 , 2 , 3 ])-> get (); DB :: table ( ' users ' )-> whereNotIn ( ' id ' , [ 1 , 2 , 3 ])-> get (); DB :: table ( ' users ' )-> whereNull ( ' id ' )-> get (); DB :: table ( ' users ' )-> whereNotNull ( ' id ' )-> get (); DB :: table ( ' users ' )-> orderBy ( ' id ' , ' desc ' )-> get ();
DB :: table ( ' users ' )-> orderBy ( ' id ' , ' asc ' )-> get (); DB :: table ( ' users ' )
-> join ( ' roles ' , ' users.role_id ' , ' = ' , ' roles.id ' )
-> select ( ' users.* ' , ' roles.name as role_name ' )
-> get (); DB :: table ( ' users ' )
-> groupBy ( ' role_id ' )
-> get (); DB :: table ( ' users ' )-> insert ([
' name ' => ' user ' ,
' email ' => ' [email protected] ' ,
' password ' => password_hash ( ' password ' , PASSWORD_DEFAULT ),
]); DB :: table ( ' users ' )-> where ( ' id ' , 1 )-> update ([
' name ' => ' user ' ,
' email ' => ' [email protected] ' ,
]); DB :: table ( ' users ' )-> where ( ' id ' , 1 )-> delete (); DB :: table ( ' users ' )-> count ();تواصل معي في أحد الأماكن التالية!
demostmikmi.com