jn-devops/common
最新稳定版本:v1.5.95
Composer 安装命令:
composer require jn-devops/common
包简介
Homeful Common Package
README 文档
README
The Homeful\Common package is a utility package that contains reusable helpers, constants, enumerations, and abstract types used across the Homeful system. It aims to promote consistency and reduce duplication of logic in other domain-specific packages such as Mortgage, Payment, Property, and Borrower.
📦 Contents
- Utilities
- Classes
- Enumerations
🧰 Utilities
documents_path(?string $path = null): string
Returns the path to the /resources/documents directory.
documents_path(); // /resources/documents documents_path('legal/contract.pdf'); // /resources/documents/legal/contract.pdf
formatted_age(DateTime $born, ?DateTime $reference = null): string
Returns a human-readable age string based on birthdate.
formatted_age(new DateTime('1990-05-23')); // "33 years, 10 months and 3 days old"
doc_stamps(mixed $value): float
Returns the documentary stamp fee based on property value.
doc_stamps(450000); // 50.0
filter_trim_recursive_array(array $array): array
Trims strings and filters empty values recursively in nested arrays.
dot_shift(&$dot_notation): string
Shifts off the first key in a dot notation string.
$key = dot_shift($dot = "property.name"); // $key = "property", $dot = "name"
titleCase(?string $text, array $exclusions = []): string
Applies Str::title() but preserves Roman numerals and exceptions.
titleCase('juan dela cruz ii'); // Juan Dela Cruz II
validateJson(string $json): bool
Returns true if a valid JSON string.
resolveOptionalCollection(DataCollection|Optional|null $collection): Collection
Handles resolution of Spatie DataCollection and Optional.
array_when(array $array, $condition, callable $callback): array
Conditionally apply a transformation on an array.
array_when([1,2,3], false, fn($arr) => array_map(fn($x) => $x * 2, $arr)); // [1,2,3]
convertNumberToWords(float $value): string
Converts a float value to words.
convertNumberToWords(1500.75); // ONE THOUSAND FIVE HUNDRED AND 75/100
📚 Core Classes
Homeful\Common\Classes\Input
A collection of constants used for data keys in form input and parameter arrays. Examples include:
Input::TCP- Total Contract PriceInput::PERCENT_DP- Percent Down PaymentInput::BP_TERM- Balance Payment Term
Usage:
$params = [ Input::TCP => 2500000, Input::PERCENT_DP => 0.05, ];
Homeful\Common\Classes\Assert
A collection of constants used to assert derived or calculated values in computations:
Assert::LOAN_AMOUNTAssert::INCOME_REQUIREMENTAssert::LOAN_AMORTIZATION
Used commonly in unit tests:
expect($mortgage->getLoan()->getPrincipal()->inclusive()->compareTo($params[Assert::LOAN_AMOUNT]))->toBe(Amount::EQUAL);
🧮 AmountCollectionItem
Base class representing any item with:
- a name
- a
Pricevalue - deductible flag
- a tag
Used as a base for:
AddOnFeeToPaymentDeductibleFeeFromPayment
📈 Enumerations
UploadFile
Maps file-related attributes to suffixes for Media Library collections.
UploadFile::Image->suffix(); // 'images' UploadFile::deriveCollectionNameFromAttribute('propertyImage'); // 'property-images'
WorkArea
Represents whether a user operates in a Highly Urbanized City or Region.
WorkArea::fromRegional(true); // WorkArea::REGION WorkArea::default(); // WorkArea::HUC
✅ Example Usage
use Homeful\Common\Classes\Input; use Homeful\Common\Classes\Assert; $params = [ Input::TCP => 2500000, Input::PERCENT_DP => 0.05, Assert::LOAN_AMOUNT => 2375000.0, ]; expect($params[Assert::LOAN_AMOUNT])->toBe(2375000.0);
📂 Path Resolution
documents_path('mortgage/terms.pdf'); // => /resources/documents/mortgage/terms.pdf
🧪 Testing Helpers
Used extensively in test scripts to:
- Assert expected results via
Assert - Pass parameters using
Input - Use
formatted_age,doc_stamps, etc.
Behold, a new you awaits. ✨
jn-devops/common 适用场景与选型建议
jn-devops/common 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「common」 「laravel」 「Homeful」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jn-devops/common 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jn-devops/common 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jn-devops/common 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides common functionality and classes for Serenata.
Homeful Property Package
Homeful Contacts Package
Homeful Borrower Package
Homeful Payment Package
Homeful Products Package
统计信息
- 总下载量: 9k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-12