|
1 |
| -# ChileanRutPHP |
2 |
| -ChileanRutPHP |
| 1 | +# ChileanRut |
| 2 | + |
| 3 | +[![Latest Version on Packagist][ico-version]][link-packagist] |
| 4 | +[![Total Downloads][ico-downloads]][link-downloads] |
| 5 | +[![Build Status][ico-travis]][link-travis] |
| 6 | +[![StyleCI][ico-styleci]][link-styleci] |
| 7 | + |
| 8 | +A Chilean Rut script to handle ruts. Take a look at [contributing.md](contributing.md) to see a to do list. |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +Via Composer |
| 13 | + |
| 14 | +``` bash |
| 15 | +$ composer require innovaweb/chileanrut |
| 16 | +``` |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +### Format Function |
| 21 | +Format the rut according to the assigned parameters, if withDotted is true it will always return with a hyphen, return string value |
| 22 | + |
| 23 | +| Params | Type | Description | |
| 24 | +| --- | --- | --- | |
| 25 | +| $rut | string | rut with any of these formats 11.111.111-1, 11111111-1, 111111111 | |
| 26 | +| $withDotted | bool | return rut with dots format, default true | |
| 27 | +| $withHyphen | bool | return rut with hyphen format. default true | |
| 28 | +```php |
| 29 | +Rut::format('123123123'); // return 12.312.312-3 |
| 30 | +Rut::format('123123123', false); // return 12312312-3 |
| 31 | +Rut::format('123123123', false, false); // return 123123123 (it is best to use the unformat function) |
| 32 | +``` |
| 33 | + |
| 34 | +### Unformat Function |
| 35 | +Clean the rut of spaces, dots and hyphens, return string value |
| 36 | + |
| 37 | +| Params | Type | Description | |
| 38 | +| --- | --- | --- | |
| 39 | +| $rut | string | rut with any of these formats 11.111.111-1, 11111111-1, 111111111 | |
| 40 | + |
| 41 | +```php |
| 42 | +Rut::unformat('12.312.312-3'); // return 123123123 |
| 43 | +``` |
| 44 | + |
| 45 | +### Validate Function |
| 46 | +Check if the code is valid with the validation algorithm, return boolean value |
| 47 | + |
| 48 | +| Params | Type | Description | |
| 49 | +| --- | --- | --- | |
| 50 | +| $rut | string | rut with any of these formats 11.111.111-1, 11111111-1, 111111111 | |
| 51 | + |
| 52 | +```php |
| 53 | +Rut::validate('12.312.312-3'); // return true |
| 54 | +``` |
| 55 | + |
| 56 | +### Calculate Dv Function |
| 57 | +Calculates the check digit from a sequential rut number, return string value |
| 58 | + |
| 59 | +| Params | Type | Description | |
| 60 | +| --- | --- | --- | |
| 61 | +| $number | int | only the number of rut as integer type | |
| 62 | + |
| 63 | +```php |
| 64 | +Rut::calculateDv('12312312'); // return 3 |
| 65 | +``` |
| 66 | + |
| 67 | +### Get Number Function |
| 68 | +Extract the numerical part of the rut, can return with points according to the parameters, return string value |
| 69 | + |
| 70 | +| Params | Type | Description | |
| 71 | +| --- | --- | --- | |
| 72 | +| $rut | string | rut with any of these formats 11.111.111-1, 11111111-1, 111111111 | |
| 73 | +| $withDotted | bool | return rut with dots format, default true | |
| 74 | + |
| 75 | +```php |
| 76 | +Rut::getNumber('12312312-3'); // return 12312312 |
| 77 | +Rut::getNumber('12312312-3', true); // return 12.312.312 |
| 78 | +``` |
| 79 | + |
| 80 | + |
| 81 | +### Get Dv Function |
| 82 | +Extract the check digit part of the rut, return string value |
| 83 | + |
| 84 | +| Params | Type | Description | |
| 85 | +| --- | --- | --- | |
| 86 | +| $rut | string | rut with any of these formats 11.111.111-1, 11111111-1, 111111111 | |
| 87 | + |
| 88 | +```php |
| 89 | +Rut::getDv('12312312-3'); // return 3 |
| 90 | +``` |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +### Example |
| 96 | +````php |
| 97 | +namespace App\Http\Controllers; |
| 98 | + |
| 99 | +use Innovaweb\ChileanRut\Rut; |
| 100 | + |
| 101 | +class RutController extends Controller |
| 102 | +{ |
| 103 | + public function index() |
| 104 | + { |
| 105 | + $format = Rut::format('123123123'); |
| 106 | + $unformat = Rut::unformat($format); |
| 107 | + return [ |
| 108 | + $format, |
| 109 | + $unformat, |
| 110 | + Rut::validate($unformat), |
| 111 | + Rut::calculateDv(12312312), |
| 112 | + Rut::getNumber($format, false), |
| 113 | + Rut::getDv($format), |
| 114 | + ]; |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +```` |
| 119 | +Result |
| 120 | +```json |
| 121 | +[ |
| 122 | + "12.312.312-3", |
| 123 | + "123123123", |
| 124 | + true, |
| 125 | + "3", |
| 126 | + "12312312", |
| 127 | + "3" |
| 128 | +] |
| 129 | + |
| 130 | +``` |
| 131 | + |
| 132 | +## Change log |
| 133 | + |
| 134 | +Please see the [changelog](changelog.md) for more information on what has changed recently. |
| 135 | + |
| 136 | +## Testing |
| 137 | + |
| 138 | +``` bash |
| 139 | +$ composer test |
| 140 | +``` |
| 141 | + |
| 142 | +## Contributing |
| 143 | + |
| 144 | +Please see [contributing.md](contributing.md) for details and a todolist. |
| 145 | + |
| 146 | +## Security |
| 147 | + |
| 148 | +If you discover any security related issues, please email aisla@innovaweb.cl instead of using the issue tracker. |
| 149 | + |
| 150 | +## Credits |
| 151 | + |
| 152 | +- [Alejandro Isla][link-author] |
| 153 | +- [All Contributors][link-contributors] |
| 154 | + |
| 155 | +## License |
| 156 | + |
| 157 | +license. Please see the [license file](license.md) for more information. |
| 158 | + |
| 159 | +[ico-version]: https://img.shields.io/packagist/v/innovawebcl/chileanrut.svg?style=flat-square |
| 160 | + |
| 161 | +[ico-downloads]: https://img.shields.io/packagist/dt/innovawebcl/chileanrut.svg?style=flat-square |
| 162 | + |
| 163 | +[ico-travis]: https://img.shields.io/travis/innovawebcl/chileanrut/master.svg?style=flat-square |
| 164 | + |
| 165 | +[ico-styleci]: https://styleci.io/repos/12345678/shield |
| 166 | + |
| 167 | +[link-packagist]: https://packagist.org/packages/innovawebcl/chileanrut |
| 168 | + |
| 169 | +[link-downloads]: https://packagist.org/packages/innovawebcl/chileanrut |
| 170 | + |
| 171 | +[link-travis]: https://travis-ci.org/innovawebcl/chileanrut |
| 172 | + |
| 173 | +[link-styleci]: https://styleci.io/repos/12345678 |
| 174 | + |
| 175 | +[link-author]: https://github.com/innovawebcl |
| 176 | + |
| 177 | +[link-contributors]: ../../contributors |
0 commit comments