Skip to content

Installation & Quick Start

  • PHP 8.2 or higher
  • Composer
  1. Require the package

    Terminal window
    composer require slashlab/numerik
  2. No configuration needed

    The package is autoloaded via PSR-4. There is no service provider, config file, or bootstrap step for the core library.

  3. Use it

    use SlashLab\Numerik\Numerik;
    Numerik::pesel()->isValid('92060512186'); // true

The simplest entry point — returns true or false.

use SlashLab\Numerik\Numerik;
Numerik::pesel()->isValid('92060512186'); // true
Numerik::nip()->isValid('5260250274'); // true
Numerik::regon()->isValid('691761365'); // true
Numerik::krs()->isValid('0000127206'); // true

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 message

See Validation Results for the full API.

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(); // true

Use tryParse() when you prefer null on failure instead of an exception:

$pesel = Numerik::pesel()->tryParse('bad-input'); // null
MethodReturnsThrowsUse when
isValid()boolneverSimple existence check
validate()ValidationResultneverYou need the failure reason
parse()value objectValidationExceptionYou need extracted data and want exceptions
tryParse()value object or nullneverYou need extracted data but prefer null over exceptions
If this saved you time → ☕ Buy me a coffee