Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/igorsantos07/yii-br-pack
https://github.com/igorsantos07/yii-br-pack
Last synced: about 5 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/igorsantos07/yii-br-pack
- Owner: igorsantos07
- License: bsd-3-clause
- Created: 2014-07-10T06:06:24.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-26T13:20:26.000Z (almost 10 years ago)
- Last Synced: 2024-04-14T22:56:10.627Z (7 months ago)
- Language: PHP
- Size: 189 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Yii Brazilian Package
=====================Yii 1.1 Extension that provides various helpers for Brazilian localization.
* Validators:
- CPF: Cadastro de Pessoa Física (like a Security Social Number in USA)
- CNPJ: Cadastro Nacional de Pessoa Jurídica
- landlines: beginning with 2 and 3
- cellphones: 9 digits or 8 digits beginning with 7, 8 or 9
* Fields:
- CPF and CNPJ
- Polymorphic credit card field - given the name it turns into a PAN, CVV or Expiry field
- Phone - landline, mobile, both, or area code only
* Formatter:
- CPF
- Phone with area code
- Money (alias of `NumberFormatter::formatCurrency()` which defaults to BRLInstallation
------------The preferred way to install this extension is through [Composer](http://getcomposer.org/download/).
[![Latest Stable Version](https://poser.pugx.org/igorsantos07/yii-br-pack/v/stable.svg)](https://packagist.org/packages/igorsantos07/yii-br-pack)
[![Total Downloads](https://poser.pugx.org/igorsantos07/yii-br-pack/downloads.svg)](https://packagist.org/packages/igorsantos07/yii-br-pack)Either run this:
```
php composer.phar require --prefer-dist igorsantos07/yii-br-pack:1.*
```or add this to the "require" section of your `composer.json` file.
```
"igorsantos07/yii-br-pack": "1.*"
```Usage
-----Add the rules as the following example:
> models/PersonForm.php
```php
class PersonForm extends CModel {public $name;
public $cpf;
public $cnpj;
public $cellphone;
public $landline;
public $phone;
public $areaCode;public $card_number;
public $card_cvv;
public $card_expiry;public function rules() {
// Using short array notation but the class is PHP <5.4 compatible ;)
return [
// CPF validator
['cpf', 'BrPack\Validator\Cpf'],
// CNPJ validator
['cnpj', 'BrPack\Validator\Cnpj'],
// Cellphone-only validator, checking area code inside the field
['cellphone', 'BrPack\Validator\Phone', 'type' => PhoneValidator::TYPE_CELLPHONE],
// Cellphone-only validator, not validating area code
[
'cellphone',
'BrPack\Validator\Phone',
'type' => BrPack\Validator\Phone::TYPE_CELLPHONE,
'areaCode' => false
],
// Landline-only validator
['landline', 'BrPack\Validator\Phone', 'type' => BrPack\Validator\Phone::TYPE_LANDLINE],
// Any phone validator - cellphone or landline
['phone', 'BrPack\Validator\Phone'],
// Cellphone validator with external area code check
[
'cellphone',
'BrPack\Validator\Phone',
'type' => BrPack\Validator\Phone::TYPE_CELLPHONE,
'areaCodeAttribute' => 'areaCode'
],
];
}
}
```> views/person/edit.php
```php
beginWidget('CActiveForm, ['id' => 'my-person-form']) ?>=$form->label($model, 'name')?>
=$form->textField($model, 'name')?>
=$form->error($model, 'name')?>
Current document: =Yii::app()->format->cpf('12365487588')?> // 123.654.875-88
=$form->label($model, 'cpf')?>
widget('BrPack\Field\Cpf', ['model' => $model, 'attribute' => 'cpf']) ?>
=$form->error($model, 'cpf')?>
Current phone: =Yii::app()->format->phone('21996543354')?> // (21) 99654-3354
=$form->label($model, 'cellphone')?>
widget('BrPack\Field\Phone', ['model' => $model, 'attribute' => 'cellphone', 'type' => 'mobile']) ?>
=$form->error($model, 'cpf')?>
=$form->label($model, 'card_number')?>
widget('BrPack\Field\Card', ['model' => $model, 'attribute' => 'card_number']) ?>
widget('BrPack\Field\Card', ['model' => $model, 'attribute' => 'card_expiry']) ?>
widget('BrPack\Field\Card', ['model' => $model, 'attribute' => 'card_cvv']) ?>
=$form->error($model, 'card_number')?>
=$form->error($model, 'card_expiry')?>
=$form->error($model, 'card_cvv')?>Amount to be charged in your card: =Yii::app()->format->money(9.99)?> // R$9,99
=CHtml::submitButton()?>
endWidget() ?>
```