{"id":14983939,"url":"https://github.com/misd-service-development/phone-number-bundle","last_synced_at":"2025-05-15T02:07:46.937Z","repository":{"id":443652,"uuid":"10194913","full_name":"misd-service-development/phone-number-bundle","owner":"misd-service-development","description":"Integrates libphonenumber into your Symfony2-Symfony4 application","archived":false,"fork":false,"pushed_at":"2023-12-06T16:00:36.000Z","size":208,"stargazers_count":456,"open_issues_count":60,"forks_count":142,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-04-13T23:55:36.960Z","etag":null,"topics":["bundle","libphonenumber","php","symfony","symfony-bundle","twig-extension"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/misd-service-development.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2013-05-21T12:20:58.000Z","updated_at":"2025-03-29T06:35:19.000Z","dependencies_parsed_at":"2024-04-10T09:46:55.283Z","dependency_job_id":"641f4476-b1ac-4b22-8594-b43f918e3d1b","html_url":"https://github.com/misd-service-development/phone-number-bundle","commit_stats":{"total_commits":181,"total_committers":36,"mean_commits":5.027777777777778,"dds":0.4696132596685083,"last_synced_commit":"b465992f8303bb7f9b64406427658cefef266233"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misd-service-development%2Fphone-number-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misd-service-development%2Fphone-number-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misd-service-development%2Fphone-number-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misd-service-development%2Fphone-number-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/misd-service-development","download_url":"https://codeload.github.com/misd-service-development/phone-number-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254259383,"owners_count":22040820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bundle","libphonenumber","php","symfony","symfony-bundle","twig-extension"],"created_at":"2024-09-24T14:08:12.573Z","updated_at":"2025-05-15T02:07:46.916Z","avatar_url":"https://github.com/misd-service-development.png","language":"PHP","funding_links":[],"categories":["PHP","Miscellaneous"],"sub_categories":[],"readme":"PhoneNumberBundle\n=================\n\nThis package has been abandoned in favour of [odolbeau/phone-number-bundle](https://github.com/odolbeau/phone-number-bundle).\n\n[![Build Status](https://img.shields.io/travis/misd-service-development/phone-number-bundle.svg?style=flat-square)](https://travis-ci.org/misd-service-development/phone-number-bundle)\n[![Total Downloads](https://img.shields.io/packagist/dt/misd/phone-number-bundle.svg?style=flat-square)](https://packagist.org/packages/misd/phone-number-bundle)\n[![Downloads per month](https://img.shields.io/packagist/dm/misd/phone-number-bundle.svg?style=flat-square)](https://packagist.org/packages/misd/phone-number-bundle)\n[![Latest stable version](https://img.shields.io/packagist/v/misd/phone-number-bundle.svg?style=flat-square)](https://packagist.org/packages/misd/phone-number-bundle)\n[![License](http://img.shields.io/packagist/l/misd/phone-number-bundle.svg?style=flat-square)](https://packagist.org/packages/misd/phone-number-bundle)\n\nThis bundle integrates [Google's libphonenumber](https://github.com/googlei18n/libphonenumber) into your Symfony2-Symfony4 application through the [giggsey/libphonenumber-for-php](https://github.com/giggsey/libphonenumber-for-php) port.\n\nInstallation\n------------\n\n 1. Use Composer to download the PhoneNumberBundle:\n\n```bash\n        $ composer require misd/phone-number-bundle\n```\n\n 2. Register the bundle in your application:\n\n```php\n        // app/AppKernel.php\n\n        public function registerBundles()\n        {\n            $bundles = array(\n                // ...\n                new Misd\\PhoneNumberBundle\\MisdPhoneNumberBundle()\n            );\n        }\n```\n\nUsage\n-----\n\n### Services\n\nThe following services are available:\n\n| Service                                               | ID                                                 | libphonenumber version |\n| ----------------------------------------------------- | -------------------------------------------------- | ---------------------- |\n| `libphonenumber\\PhoneNumberUtil`                      | `libphonenumber.phone_number_util`                 |                        |\n| `libphonenumber\\geocoding\\PhoneNumberOfflineGeocoder` | `libphonenumber.phone_number_offline_geocoder`     | \u003e=5.8.8                |\n| `libphonenumber\\ShortNumberInfo`                      | `libphonenumber.short_number_info`                 | \u003e=5.8                  |\n| `libphonenumber\\PhoneNumberToCarrierMapper`           | `libphonenumber.phone_number_to_carrier_mapper`    | \u003e=5.8.8                |\n| `libphonenumber\\PhoneNumberToTimeZonesMapper`         | `libphonenumber.phone_number_to_time_zones_mapper` | \u003e=5.8.8                |\n\nSo to parse a string into a `libphonenumber\\PhoneNumber` object:\n\n```php\n    $phoneNumber = $container-\u003eget('libphonenumber.phone_number_util')-\u003eparse($string, PhoneNumberUtil::UNKNOWN_REGION);\n```\n\n### Doctrine mapping\n\n*Requires `doctrine/doctrine-bundle`.*\n\nTo persist `libphonenumber\\PhoneNumber` objects, add the `Misd\\PhoneNumberBundle\\Doctrine\\DBAL\\Types\\PhoneNumberType` mapping to your application's config:\n\n```yml\n    // app/config.yml\n\n    doctrine:\n        dbal:\n            types:\n                phone_number: Misd\\PhoneNumberBundle\\Doctrine\\DBAL\\Types\\PhoneNumberType\n```\n\nYou can then use the `phone_number` mapping:\n\n```php\n    /**\n     * @ORM\\Column(type=\"phone_number\")\n     */\n    private $phoneNumber;\n```\n\nThis creates a `varchar(35)` column with a Doctrine mapping comment.\n\nNote that if you're putting the `phone_number` type on an already-existing schema the current values must be converted to the `libphonenumber\\PhoneNumberFormat::E164` format.\n\n### Templating\n\n#### Twig\n\n##### phone_number_format\nThe `phone_number_format` filter can be used to format a phone number object. A `libphonenumber\\PhoneNumberFormat` constant can be passed as argument to specify in which format the number should be printed.\n\nFor example, to format an object called `myPhoneNumber` in the `libphonenumber\\PhoneNumberFormat::NATIONAL` format:\n\n```php\n    {{ myPhoneNumber|phone_number_format('NATIONAL') }}\n```\n\nBy default phone numbers are formatted in the `libphonenumber\\PhoneNumberFormat::INTERNATIONAL` format.\n\n###### phone_number_of_type\n\nThe `phone_number_of_type` test can be used to check a phone number against a type: A `libphonenumber\\PhoneNumberType` constant name must be passed to specify to which type a number has to match.\n\nFor example, to check if an object called `myPhoneNumber` is a `libphonenumber\\PhoneNumberType::MOBILE` type:\n\n```php\n    {% if myPhoneNumber is phone_number_of_type('MOBILE') }} %} ... {% endif %}\n```\n\n#### PHP template\n\n##### format()\n\nThe `format()` method in the `phone_number_helper` takes two arguments: a `libphonenumber\\PhoneNumber` object and an optional `libphonenumber\\PhoneNumberFormat` constant name or value.\n\nFor example, to format `$myPhoneNumber` in the `libphonenumber\\PhoneNumberFormat::NATIONAL` format, either use:\n\n```php\n    \u003c?php echo $view['phone_number_helper']-\u003eformat($myPhoneNumber, 'NATIONAL') ?\u003e\n```\n\nor:\n\n```php\n    \u003c?php echo $view['phone_number_helper']-\u003eformat($myPhoneNumber, \\libphonenumber\\PhoneNumberFormat::NATIONAL) ?\u003e\n```\n\nBy default phone numbers are formatted in the `libphonenumber\\PhoneNumberFormat::INTERNATIONAL` format.\n\n###### isType()\n\nThe `isType()` method in the `phone_number_helper` takes two arguments: a `libphonenumber\\PhoneNumber` object and an optional `libphonenumber\\PhoneNumberType` constant name or value.\n\nFor example, to check if $myPhoneNumber` is a `libphonenumber\\PhoneNumberType::MOBILE` type:\n\n```php\n    \u003c?php if $view['phone_number_helper']-\u003eisType($myPhoneNumber, 'MOBILE'): ?\u003e\n    ...\n    \u003c?php endif; ?\u003e\n```\n\nor:\n\n```php\n    \u003c?php if $view['phone_number_helper']-\u003eisType($myPhoneNumber, \\libphonenumber\\PhoneNumberType::MOBILE): ?\u003e\n    ...\n    \u003c?php endif; ?\u003e\n```\n\n### Serializing `libphonenumber\\PhoneNumber` objects\n\n*Requires `jms/serializer-bundle`.*\n\nInstances of `libphonenumber\\PhoneNumber` are automatically serialized in the E.164 format.\n\nPhone numbers can be deserialized from an international format by setting the type to `libphonenumber\\PhoneNumber`. For example:\n\n```php\n    use JMS\\Serializer\\Annotation\\Type;\n\n    /**\n     * @Type(\"libphonenumber\\PhoneNumber\")\n     */\n    private $phoneNumber;\n```\n\n### Using `libphonenumber\\PhoneNumber` objects in forms\n\nYou can use the `PhoneNumberType` (`phone_number` for Symfony 2.7) form type to create phone number fields. There are two widgets available.\n\n#### Single text field\n\nA single text field allows the user to type in the complete phone number. When an international prefix is not entered, the number is assumed to be part of the set `default_region`. For example:\n\n```php\n    use libphonenumber\\PhoneNumberFormat;\n    use Misd\\PhoneNumberBundle\\Form\\Type\\PhoneNumberType;\n    use Symfony\\Component\\Form\\FormBuilderInterface;\n\n    public function buildForm(FormBuilderInterface $builder, array $options)\n    {\n        $builder-\u003eadd('phone_number', PhoneNumberType::class, array('default_region' =\u003e 'GB', 'format' =\u003e PhoneNumberFormat::NATIONAL));\n    }\n```\n\nBy default the `default_region` and `format` options are `PhoneNumberUtil::UNKNOWN_REGION` and `PhoneNumberFormat::INTERNATIONAL` respectively.\n\n#### Country choice fields\n\nThe phone number can be split into a country choice and phone number text fields. This allows the user to choose the relevant country (from a customisable list) and type in the phone number without international dialling.\n\n```php\n    use libphonenumber\\PhoneNumberFormat;\n    use Misd\\PhoneNumberBundle\\Form\\Type\\PhoneNumberType;\n    use Symfony\\Component\\Form\\FormBuilderInterface;\n\n    public function buildForm(FormBuilderInterface $builder, array $options)\n    {\n        $builder-\u003eadd('phone_number', PhoneNumberType::class, array('widget' =\u003e PhoneNumberType::WIDGET_COUNTRY_CHOICE, 'country_choices' =\u003e array('GB', 'JE', 'FR', 'US'), 'preferred_country_choices' =\u003e array('GB', 'JE')));\n    }\n```\n\nThis produces the preferred choices of 'Jersey' and 'United Kingdom', and regular choices of 'France' and 'United States'.\n\nBy default the `country_choices` is empty, which means all countries are included, as is `preferred_country_choices`.\nThe option `country_placeholder` can be specified to create a placeholder option on above the whole list.\n\n### Validating phone numbers\n\nYou can use the `Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber` constraint to make sure that either a `libphonenumber\\PhoneNumber` object or a plain string is a valid phone number. For example:\n\n```php\n    use Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber as AssertPhoneNumber;\n\n    /**\n     * @AssertPhoneNumber\n     */\n    private $phoneNumber;\n```\n\nYou can set the default region through the `defaultRegion` property:\n\n```php\n    use Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber as AssertPhoneNumber;\n\n    /**\n     * @AssertPhoneNumber(defaultRegion=\"GB\")\n     */\n    private $phoneNumber;\n```\n\nBy default any valid phone number will be accepted. You can restrict the type through the `type` property, recognised values:\n\n- `Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber::ANY` (default)\n- `Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber::FIXED_LINE`\n- `Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber::MOBILE`\n- `Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber::PAGER`\n- `Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber::PERSONAL_NUMBER`\n- `Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber::PREMIUM_RATE`\n- `Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber::SHARED_COST`\n- `Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber::TOLL_FREE`\n- `Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber::UAN`\n- `Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber::VOIP`\n- `Misd\\PhoneNumberBundle\\Validator\\Constraints\\PhoneNumber::VOICEMAIL`\n\n(Note that libphonenumber cannot always distinguish between mobile and fixed-line numbers (eg in the USA), in which case it will be accepted.)\n\n```php\n    /**\n     * @AssertPhoneNumber(type=\"mobile\")\n     */\n    private $mobilePhoneNumber;\n```\n\n### Translations\n\nThe bundle contains translations for the form field and validation constraints.\n\nIn cases where a language uses multiple terms for mobile phones, the generic language locale will use the term 'mobile', while country-specific locales will use the relevant term. So in English, for example, `en` uses 'mobile', `en_US` uses 'cell' and `en_SG` uses 'handphone'.\n\nIf your language doesn't yet have translations, feel free to open a pull request to add them in!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmisd-service-development%2Fphone-number-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmisd-service-development%2Fphone-number-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmisd-service-development%2Fphone-number-bundle/lists"}