Download the PHP package eram/abzar without Composer
On this page you can find all versions of the php package eram/abzar. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package abzar
Short Description Zero-runtime-dependency Persian (Farsi) utility toolkit for PHP 8.1+: validators (national ID, IBAN, bank card, phone), formatters (number-to-words, time-ago, ordinals), text utilities (slug, script detection, char normalization), and digit conversion.
License MIT
Homepage https://github.com/eramhq/abzar-php
Informations about the package abzar
Abzar
Zero-runtime-dependency Persian (Farsi) utility toolkit for PHP 8.1+.
Abzar (ابزار, "tool") is a pure-PHP library covering the small but opinionated set of utilities every Persian-language application ends up reimplementing: national-ID / IBAN / bank-card / phone validation, number-to-words and time-ago formatting, Persian slug generation, script detection, and digit conversion between Persian, Arabic, and English.
No framework coupling, no runtime extensions beyond stock PHP, no transitive Composer dependencies.
Messages and error codes. Persian error messages are byte-identical to the upstream data. For language-neutral error handling, every validator failure also emits a machine-readable
ErrorCode:Error-code values are stable API surface as of
0.3— renaming a case is a breaking change.Exception hierarchy. Every thrown exception extends
Eram\Abzar\Exception\AbzarException(abstract; carrieserrorCode(): ErrorCode). Three concrete subclasses:ValidationException(thrown by::from()),FormatException(thrown by formatters), andEnvironmentException(thrown when an optional extension likeext-intlis missing at runtime). Catch the base to handle every library failure uniformly.
Feature matrix
| Namespace | Class | What it does |
|---|---|---|
Validation |
NationalId |
Iranian national-ID checksum + city / province lookup |
Validation |
LegalId |
11-digit Iranian legal-entity ID checksum |
Validation |
PhoneNumber |
Iranian mobile + landline number validation, operator / area-code detection (09xx, +98, 0098, 98) |
Validation |
CardNumber |
16-digit bank card Luhn check + bank name from BIN |
Validation |
Iban |
IR-prefixed IBAN mod-97 check + bank lookup |
Validation |
PostalCode |
10-digit Iranian postal code validator |
Validation |
BillId |
شناسه قبض / شناسه پرداخت mod-11 pair validator with bill-type decoding |
Validation |
PlateNumber |
Iranian license plate (NN[letter]NNN-NN) parser with letter-derived type + province lookup |
Validation |
ErrorCode |
Stable DOMAIN.REASON codes emitted by every validator + format exception |
Validation |
Bank / Operator / Province / PlateType |
Typed enums with fromPersian() lookup and Arabic-char-tolerant matching |
Validation |
ValidationResult |
Shared {isValid, errors, errorCodes, warnings, detail} return type (implements JsonSerializable / Stringable) |
Validation\Details |
ValidationDetail |
Marker interface for the per-validator readonly DTOs returned from ValidationResult::detail() |
Format |
NumberFormatter |
Thousands-separator formatter with digit normalization |
Format |
NumberToWords |
Integer / float to Persian words (۱۲۳۴ → یک هزار و دویست و سی و چهار) |
Format |
WordsToNumber |
Parse Persian number words back to int / float |
Format |
OrdinalNumber |
Persian ordinals: toWord(3) → سوم, toShort(43) → ۴۳ام |
Format |
TimeAgo |
Fuzzy relative time in Persian (۵ دقیقه پیش, حدود ۳ روز پیش) |
Money |
Amount |
Immutable Iranian-currency value object; stores rials internally, factories / accessors for both units |
Money |
Currency / Unit |
Toman / Rial formatter and ×10 / ÷10 converter |
Text |
Script |
isPersian / hasPersian / isArabic / hasArabic detectors |
Text |
Slug |
Persian-aware slug (سلام دنیا → سلام-دنیا) |
Text |
CharNormalizer |
Arabic → Persian char + digit normalization, HTML-aware normalizeContent(), opt-in hamza / tashkeel / kashida / NFC flags |
Text |
KeyboardFixer |
Swap between English QWERTY and Persian keyboard layouts, with a detect() heuristic |
Text |
PersianCollator |
ext-intl-backed fa_IR collator with sort / sortBy helpers |
Text |
HalfSpaceFixer |
Best-effort zero-width-non-joiner placement for compound-word affixes (میروم, خانهها, بزرگترین) |
Digits |
DigitConverter |
toPersian / toEnglish / toArabic + HTML-aware convertContent() |
Install
Requires PHP 8.1+. No runtime extensions beyond mbstring.
Quick examples
Validation
Three entry points per validator (same pattern as BackedEnum), ordered by how most apps use them:
isValid()vsisStrictlyValid().validate()can returntruewith a non-fatal warning when the input parses cleanly but an optional lookup fails (unknown card BIN, unknown mobile-operator prefix).isValid()does not reject these. For strict acceptance — form submissions, payment flows — usefrom()/tryFrom()(which reject warning-bearing results) or callisStrictlyValid()explicitly. The warning path is documented per validator underdocs/en/.
Formatting
Money
Text
Digits
Plate numbers
Display formatters
Fixtures and extraction
Persian collation and half-space fixing
Further reading
Longer-form docs live under API stability policy, async-runtime notes, and framework integration recipes.
Related packages
Abzar deliberately stays narrow. Two companion packages cover adjacent ground:
eramhq/daynum— jalali / shamsi calendar utilities. Abzar does not ship calendar logic; install daynum for anything date-related.eramhq/persian-kit— WordPress plugin that wires abzar into WP hooks (the_content,sanitize_title,pre_get_posts), adds admin tools for one-shot database normalization, and exposes shortcodes / blocks.
See docs/en/related.md for a longer comparison.
Versus other Persian PHP libraries
| abzar | persian-tools (JS) | nikapps/iran-validator | |
|---|---|---|---|
| Language | PHP 8.1+ | JS/TS | PHP 7.4+ |
| Zero runtime deps | Yes | — | Yes |
Typed result object (isValid/errors/details) |
Yes | Partial | No (bool only) |
JsonSerializable result |
Yes | n/a | No |
| Structured error codes | Yes | No | No |
| Bank card / IBAN / phone / national-ID / legal-ID | Yes | Yes | Subset |
| Number-to-words / time-ago / ordinals | Yes | Yes | No |
| Slug / char normalize / digit convert | Yes | Partial | No |
| WordPress integration | Via eramhq/persian-kit |
No | No |
Framework bridges
Abzar stays framework-agnostic. Integration recipes for Laravel FormRequest, Symfony Validator, Symfony Console, and WordPress live under docs/en/recipes/. Each is a few dozen lines — paste into your project and tweak.
Stability
Abzar is in 0.x. Breaking changes may happen before 1.0; pin with ^0.5@beta until the API stabilizes. The API stability policy spells out which parts of the surface are protected — ErrorCode values are pinned as stable API as of 0.3.
License
MIT. See persian-tools project.
All versions of abzar with dependencies
ext-mbstring Version *