lyhty/macronite
Composer 安装命令:
composer require lyhty/macronite
包简介
Helpful macro maker for your Laravel project.
README 文档
README
This package provides a very convenient macro maker to your Laravel project.
Installation
Install the package with Composer:
composer require lyhty/macronite
The package registers itself automatically.
Extending the MacroServiceProvider
You can make your own pretty MacroServiceProviders by extending the MacroServiceProvider class provided by this package!
Here's an example:
<?php namespace App\Providers; use Lyhty\Macronite\MacroServiceProvider as ServiceProvider; class MacroServiceProvider extends ServiceProvider { protected static array $macros = [ \Illuminate\Support\Collection::class => [ 'example' => \App\Macros\ExampleMacro::class, \App\Macros\SecondExampleMacro::class, ] ]; }
The first macro class referenced in the example above would look something like:
<?php namespace App\Macros; class ExampleMacro { public function __invoke(): \Closure { return function () { // Something cool worth getting macroed happens here... return $this; } } }
The Macro service provider handles the mapping of the macros quite responsively. You can either
explicitly name the macro by setting the key of the array row defining the macro as the name you wish
to use. Alternatively you can define a constant MACRO_NAME inside the macro file, which will be used
if the key is not defined in the service provider.
Finally, if the key is not defined in the service provider and the macro class does not contain
the constant, the class name will be used. For example ExampleMacro::class macro will be named as
example.
Commands
make:macro
You can use make:macro <name> to generate a macro file to help you with the structure. The command
supports --mixin option (example: --mixin=/Illuminate/Support/Collection). This will add a PHP
docblock above the macro class declaration with @mixin tag.
macro:generate
The package also comes with macro:generate command. If you have a provider class setup that extends
Lyhty\Macronite\MacroServiceProvider class, the command will go through the macros
defined in the provider and generate the ones that are missing. This way you can define multiple macros
you know you will have and then generate them in bulk. It is very similar to Laravel's event:generate
in its behavior.
For example:
<?php namespace App\Providers; use Lyhty\Macronite\MacroServiceProvider as ServiceProvider; class MacroServiceProvider extends ServiceProvider { protected static array $macros = [ \Illuminate\Support\Collection::class => [ 'example' => \App\Macros\ExampleMacro::class, ] ]; }
Assuming ExampleMacro doesn't exist yet, the command would then generate the macro class, automatically
also filling in the @mixin tag.
macro:cache & macro:clear
Since the macro mapping is very dynamic, you can cache the macros to be set in stone with macro:cache.
The cache can be cleared with the macro:clear function.
macro:list
If you want to list all the macros that are created using the MacroServiceProvider, you can use the
macro:list command.
Example output:
$ php artisan macro:list Illuminate\Database\Eloquent\Builder ⇂ orWhereLike ...................................... Lyhty\Macros\Builder\WhereLikeOrMacro ⇂ selectKey .......................................... Lyhty\Macros\Builder\SelectKeyMacro ⇂ whereLike .......................................... Lyhty\Macros\Builder\WhereLikeMacro
Example verbose output:
$ php artisan macro:list --v Illuminate\Database\Eloquent\Builder ⇂ orWhereLike ...................................... Lyhty\Macros\Builder\WhereLikeOrMacro ⇂ Parameter #0 [ <required> $attributes ] ⇂ Parameter #1 [ <required> string $searchTerm ] ⇂ Parameter #2 [ <optional> $pattern = 'both' ] ⇂ Return [ mixed ]
License
Lyhty Macros is open-sourced software licensed under the MIT license.
lyhty/macronite 适用场景与选型建议
lyhty/macronite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 193 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 08 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「macro」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lyhty/macronite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lyhty/macronite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lyhty/macronite 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Convert has() and whereHas() constraints to non-dependent subqueries.
Latte macro to embed SVG from file into HTML
Latte macro to embed SVG from file into HTML
A useful set of HTML and Form macros with css and js made for bootstrap
A lightweight PHP DI container, invoker, serializer, and utility toolkit.
Alfabank REST API integration
统计信息
- 总下载量: 193
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-10