mardira/mardira-framework
Composer 安装命令:
composer require mardira/mardira-framework
包简介
Mardira Framework
关键字:
README 文档
README
Mardira Framework is a PHP framework Model Controller Based for building web applications and APIs. It is designed to be simple, and fast.
Table of Contents
- Requirements
- Structure Folders
- Installation
- Usage
- Start Server
- Create .env
- Create Controller
- Create Model
- Create Route
- Create Migration
- Run Migration
- Refresh Migration
- Refresh Migration With Seed
- Create Seeder
- Run Seeder
- Run Seeder Specific
- Create Authetication
- Refresh Authetication
- Update Framework Version
- Controller
- Model
- Migration
- Seeder
- Middleware
- Route
- Query Builder
Requirements
- PHP = 7.4
- MySQL >= 5.7.8
- Apache >= 2.4.41
- Composer >= 2.0.9
Structure Folders
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
Installation
Setup
You can create a new project using composer
composer create-project mardira/mardira-framework <your_project_name>
or you can clone this project
Clone
- Clone this repo to your local machine using `git clone
git clone https://github.com/Bootcamp-STMIK-Mardira-Indonesia/mardira-framework.git
Then, install the dependencies using composer
composer install
or
composer update
Usage
Start Server
php mardira serve
or
php mardira serve --port=<your_port>
Create .env
You can create .env file using command
php mardira make:env
Create Controller
php mardira make:controller ControllerName
Create Model
php mardira make:model ModelName
Create Route
php mardira make:route route_name --controller=ControllerName
Create Migration
php mardira make:migration create_table_table_name
Run Migration
If database not exist, will automatically create database from .env
php mardira migrate
Refresh Migration
php mardira migrate:refresh
Refresh Migration With Seed
php mardira migrate:refresh --seed
Create Seeder
php mardira make:seeder SeederName
Run Seeder
php mardira db:seed
Run Seeder Specific
php mardira db:seed --class=SeederName
Create Authetication
php mardira make:auth
Refresh Authetication
php mardira make:auth --refresh
Update Framework Version
php mardira update
Controller
Create controller use
php mardira make:controller ControllerName, here is example controller
<?php namespace App\Controllers; use App\Core\Controller; class HomeController extends Controller { public function index() { $this->response(200,[ 'message' => 'Hello World' ]); } }
to use controller, you can add route in
App/Routes/Api.php
<?php use App\Core\Route; use App\Controllers\HomeController; Route::get('/home', [HomeController::class, 'index']);
Response
You can use response in controller
$this->response(200,[ 'message' => 'Hello World' ]);
return json expected
{
"message": "Hello World"
}
another response example 409
$this->response->json(409,[ 'message' => 'Conflict' ]);
Model
Create model use
php mardira make:model ModelName, here is example model
<?php namespace App\Models; use App\Core\Model; class User extends Model { protected $table = 'users'; protected $primaryKey = 'id'; }
to use model, you can add model in
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 ]); } }
Migration
Create migration use
php mardira make:migration create_table_table_name, here is example migration
<?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'); } }
Seeder
Create seeder use
php mardira make:seeder SeederName, here is example seeder
<?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' => 'admin@admin.com', 'password' => password_hash('password', PASSWORD_DEFAULT), 'role_id' => 1, ], [ 'name' => 'User', 'username' => 'user', 'email' => 'user@user.com', 'password' => password_hash('password', PASSWORD_DEFAULT), 'role_id' => 2, ] ]; DB::table('users')->insert($data); } }
Middleware
Create middleware use
php mardira make:middleware MiddlewareName, here is example middleware
<?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']); } }
to use middleware, you can add middleware in route
Router::get('/schedules', [ScheduleController::class, 'index'], [AuthMiddleware::class]);
Routing
You can add route in
App/Routes/Api.php
<?php use App\Core\Route; Router::get('/home', [HomeController::class, 'index']);
Route Group
You can add route group in
App/Routes/Api.php
<?php use App\Core\Route; Router::controller(ProductController::class)->group(function () { Router::post('/products/store', 'store'); });
Query Builder
use App\Core\QueryBuilder as DB;
Select
DB::table('users')->select('name', 'email')->get();
Where
// 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();
Or Where
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();
Where In
DB::table('users')->whereIn('id', [1,2,3])->get(); DB::table('users')->whereNotIn('id', [1,2,3])->get();
Where Not In
DB::table('users')->whereNotIn('id', [1,2,3])->get();
Where Null
DB::table('users')->whereNull('id')->get();
Where Not Null
DB::table('users')->whereNotNull('id')->get();
Order By
DB::table('users')->orderBy('id', 'desc')->get(); DB::table('users')->orderBy('id', 'asc')->get();
Join Table
DB::table('users') ->join('roles', 'users.role_id', '=', 'roles.id') ->select('users.*', 'roles.name as role_name') ->get();
Group By
DB::table('users') ->groupBy('role_id') ->get();
Insert
DB::table('users')->insert([ 'name' => 'user', 'email' => 'user@user.com', 'password' => password_hash('password', PASSWORD_DEFAULT), ]);
Update
DB::table('users')->where('id', 1)->update([ 'name' => 'user', 'email' => 'user@gmail.com', ]);
Delete
DB::table('users')->where('id', 1)->delete();
Count
DB::table('users')->count();
Support
Reach out to me at one of the following places!
- Website at
demostmikmi.com
mardira/mardira-framework 适用场景与选型建议
mardira/mardira-framework 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 156 次下载、GitHub Stars 达 47, 最近一次更新时间为 2023 年 02 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「bootcamp」 「mardira」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mardira/mardira-framework 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mardira/mardira-framework 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mardira/mardira-framework 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Symfony2 BootCamp Bundle
Aplicación base para pruebas en módulos de Keepcoding Academy
Aplicación para el proyecto final Devops de Keepcoding Academy
High-performance, opinionated PHP 8 web framework with O(1) routing, parallel async MySQL, type-safe asset bridge, and React-island frontend
The skeleton application for the Geoffrey agent framework.
统计信息
- 总下载量: 156
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 47
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-01
