tarik02/laravel-mixin
Composer 安装命令:
composer require tarik02/laravel-mixin
包简介
Mixin library for Laravel
关键字:
README 文档
README
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$methodfrom trait$traitinstead of the one from$replacedTrait.renameMethod(string $trait, string $oldName, string $newName)- rename method named$oldNameof trait$traitto$newName.beforeConstruct(string $code)- add$codebefore parent constructor call.afterConstruct(string $code)- add$codeafter parent constructor call.code(string $code)- add$codeinto 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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tarik02/laravel-mixin 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Functional programming utilities for composing, decorating, and controlling function execution
Function composition.
Reusable PHP traits for HTML rendering components: attribute management, content, templates, and prefix/suffix/label collections.
Reusable PHP traits for HTML rendering components: attribute management, content, templates, and prefix/suffix/label collections.
A lightweight PHP DI container, invoker, serializer, and utility toolkit.
Stylize - Css Preprocessor using Scss syntax ( SASS 3.x ) ported to PHP with added supports: php imbrication, php mixin, mixin autoload, extend autoload, font autoload - derived from leafo-scssphp
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-01-27