tifon/rut-php

1.0.0 2015-07-16 23:48 UTC

This package is not auto-updated.

Last update: 2024-10-26 18:54:37 UTC


README

This library contain two simples class to provide you helpers methods to work with rut.

Build Status

Installation

Using Composer just add a dependency on tifon/rut-php to your project's composer.json file. Here is an example:

{
    "require": {
        "tifon/rut-php": "1.0.*"
    }
}

Usage Util

Validate a Rut.

<?php
use Tifon\Rut\RutUtil;

RutUtil::validateRut('11.111.111-1');
// Or
RutUtil::validateRut(11111111, 1);

Generate random Rut.

<?php
use Tifon\Rut\RutUtil;

$randomRutWithFormatter = RutUtil::generateRut();
// Generate rut between 1000000 and 2000000 and separate the check digit.
list($rut, $dv) = RutUtil::generateRut(FALSE, 1000000, 2000000);

Formatting a Rut.

<?php
use Tifon\Rut\RutUtil;

$rut = RutUtil::formatterRut(111111111);
// 11.111.111-1

// Or
$rut = RutUtil::formatterRut(11111111, 1, FALSE);
// 11111111-1

Separate the check digit from the Rut.

<?php
use Tifon\Rut\RutUtil;

list($rut, $dv) = RutUtil::separateRut('11.111.111-1');

Usage Rut

<?php
use Tifon\Rut\Rut;

$rut = new Rut('11.111.111-1');
// Or
$rut = new Rut(11111111, 1);

echo $rut->getRut();
// 11111111
echo $rut->getDv();
// 1
echo $rut->getFormatter();
// 11.111.111-1
echo $rut->getRaw();
// 111111111
echo $rut->isValid();
// 1