定制 aybarsm/laravel-extended-support 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

aybarsm/laravel-extended-support

Composer 安装命令:

composer require aybarsm/laravel-extended-support

包简介

Additional mixins for Laravel Macroable Facades and helpers

README 文档

README

It contains custom mixin classes for built-in macroable facades and also can be configured to load external mixins dynamically. It also includes some custom functions and helper traits.

Installation

You can install the package via composer:

composer require aybarsm/laravel-extended-support

You can publish the config file by:

php artisan vendor:publish --provider="Aybarsm\Laravel\Support\ExtendedSupportServiceProvider" --tag=config

Configure Mixins

You can remove or add new mixins to the load list and modify concretes by extending classes.

return [
    'runtime' => [
        'replace_existing' => true,
        'class_autoload' => true,
        'required_trait' => 'Illuminate\Support\Traits\Macroable',
        'bind_pattern' => '/@mixin\s*([^\s*]+)/',
        'load' => [
            Aybarsm\Laravel\Support\Mixins\StringableMixin::class,
            Aybarsm\Laravel\Support\Mixins\StrMixin::class,
            Aybarsm\Laravel\Support\Mixins\ArrMixin::class,
            Aybarsm\Laravel\Support\Mixins\FileMixin::class,
            Aybarsm\Laravel\Support\Mixins\RuleMixin::class,
            Aybarsm\Laravel\Support\Mixins\ApplicationMixin::class,
            Aybarsm\Laravel\Support\Mixins\CommandMixin::class,
            Aybarsm\Laravel\Support\Mixins\ProcessMixin::class,
            Aybarsm\Laravel\Support\Mixins\CollectionMixin::class,
        ],
    ],
    'concretes' => [
        'ExtendedSupport' => Aybarsm\Laravel\Support\ExtendedSupport::class,
        'Supplements' => [
            'Str' => [
                'SemVer' => Aybarsm\Laravel\Support\Supplements\Str\SemVer::class,
            ],
            'Foundation' => [
                'Annotation' => Aybarsm\Laravel\Support\Supplements\Foundation\Annotation::class,
            ],
        ],
    ],
];

Custom Mixins

You can create any new mixin by artisan command. The command will ask the class name and also provide the full list of classes that uses macroable trait to select easily or enter manually.

php artisan make:mixin ArrMixin

Make Mixin Command - Bind List Make Mixin Command - Bind Manual

You can publish the stubs by:

php artisan vendor:publish --provider="Aybarsm\Laravel\Support\ExtendedSupportServiceProvider" --tag=stubs

Or you can manually create a class for mixin and identify the macroable class by @mixin annotation and add it to configuration to be loaded:

<?php

namespace App\Mixins;

/** @mixin \Illuminate\Support\Arr */

class ArrMixin
{
    public static function toObject(): \Closure
    {
        return fn (array|object $arr, int $flags = JSON_NUMERIC_CHECK | JSON_FORCE_OBJECT): object => json_decode(json_encode($arr, $flags));
    }
}
'runtime' => [
        'load' => [
            Aybarsm\Laravel\Support\Mixins\StringableMixin::class,
            Aybarsm\Laravel\Support\Mixins\StrMixin::class,
            Aybarsm\Laravel\Support\Mixins\ArrMixin::class,
            Aybarsm\Laravel\Support\Mixins\FileMixin::class,
            Aybarsm\Laravel\Support\Mixins\RuleMixin::class,
            Aybarsm\Laravel\Support\Mixins\ApplicationMixin::class,
            Aybarsm\Laravel\Support\Mixins\CommandMixin::class,
            Aybarsm\Laravel\Support\Mixins\ProcessMixin::class,
            Aybarsm\Laravel\Support\Mixins\CollectionMixin::class,
            App\Mixins\ArrMixin::class,
        ],
    ],
];

Supplements

Str :: Semantic Version

New Semantic Versioning helper class added. You can create a new SemVer instance directly or with macro Str::semVer() function. SemVer class is macroable too.

use Aybarsm\Laravel\Support\Supplements\Str\SemVer;
use Aybarsm\Laravel\Support\Enums\SemVerScope;

// Regardless of multiple occurrences, the function always captures the first occurrence of \d+\.\d+\.\d+
$version = 'ver9.2.78beta-1.0.6';
$semVer = new SemVer($version);
$semVer = Str::semVer($version);

// Get scope of the Semantic Version:
dump($semVer->getScope(SemVerScope::MINOR)); // Output: "2"
dump($semVer->getScope(SemVerScope::MINOR, $asInteger = true)); // Output: 2

// More importantly you can easily calculate the next scopes of the Semantic Version.
dump($semVer->value()); // Output: "9.2.78"
$semVer = $semVer->next(SemVerScope::MINOR);
dump($semVer->value()); // Output: "9.3.0"
$semVer = $semVer->next(SemVerScope::PATCH);
dump($semVer->value()); // Output: "9.3.1"
$semVer = $semVer->next(SemVerScope::MAJOR);
dump($semVer->value()); // Output: "10.0.0"

// You can access the original Semantic Version by:
dump($semVer->getOriginal()); // Output: "9.2.78"

// If you would like to have an output with t original version structure
dump($semVer->value($asOriginal = true)); // Output: "ver10.0.0beta-1.0.6"

// Lastly, static function and Str macros have been implemented to validate Semantic Version string.
SemVer::validate('9.2.78'); // Output: true
// OR
Str::isSemVer('9.2'); // Output: false

Helper Traits:

EnumHelper:

use Aybarsm\Laravel\Support\Traits\EnumHelper;

enum ProcessReturnType: int
{
    use EnumHelper;
    
    case STATUS = 0;
    case SUCCESSFUL = 1;
    case FAILED = 2;
    case EXIT_CODE = 3;
    case OUTPUT = 4;
    case ERROR_OUTPUT = 5;
    case INSTANCE = 6;
    case ALL_OUTPUT = 7;
}

$enum = ProcessReturnType::tryFrom(ProcessReturnType::byName('EXIT_CODE')); //returns designated enum as static

aybarsm/laravel-extended-support 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-31