Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alexeevdv/yii2-kz-personalid

Yii2 extension to deal with Kazakhstan individual identification number
https://github.com/alexeevdv/yii2-kz-personalid

kz personalidentity validator yii2 yii2-extension

Last synced: about 1 month ago
JSON representation

Yii2 extension to deal with Kazakhstan individual identification number

Awesome Lists containing this project

README

        

yii2-kz-personalid
===========

[![Build Status](https://travis-ci.org/alexeevdv/yii2-kz-personalid.svg?branch=master)](https://travis-ci.org/alexeevdv/yii2-kz-personalid)
[![codecov](https://codecov.io/gh/alexeevdv/yii2-kz-personalid/branch/master/graph/badge.svg)](https://codecov.io/gh/alexeevdv/yii2-kz-personalid)
![PHP 5.6](https://img.shields.io/badge/PHP-5.6-green.svg)
![PHP 7.0](https://img.shields.io/badge/PHP-7.0-green.svg)
![PHP 7.1](https://img.shields.io/badge/PHP-7.1-green.svg)
![PHP 7.2](https://img.shields.io/badge/PHP-7.2-green.svg)

Yii2 extension to deal with [Kazakhstan personal identification number](https://ru.wikipedia.org/wiki/%D0%98%D0%BD%D0%B4%D0%B8%D0%B2%D0%B8%D0%B4%D1%83%D0%B0%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9_%D0%B8%D0%B4%D0%B5%D0%BD%D1%82%D0%B8%D1%84%D0%B8%D0%BA%D0%B0%D1%86%D0%B8%D0%BE%D0%BD%D0%BD%D1%8B%D0%B9_%D0%BD%D0%BE%D0%BC%D0%B5%D1%80)

It contains:
- Both server-side and client-side validators
- Helper to fetch data from identification number

## Installation

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ php composer.phar require alexeevdv/yii2-kz-personalid "~1.0"
```

or add

```
"alexeevdv/yii2-kz-personalid": "~1.0"
```

to the ```require``` section of your `composer.json` file.

## Usage

### Validation

#### As standalone validator

```php
use alexeevdv\kz\PersonalidValidator;

//...
$validator = new PersonalidValidator;
$result = $validator->validateValue('123456789012');
//...
```

### In model

```php
use alexeevdv\kz\PersonalidValidator;

public function rules()
{
//...
['personalid', PersonalidValidator::class, 'message' => 'Wrong personalid value!'],
//...
}
```

### Helper

```php
use alexeevdv\kz\PersonalidHelper;

$personalid = '850407301166';

/** @var \DateTime $birtdate = 1985-04-07 */
$birtdate = PersonalidHelper::getBirthDate($personalid);

/** @var int $sex = PersonalidHelper::SEX_MALE */
$sex = PersonalidHelper::getSex($personalid);

/** @var string $serialNumber = 0116 */
$serialNumber = PersonalidHelper::getSerialNumber($personalid);
```