mardira/mardira-framework 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mardira/mardira-framework

Composer 安装命令:

composer require mardira/mardira-framework

包简介

Mardira Framework

README 文档

README

Mardira Logo

Mardira Framework is a PHP framework Model Controller Based for building web applications and APIs. It is designed to be simple, and fast.

Total Downloads Total Stars Total Forks Version License

Table of Contents

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!

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 mardira/mardira-framework 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 156
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 47
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 47
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-01