uniqby / yii2-phone-formatter
Phone numbers formatter and behavior for Yii2 Framework
Installs: 13 229
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- giggsey/libphonenumber-for-php: ~7.0
- yiisoft/yii2: 2.*
- yiisoft/yii2-composer: 2.*
This package is not auto-updated.
Last update: 2024-10-26 19:00:01 UTC
README
Phone numbers formatter and behavior for Yii2 Framework
Composer
The preferred way to install this extension is through Composer.
Either run
php composer.phar require uniqby/yii2-phone-formatter "dev-master"
or add
"uniqby/yii2-phone-formatter": "dev-master"
to the require section of your composer.json
Configuration
Configure your application in common config:
'components' => [ 'formatter' => [ 'class' => 'uniqby\phoneFormatter\i18n\Formatter', ] ]
Now you can use asPhoneE164 and asPhoneInt methods
echo \Yii::$app->formatter->asPhoneE164( '+375259862464', 'BY' ); echo \Yii::$app->formatter->asPhoneInt( '+375 25 986-24-64', 'BY' );
Behavior
You can add behavior to your models
/** * @inheritdoc */ public function behaviors() { return [ 'convertPhone' => [ 'class' => PhoneFormatterBehavior::className(), 'attributes' => [ 'number' ] ] ]; }