uniqby/yii2-phone-formatter

Phone numbers formatter and behavior for Yii2 Framework

0.2.1 2016-04-06 07:24 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:07:10 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'
            ]
        ]
    ];
}