meita/journal-guard
Composer 安装命令:
composer require meita/journal-guard
包简介
Guard and validate journal entries before they are posted to the ledger.
README 文档
README
Guard and validate journal entries before they are posted to the ledger. Built for Laravel 10/11/12 with extensible rule classes and clear, human-readable errors.
Installation
composer require meita/journal-guard
php artisan vendor:publish --provider="Meita\\JournalGuard\\JournalGuardServiceProvider" --tag=config
Configuration
config/journal-guard.php ships with:
enabled: toggle the guard.mode:strict(throws) orwarning(returns warnings, no throw).rules: ordered list of rule classes.account_model,period_model,currency_model: optional model classes for built-in rules.resolvers.account|period|currency: optional callbacks to resolve accounts/periods/currency without coupling to models.default_currency,enforce_default_currency: enforce default currency when needed.
Example resolver registration:
app('config')->set('journal-guard.resolvers.account', function ($line, $entry) { // return model/array/bool to indicate active account return $line->accountId() === 100 ? (object) ['is_active' => true] : null; });
Usage
Validating a payload
use Meita\JournalGuard\Facades\JournalGuard; use Meita\JournalGuard\Exceptions\JournalValidationException; $payload = [ 'company_id' => 1, 'branch_id' => 2, 'currency' => 'SAR', 'entry_date' => '2024-01-31', 'reference' => 'JV-1001', 'description' => 'Accruals', 'lines' => [ ['account_id' => 10, 'debit' => 1000, 'credit' => 0, 'description' => 'Expense'], ['account_id' => 200, 'debit' => 0, 'credit' => 1000, 'description' => 'Accrual'], ], ]; try { $result = JournalGuard::validate($payload); // returns ValidationResult on success } catch (JournalValidationException $e) { // $e->errors() holds code/message/path tuples }
Warning mode
config(['journal-guard.mode' => 'warning']); $result = JournalGuard::validate($payload); if (!$result->passed()) { // $result->warnings() contains non-blocking issues }
Trait for services
use Meita\JournalGuard\Traits\GuardsJournalEntries; class JournalEntryService { use GuardsJournalEntries; public function create(array $payload) { $this->guardJournalEntry($payload); // ...persist entry } }
Custom rules
Create a rule implementing Meita\JournalGuard\Contracts\RuleInterface and add it to the rules config array.
use Meita\JournalGuard\Contracts\RuleInterface; use Meita\JournalGuard\DTO\JournalEntryDTO; use Meita\JournalGuard\Exceptions\JournalValidationException; class NoWeekendEntriesRule implements RuleInterface { public function validate(JournalEntryDTO $entry): void { if ($entry->date()->isWeekend()) { throw new JournalValidationException([ ['code' => 'weekend_block', 'message' => 'Weekend entries are not allowed.', 'path' => 'entry_date'], ]); } } }
Middleware-like usage
public function store(Request $request) { try { JournalGuard::validate($request->all()); } catch (JournalValidationException $e) { return back()->withErrors($e->errors()); } // continue to save... }
Built-in rules
- BalancedRule: total debit equals total credit; totals must be > 0.
- PositiveAmountsRule: no negatives, no line with both debit and credit, no empty amounts.
- AccountsActiveRule: accounts exist and are active (via resolver or configured model).
- ClosedPeriodRule: entry date falls within an open period (resolver or model).
- CurrencyRule: currency allowed for the company and default currency enforcement.
Events
JournalValidatingJournalValidatedJournalRejected
Hook into these with Laravel's event listeners to log, audit, or instrument validation.
meita/journal-guard 适用场景与选型建议
meita/journal-guard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 meita/journal-guard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 meita/journal-guard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-21