Phone numbers formatter and behavior for Yii2 Framework
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
'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'
);
You can add behavior to your models
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'convertPhone' => [
'class' => PhoneFormatterBehavior::className(),
'attributes' => [
'number'
]
]
];
}