tarik02/laravel-mixin 问题修复 & 功能扩展

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

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

tarik02/laravel-mixin

Composer 安装命令:

composer require tarik02/laravel-mixin

包简介

Mixin library for Laravel

README 文档

README

Travis CI Build Status Latest Stable Version Total Downloads Packagist License

Take class, some traits and interfaces and put them in one place. For example, add new methods, relations, etc. to existing model without touching it. Very useful for dividing project into packages without loosing ability to improve.

NOTE: This can only be used with special packages which are ready to use this package. See below for more information.

Installation

$ composer require tarik02/laravel-mixin
$ mkdir -p storage/framework/mixin
$ echo "*\n\!.gitignore" > storage/framework/mixin/.gitignore

Commands

The package provides the following commands:

$ php artisan mixin:cache        # Cache all mixins and use only cache
$ php artisan mixin:cache:clear  # Clear mixins cache
$ php artisan mixin:generate     # Generate all mixins

Cache should only be used in production and be regenerated after every code change.

Documentation

You can generate documentation using the Sami. Documentation for master branch is always available here.

Note

You should use all methods of this package only during application booting phase. Using them during another stages may lead to undefined behaviour.

Usage example

Create your model class (note, the class is abstract):

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Article
 *
 * @property int $id
 * @property string $title
 * @property string $description
 * @property string $text
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $deleted_at
 */
abstract class Article extends Model
{
    //
}

Create App\Providers\MixinServiceProvider:

<?php

namespace App\Providers;

use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\ServiceProvider;

class MixinServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $mixin = $this->app->make('mixin');

        $mixin
            ->register(\Models\Article::class, \App\Models\Article::class)
            ->mixTrait(SoftDeletes::class)
        ;

        $mixin
            ->class(\Models\Article::class)
            ->mixInterface(MyInterface::class)
        ;
    }
}

Add MixinServiceProvider before AppServiceProvider to providers section in config/app.php:

+        App\Providers\MixinServiceProvider::class,
         App\Providers\AppServiceProvider::class,

Now you have to use \Models\Article class instead of \App\Models\Article (really, you can name it whatever you want).

If your trait has a constructor, you should pass true as second parameter to mixTrait function.

Complete list of building methods of MixedClass:

  • mixInterface(string $name) - add an interface to implements section.
  • mixTrait(string $name, bool $hasConstructor = false) - add a trait to use section.
  • useInsteadOf(string $method, string $trait, string $replacedTrait) - use method named $method from trait $trait instead of the one from $replacedTrait.
  • renameMethod(string $trait, string $oldName, string $newName) - rename method named $oldName of trait $trait to $newName.
  • beforeConstruct(string $code) - add $code before parent constructor call.
  • afterConstruct(string $code) - add $code after parent constructor call.
  • code(string $code) - add $code into class body (property or method).

Under the hood

Actually, the code above generates class which extends specified class, uses specified traits and implements specified interfaces. Classes are located at storage/framework/mixin and can be cached (see Caching section). Here's how the class looks like:

<?php

namespace Models;

use App\Models\Article as Base;

class Article
    extends Base
{
    use \Illuminate\Database\Eloquent\SoftDeletes;
}

License

The package is open-sourced software licensed under the MIT license.

tarik02/laravel-mixin 适用场景与选型建议

tarik02/laravel-mixin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 01 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 tarik02/laravel-mixin 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-27