laravel-enso/helpers 问题修复 & 功能扩展

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

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

laravel-enso/helpers

Composer 安装命令:

composer require laravel-enso/helpers

包简介

Helper classes dependency for Laravel Enso

README 文档

README

License Stable Downloads PHP Issues Merge Requests

Description

Helpers is a shared utility package for the Laravel Enso ecosystem.

It bundles small reusable services, model traits, request helpers, casts, enums, contracts, and exceptions that are consumed by many backend packages. The package is intentionally broad: instead of modelling one business feature, it centralizes low-level building blocks that would otherwise be duplicated across the ecosystem.

Typical use cases include precise decimal arithmetic, monetary calculations, JSON parsing, factory resolution in package models, request key normalization, active-state handling, seeder progress reporting, and a few convenience enums and casts.

Installation

This package is usually installed transitively by other Enso backend packages.

For standalone installation:

composer require laravel-enso/helpers

No publishing step is required.

Features

  • Provides decimal-safe arithmetic helpers built on BCMath.
  • Includes utility services for JSON reading, object wrapping, disk-size formatting, loan rates, pricing, chunk sizing, and factory resolution.
  • Provides Eloquent and request traits for active state, request-key normalization, morph-map handling, observer cascading, and touch propagation.
  • Provides a relation-load guard trait for resources and serializers that must fail fast when expected Eloquent relations were not eager loaded.
  • Includes casts for encrypted strings and JSON-backed object payloads.
  • Ships helper enums for VAT rates and payment methods.
  • Provides ecosystem-level helper exceptions and a JSON-friendly EnsoException.
  • Exposes an Activatable contract used by packages that model is_active semantics.

Usage

Use Decimals for precise arithmetic:

use LaravelEnso\Helpers\Services\Decimals;

$gross = Decimals::add('100.25', '19.75');
$vat = Decimals::mul('100', '0.19', 4);

Use JsonReader to load JSON in different formats:

use LaravelEnso\Helpers\Services\JsonReader;

$data = (new JsonReader($path))->array();
$obj = (new JsonReader($path))->obj();

Use PriceComputor for pricing totals:

use LaravelEnso\Helpers\Services\PriceComputor;

$total = (new PriceComputor('100'))
    ->quantity('2')
    ->discountPercent('10')
    ->vatPercent('19')
    ->total();

Normalize request keys before validation with ToSnakeCase:

use Illuminate\Foundation\Http\FormRequest;
use LaravelEnso\Helpers\Traits\ToSnakeCase;

class StoreCompany extends FormRequest
{
    use ToSnakeCase;
}

ToSnakeCase rewrites nested array keys recursively, so frontend payloads may use camelCase while backend validation rules remain snake_case.

Guard required Eloquent relations before serializing relation-dependent payloads:

use Illuminate\Http\Resources\Json\JsonResource;
use LaravelEnso\Helpers\Traits\GuardRelationLoad;

class Project extends JsonResource
{
    use GuardRelationLoad;

    public function toArray($request): array
    {
        $flow = $this->guardRelationLoad($this->resource, 'flow');

        return [
            'flow' => $flow->name,
        ];
    }
}

The guard returns the loaded relation, so resources can use it directly after the load check.

Use Laravel's native validated input API to exclude validated fields:

$attributes = $request->safe()->except('roles');

Deprecated Traits

The following traits are kept for backwards compatibility only and should not be used in new code:

  • FiltersRequest; use $request->safe()->except(...).
  • MapsRequestKeys; use ToSnakeCase.
  • InCents; use explicit model casts, accessors, and mutators for monetary values.

API

Services

Core helpers:

  • Decimals
  • JsonReader
  • Obj
  • FactoryResolver
  • OptimalChunk
  • DiskSize

Financial helpers:

  • PriceComputor
  • Loan

Utility placeholder:

  • Dummy

Traits

Model traits:

  • ActiveState
  • AvoidsDeletionConflicts
  • CascadesMorphMap
  • CascadesObservers
  • ForceableIndex
  • GuardRelationLoad
  • InCents (deprecated)
  • UpdatesOnTouch

Request / validation traits:

  • FiltersRequest (deprecated)
  • MapsRequestKeys (deprecated)
  • ToSnakeCase
  • TransformMorphMap

Seeder traits:

  • SeederProgress
  • DatabaseSeedProgress

Casts

  • LaravelEnso\Helpers\Casts\Encrypt
  • LaravelEnso\Helpers\Casts\Obj

Enums

  • LaravelEnso\Helpers\Enums\PaymentMethods
  • LaravelEnso\Helpers\Enums\VatRates

Contracts

  • LaravelEnso\Helpers\Contracts\Activatable

Exceptions

  • LaravelEnso\Helpers\Exceptions\EnsoException
  • LaravelEnso\Helpers\Exceptions\InCents
  • LaravelEnso\Helpers\Exceptions\JsonParse

Depends On

Required Enso packages:

Framework and runtime dependencies:

Contributions

are welcome. Pull requests are great, but issues are good too.

Thank you to all the people who already contributed to Enso!

laravel-enso/helpers 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 102.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 10
  • 依赖项目数: 73
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 4
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-19