承接 scriptpage/framework 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

scriptpage/framework

Composer 安装命令:

composer require scriptpage/framework

包简介

Core code of the Scriptpage framework

README 文档

README

v3.0

Note: This repository contains the core code of the Scriptpage framework. If you want to build an application using Laravel with scriptpage, you need know Scriptpage Sail.

See a MVC Starter with VueJS using scriptpage: starter-with-vuejs

You want to know a little more about the Repository pattern? Read this great article.

Table of Contents

Installation

Composer

Execute the following command to get the latest version of the package:

composer require scriptpage/framework

Laravel

Execute the following command to install componente on project:

php artisan vendor:publish --tag=scriptpage-install

To enable helpers.php file, add in composer.json:

    "autoload": {
        "psr-4": {
        ...
        },
        "files": [
            "app/helpers.php"
        ]

Then, execute the following command to reload componentes on project:

composer dumpautoload -o

Add in api or web route file:

Route::middleware('auth')->group(function () {

    /**
     * Home routes
     */
    addRoute('web/home');

    /**
     * Users routes
     */
    addRoute('web/users');

});

/**
 * Auth routes
 */
addRoute('api/auth');

/**
 * Users routes
 */
Route::prefix('v1')->group(function () {
        addRoute('api/users');
});

JWT Authorization

Execute the following commands to install and configure JWT package with scriptpage:

composer require tymon/jwt-auth
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
php artisan jwt:secret
php artisan vendor:publish --tag=scriptpage-jwt

Inside the config/auth.php make the following changes to the file:

'defaults' => [
    'guard' => 'api',
    'passwords' => 'users',
],

...

'guards' => [
    'api' => [
        'driver' => 'jwt',
        'provider' => 'users',
    ],
],

Add trait in Models\User class.

...

use App\Traits\traitUserJWT;

class User extends Authenticatable implements JWTSubject
{
  ...

  use traitUserJWT;

Add in App\Http\Kernel class.

protected $middlewareAliases = [
        ...

        'auth' => \Scriptpage\Middleware\EnsureUserAuth::class,
];

Role permissions

Execute the following commands to install and configure role permissions of scriptpage:

php artisan vendor:publish --tag=scriptpage-role

Add in App\Http\Kernel class.

protected $middlewareAliases = [
        ...

        'roles' => \Scriptpage\Middleware\EnsureUserHasRole::class,
];

Global Exception

Defining a global exception on your application's in App\Exceptions\Handler@register class.

use Scriptpage\Traits\traitApiRenderableResponse;

class Handler extends ExceptionHandler
{
        use traitApiRenderableResponse;

        ...

        $this->renderable(function (Exception $e, Request $request) {
                return $this->apiRenderableResponse($e, $request);
        });

Application Version

Add this lines in Config/App.php file:

'version' => env('APP_VERSION', '1.0.0'),
'project_name' => env('APP_PROJECT_NAME', 'app'),

URL Query Filters

filters

  • select = $column1,$column2,...
  • with = $relation1,$relation2,...
  • withCount = $relation1,$relation2,...
  • withSum = $relation:$column
  • where = $column,[$condition = 'equal']:$value
  • orWhere = $column,[$condition = 'equal']:$value
  • join = $table:$field1,$field2
  • leftJoin = $table:$field1,$field2
  • rightJoin = $table:$field1,$field2
  • take = $limit
  • skip = $offset
  • orderBy = $column:[$direction = 'asc']
  • groupBy = $column1,$column2,...
  • having = $column,[$condition = 'equal']:$value
  • orHaving = $column,[$condition = 'equal']:$value
  • paginate = true|false

array is separated by semicolons, example: expresion1; expression2; expresion3...

Conditions

  • equal( = )

      $field:$value
    
  • greater( > )

      $field,greater:$value
    
  • greater_or_equal( >= )

      $field,greater_or_equal:$value
    
  • less( < )

      $field,less:$value
    
  • less_or_equal( <= )

      $field,less_or_equal:$value
    
  • different ( <> )

      $field,different:$value
    
  • null_safe ( <=> )

      $field,null_safe:$value
    
  • in

      $field,in:$value1,$value2,$value3...
    
  • not_in

      $field,in:$value1,$value2,$value3...
    
  • like

      $field,like:$pattern
    
      $pattern, examples:
    
              _value*
              value*
              *value_*
    
  • not_like

      $field,like:$pattern
    
  • between

      $field,between:$value1, $value2
    
  • not_between

      $field,not_between:$value1, $value2
    

Examples

Using repository by request

Model

  • get api/users

With clausule

  • get api/users?select=id,name,email&with=roles

Where clausule

  • get api/users?where=role_id:2
  • get api/users?where=role_id:2;name:ester
  • get api/users?where=role_id:2&orWhere=name:ester
  • get api/users?where=role_id,between:34,52
  • get api/users?where=email_verified_at:2023-05-14 14.02.20

to Sql

Show sql statement result

  • get api/users/sql?where=email_verified_at:2023-05-14 14.02.20

selecting fields

  • get api/model/users?select=id,name,email

Database

  • get api/users/db?select=name,email&where=id,greater:200

Add relationship

get api/table/users?join=contacts:users.id,contacts.user_id

get api/table/users
    ?join=contacts:users.id,contacts.user_id
    ;orders:users.id,orders.user_id
    &where=users.name:laravel
    &select=users.*,contacts.phone,orders.price

Laravel Eloquent Query: Using WHERE with OR AND OR

Make use of Logical Grouping

    Model::where(function ($query) {
    $query->where('a', '=', 1)
            ->orWhere('b', '=', 1);
    })->where(function ($query) {
    $query->where('c', '=', 1)
            ->orWhere('d', '=', 1);
    });

With parameters for a,b,c,d

$a = 1;
$b = 1;
$c = 1;
$d = 1;
Model::where(function ($query) use ($a, $b) {
    return $query->where('a', '=', $a)
        ->orWhere('b', '=', $b);
})->where(function ($query) use ($c, $d) {
    return $query->where('c', '=', $c)
        ->orWhere('d', '=', $d);
});

Footnotes

  1. A framework is an abstraction that links common code across multiple software projects to provide generic functionality. A framework can achieve specific functionality, by configuration, during application programming. Unlike libraries, it is the framework that dictates the flow of control of the application, called Inversion of Control..wikipedia

scriptpage/framework 适用场景与选型建议

scriptpage/framework 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 623 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 05 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「repository」 「laravel」 「eloquent」 「jwt」 「url query string」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 scriptpage/framework 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 scriptpage/framework 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 623
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-06