alpixel / phoneformatterbundle
提供方便格式化电话号码的助手
v1.0
2016-10-24 16:17 UTC
Requires
- php: >=5.4.0
- giggsey/libphonenumber-for-php: ^7.7
- symfony/symfony: ~2.8|~3.0
This package is not auto-updated.
Last update: 2024-09-14 20:04:05 UTC
README
安装
- 安装包
composer require 'alpixel/phoneformatterbundle'
- 更新AppKernel.php
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Alpixel\Bundle\PhoneFormatterBundle\AlpixelPhoneFormatterBundle(),
);
// ...
}
// ...
}
使用
助手
实际上可用的唯一助手允许您根据模式重新格式化和清理电话号码。
您可以通过以下方式调用助手
$number = $this->get('alpixel.helper.phone_formatter')->format($currentNumber, PhoneNumberFormat::NATIONAL, 'DE');
上面的示例将尝试从您提供的输入输出一个国家德语号码。
格式选项可以是
AlpixelPhoneNumberFormat::INTERNATIONAL // example "+41 44 668 18 00"
AlpixelPhoneNumberFormat::NATIONAL // example : "044 668 18 00"
AlpixelPhoneNumberFormat::E164 // example : "+41446681800"
AlpixelPhoneNumberFormat::AUTO // Will try to make the best guess from your current locale
第三个参数期望一个两位字母的国家代码,例如FR或DE
Twig扩展
助手可以通过一个像这样的twig扩展来调用
"03 03 03 03 03"|phone_format("INTERNATIONAL", "FR")
"03 03 03 03 03"|phone_format("NATIONAL")
"03 03 03 03 03"|phone_format("AUTO", "CH")