Installation & Quick Start
Requirements
Section titled “Requirements”- PHP 8.2 or higher
- Composer
Installation
Section titled “Installation”-
Require the package
Terminal window composer require slashlab/numerik -
No configuration needed
The package is autoloaded via PSR-4. There is no service provider, config file, or bootstrap step for the core library.
-
Use it
use SlashLab\Numerik\Numerik;Numerik::pesel()->isValid('92060512186'); // true
Quick start
Section titled “Quick start”Boolean validation
Section titled “Boolean validation”The simplest entry point — returns true or false.
use SlashLab\Numerik\Numerik;
Numerik::pesel()->isValid('92060512186'); // trueNumerik::nip()->isValid('5260250274'); // trueNumerik::regon()->isValid('691761365'); // trueNumerik::krs()->isValid('0000127206'); // trueRich validation result
Section titled “Rich validation result”validate() never throws. It returns a ValidationResult that carries the list of failures when validation does not pass.
use SlashLab\Numerik\Numerik;
$result = Numerik::pesel()->validate('92060512186');$result->isValid; // true$result->failures; // []
$result = Numerik::pesel()->validate('00000000000');$result->isFailed(); // true$result->getFirstFailure()->reason->value; // 'all_zeros'$result->getFirstFailure()->message; // human-readable messageSee Validation Results for the full API.
Parsing to a value object
Section titled “Parsing to a value object”parse() validates the input and, on success, returns a rich value object. It throws a ValidationException on failure.
use SlashLab\Numerik\Numerik;
$pesel = Numerik::pesel()->parse('92060512186');$pesel->getBirthDate()->format('Y-m-d'); // '1992-06-05'$pesel->getGender(); // Gender::Female$pesel->getAge(); // int — calculated from today$pesel->isAdult(); // trueUse tryParse() when you prefer null on failure instead of an exception:
$pesel = Numerik::pesel()->tryParse('bad-input'); // nullChoosing the right method
Section titled “Choosing the right method”| Method | Returns | Throws | Use when |
|---|---|---|---|
isValid() | bool | never | Simple existence check |
validate() | ValidationResult | never | You need the failure reason |
parse() | value object | ValidationException | You need extracted data and want exceptions |
tryParse() | value object or null | never | You need extracted data but prefer null over exceptions |
Next steps
Section titled “Next steps”- Browse the PESEL, NIP, REGON, or KRS reference for full method listings.
- Read Error Handling to understand the exception hierarchy.
- Read Validation Results for the complete
ValidationResultAPI.
If this saved you time → ☕ Buy me a coffee