frictionlessdigital/macros 问题修复 & 功能扩展

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

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

frictionlessdigital/macros

Composer 安装命令:

composer create-project frictionlessdigital/macros

包简介

Frictionless Solutions | Macros

README 文档

README

Ass some common macroses that Frictionless uses in their daily life.

Installation

composer require "frictionlessdigital/macros":"^1.0"

Note that root namespace for the package is Fls not Frictionlessdigital.

Config

To publish configuration file, run

php artisan vendor:publish --tag=fls.macros-config

The package will publish fls.macros.php file:

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Collection;
use Illuminate\Routing\Router;
use Laravel\Dusk\Browser;

return [

    /*
    |--------------------------------------------------------------------------
    | Laravel\Dusk\Browser Macros
    |--------------------------------------------------------------------------
    | To install
    | composer require laravel/dusk
    |
    */
    Browser::class => [
        // 'firstWindow' => \Fls\Macros\Macros\Browser\FirstWindow::class,
        // 'lastWindow' => \Fls\Macros\Macros\Browser\LastWindow::class,
        // 'switchToFirstWindow' => \Fls\Macros\Macros\Browser\SwitchToFirstWindow::class,
        // 'switchToLastWindow' => \Fls\Macros\Macros\Browser\SwitchToLastWindow::class,
        // 'windows' => \Fls\Macros\Macros\Browser\Windows::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Illuminate\Database\Eloquent\Builder
    |--------------------------------------------------------------------------
    | Enabled by default
    |
    */
    Builder::class => [
        'toSqlWithBindings' => \Fls\Macros\Macros\Builder\ToSqlWithBindings::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Carbon\Carbon
    |--------------------------------------------------------------------------
    | startOfFiscalYear($at = null) will return the return of fiscal year
    |
    */
    Carbon::class => [
        'fiscalYearForHumans' => \Fls\Macros\Macros\Carbon\FiscalYearForHumans::class,
        'startOfFiscalYear' => \Fls\Macros\Macros\Carbon\StartOfFiscalYear::class,
        'endOfFiscalYear' => \Fls\Macros\Macros\Carbon\EndOfFiscalYear::class,
        'isFiscalYear' => \Fls\Macros\Macros\Carbon\IsFiscalYear::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Illuminate\Support\Collection
    |--------------------------------------------------------------------------
    | oxford() required Coduo\Humanize package
    | composer require coduo/php-humanizer
    |
    */
    Collection::class => [
        // 'ofxord' => \Fls\Macros\Macros\Collection\Oxford::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Illuminate\Database\Eloquent\Factories\Factory Macros
    |--------------------------------------------------------------------------
    | Enabled by default
    |
    */
    Factory::class => [
        'empty' => \Fls\Macros\Macros\Factory\EmptyFactory::class,
    ],

    /*
    |--------------------------------------------------------------------------
    | Illuminate\Routing\Router Macros
    |--------------------------------------------------------------------------
    | livewireResource() is just a shortcut to have a resource with [index, create, show, edit] methods only
    | but if you want to install LiveWire
    | composer require livewire/livewire
    |
    */
    Router::class => [
        'livewireResource' => \Fls\Macros\Macros\Router\LiveResource::class,
    ],
];

Configuration structure is simple: root key is the name of the class you need to add the macro to and the array is the macros that are being added.

You will notice that some are commented out: the package does not insist you have those, and does tno silently pull them, to avoid surprises (with Dusk, for instance). As there is no need to pull extra packages when you dont need them - you should integrate them within your repo.

The list of packages is suggested in composer.json:

Integration

The package automatically registers with Laravel.

If you want to manually register it, add to your composer.json:

    "extra": {
        "laravel": {
            "dont-discover": [
                "frictionlessdigital/macros"
            ]
        }
    },

and add to config\app.php:

    'providers' => [
        /*
         * Package Service Providers...
         */
        Fls\Macros\MacrosServiceProvider::class,

Usage

The package offers extension for Builder, Carbon, Router, Collection and Dusk Browser.

\Carbon\Carbon Macros

fiscalYearForHumans($formatter=null) will get readable representation for the fiscal year.

$x = Carbon::now()->fiscalYearForHumans()
// $x = 'Fiscal year ending March 31, 2022'; 

fiscalYearForHumans accepts closure formatter:

$x = Carbon::now()->fiscalYearForHumans(fn($at) => new HtmlString('<b>'.$at->year.'</b>'));
// $x = HtmlString('<b>2022</b>'); 

startOfFiscalYear will modify the date to the start of the fiscal year

Carbon::startOfFiscalYear();
// Carbon instance at April 1, 2021 0:0:0; 

endOfFiscalYear will modify the date to the end of the fiscal year

Carbon::endOfFiscalYear();
// Carbon instance at March 31, 2022 25:59:59; 

isFiscalYear Will check if the date is within the provided (int) fiscal year

// assuming now is 
Carbon::parse('March 31, 2022')->isFiscalYear(2021);
// true
Carbon::parse('April 1, 2022')->isFiscalYear(2021);
// false

Laravel\Dusk\Browser Macros

*Requires Laravel Dusk:

composer require laravel/dusk
  • firstWindow() - to get the first window
  • lastWindow() - to get the last window
  • switchToFirstWindow() - switch Browser to the first window
  • switchTolastWindow() - switch Browser to the last window
  • windows() - get all current Browser windows

Illuminate\Database\Eloquent\Builder Macros

  • toSqlWithBindings - get the SQL from the builder, hydrated with values

Illuminate\Support\Collection Macros

Optionally, many need Coduo Humanizer, tested with version 4

composer require coduo/php-humanizer
  • oxford - list values with Ofxord coma.

Illuminate\Database\Eloquent\Factories\Factory Macros

  • empty() - will return a Factory where every value in definition is null

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email support@frictionlesssolutions.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

frictionlessdigital/macros 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-05