pepperfm/macros-for-laravel 问题修复 & 功能扩展

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

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

pepperfm/macros-for-laravel

Composer 安装命令:

composer require pepperfm/macros-for-laravel

包简介

A small macro registry for Laravel facades / macroable classes.

README 文档

README

Small macro registry for Laravel facades and Macroable classes. It lets you enable macro groups via config and register everything automatically at boot.

Install

composer r pepperfm/macros-for-laravel

Laravel auto-discovers the provider: Pepperfm\LaravelMacros\Providers\LaravelMacrosServiceProvider.

Publish config

php artisan vendor:publish --tag=macros-for-laravel-config

config/macros-for-laravel.php:

return [
    'enabled' => env('MACROS_ENABLED', true),
    'profile' => env('MACROS_PROFILE', 'default'),
    'conflicts' => 'throw', // throw | overwrite
    'unreachable' => 'throw', // throw | skip
    'profiles' => [
        'default' => [
            \Pepperfm\LaravelMacros\Groups\Support\ArrCastMacros::class => true,
            \Pepperfm\LaravelMacros\Groups\Support\ArrNativeMacros::class => true,
            \Pepperfm\LaravelMacros\Groups\Cache\CacheCastMacros::class => true,
            \Pepperfm\LaravelMacros\Groups\Config\ConfigCastMacros::class => true,
            \Pepperfm\LaravelMacros\Groups\Support\CollectionMacros::class => true,
        ],
        // 'http' => [
        //     \Pepperfm\LaravelMacros\Groups\Facades\ResponseMacros::class => true,
        // ],
    ],
];

Switch profiles via env:

MACROS_PROFILE=http

You can also use the legacy top-level groups list (no profiles):

'groups' => [
    \Pepperfm\LaravelMacros\Groups\Support\ArrCastMacros::class => true,
];

Built-in macros

Arr cast helpers

Available when ArrCastMacros is enabled:

Arr::toBool($array, 'flag');
Arr::toInt($array, 'count');
Arr::toFloat($array, 'ratio');
Arr::toString($array, 'name', null, true);
Arr::toArray($array, 'items');
Arr::toEnum($array, 'status', Status::class, $default = null);

Arr native array helpers

Available when ArrNativeMacros is enabled:

Arr::values($array);
Arr::keys($array);
Arr::keyFirst($array);
Arr::keyLast($array);
Arr::flip($array);
Arr::combine(['a', 'b'], [1, 2]);
Arr::unique(['a', 'a', 'b']);
Arr::reverse([1, 2, 3]);

Collection paginate

Available when CollectionMacros is enabled:

collect([1, 2, 3])->paginate(2);

Collection filters

Available when CollectionMacros is enabled:

collect([1, null, 2])->filterNotNull();
collect(['', ' ', 'ok', null])->filterNotBlank();

Cache typed getters

Available when CacheCastMacros is enabled:

cache()->toBool('enabled', false);
cache()->toInt('count', 0);
cache()->toFloat('ratio', 0.0);
cache()->toString('name', 'guest', true);
cache()->toArray('filters', []);
cache()->toEnum('status', Status::class, Status::Draft);

Cache::toString('name', 'guest');
cache()->store('redis')->toInt('count', 0);

cache('name', 'guest')->toString() is not supported because Laravel's cache() helper returns the raw cached value when a key is passed.

Config typed getters

Available when ConfigCastMacros is enabled:

config()->toBool('features.enabled', false);
config()->toInt('features.count', 0);
config()->toFloat('features.ratio', 0.0);
config()->toString('app.name', 'Laravel', true);
config()->toArray('features.filters', []);
config()->toEnum('features.status', Status::class, Status::Draft);

Config::toString('app.name', 'Laravel');

config('app.name', 'Laravel')->toString() is not supported because Laravel's config() helper returns the raw config value when a key is passed.

Custom groups

Create a group that implements Pepperfm\LaravelMacros\Contracts\MacroGroupContract, then add it to a profile (or to groups in legacy mode). It will be resolved via the container.

pepperfm/macros-for-laravel 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-19