{"id":43291174,"url":"https://github.com/zentlix/libphonenumber","last_synced_at":"2026-02-01T18:31:09.732Z","repository":{"id":65557613,"uuid":"585122039","full_name":"zentlix/libphonenumber","owner":"zentlix","description":"Integrates Google's phone number handling library into Spiral Framework","archived":false,"fork":false,"pushed_at":"2023-09-11T10:22:40.000Z","size":39,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"1.x","last_synced_at":"2025-07-20T01:14:24.231Z","etag":null,"topics":["libphonenumber","phone-number","phonenumber","spiral-framework"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zentlix.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-04T11:25:34.000Z","updated_at":"2023-06-25T19:24:21.000Z","dependencies_parsed_at":"2023-02-08T06:31:33.250Z","dependency_job_id":null,"html_url":"https://github.com/zentlix/libphonenumber","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/zentlix/libphonenumber","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentlix%2Flibphonenumber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentlix%2Flibphonenumber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentlix%2Flibphonenumber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentlix%2Flibphonenumber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zentlix","download_url":"https://codeload.github.com/zentlix/libphonenumber/tar.gz/refs/heads/1.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentlix%2Flibphonenumber/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28985818,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T18:17:03.387Z","status":"ssl_error","status_checked_at":"2026-02-01T18:16:57.287Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["libphonenumber","phone-number","phonenumber","spiral-framework"],"created_at":"2026-02-01T18:31:09.657Z","updated_at":"2026-02-01T18:31:09.721Z","avatar_url":"https://github.com/zentlix.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Google libphonenumber integration package for Spiral Framework\n\n[![PHP Version Require](https://poser.pugx.org/zentlix/libphonenumber/require/php)](https://packagist.org/packages/zentlix/libphonenumber)\n[![Latest Stable Version](https://poser.pugx.org/zentlix/libphonenumber/v/stable)](https://packagist.org/packages/zentlix/libphonenumber)\n[![phpunit](https://github.com/zentlix/libphonenumber/actions/workflows/phpunit.yml/badge.svg)](https://github.com/zentlix/libphonenumber/actions)\n[![psalm](https://github.com/zentlix/libphonenumber/actions/workflows/psalm.yml/badge.svg)](https://github.com/zentlix/libphonenumber/actions)\n[![Codecov](https://codecov.io/gh/zentlix/libphonenumber/branch/master/graph/badge.svg)](https://codecov.io/gh/zentlix/libphonenumber)\n[![Total Downloads](https://poser.pugx.org/zentlix/libphonenumber/downloads)](https://packagist.org/packages/zentlix/libphonenumber)\n[![type-coverage](https://shepherd.dev/github/zentlix/libphonenumber/coverage.svg)](https://shepherd.dev/github/zentlix/libphonenumber)\n[![psalm-level](https://shepherd.dev/github/zentlix/libphonenumber/level.svg)](https://shepherd.dev/github/zentlix/libphonenumber)\n\nThe package provides tools for parsing, formatting, and validating international phone numbers\nin `Spiral Framework`. It integrates the `Google libphonenumber` library,\nwhich is a powerful and widely used library for working with phone numbers.\n\n## Requirements\n\nMake sure that your server is configured with following PHP version and extensions:\n\n- PHP 8.1+\n- Spiral framework 3.5+\n\n## Installation\n\nTo install the package, use Composer by running the following command:\n\n```bash\ncomposer require zentlix/libphonenumber\n```\n\nTo enable the package in your Spiral Framework application, you will need to add the\n`Spiral\\PhoneNumber\\Bootloader\\PhoneNumberBootloader` class to the list of bootloaders in your application:\n\n```php\nprotected const LOAD = [\n    // ...\n    \\Spiral\\PhoneNumber\\Bootloader\\PhoneNumberBootloader::class,\n];\n```\n\n\u003e **Note**\n\u003e If you are using [`spiral-packages/discoverer`](https://github.com/spiral-packages/discoverer),\n\u003e you don't need to register bootloader by yourself.\n\n## Configuration\n\nThe configuration file should be located at `app/config/libphonenumber.php`, and it allows you to set options\nsuch as the default region and default format for phone numbers.\n\nHere is an example of how the configuration file might look:\n\n```php\nuse libphonenumber\\PhoneNumberFormat;\nuse libphonenumber\\PhoneNumberUtil;\n\nreturn [\n    'default_region' =\u003e PhoneNumberUtil::UNKNOWN_REGION,\n    'default_format' =\u003e PhoneNumberFormat::E164,\n];\n```\n\nThe `default_region` option specifies the default region code to use when parsing and formatting phone numbers.\nThis can be set to any valid region code, such as `US`, `GB`, and others.\n\nThe `default_format` option specifies the default format to use when formatting phone numbers.\nThis can be set to any of the constants provided by the `libphonenumber\\PhoneNumberFormat` class,\nsuch as `NATIONAL`, `INTERNATIONAL`, or `E164`.\n\n## Usage\n\nThe `libphonenumber\\PhoneNumberUtil` class provides methods for parsing phone numbers from strings,\nformatting phone numbers as strings, and validating phone numbers.\n\nThe `libphonenumber\\PhoneNumber` class is a class that represents a phone number in an object-oriented format.\nIt is returned by the `parse` method of the `libphonenumber\\PhoneNumberUtil` class, and it stores complete\nphone number information such as the country code, national number, and other details.\n\nOne way to use the `PhoneNumberUtil` class is to inject it into your classes using dependency injection. For example:\n\n```php\n\nuse libphonenumber\\PhoneNumberUtil;\n\nfinal class SomeService\n{\n     public function __construct(\n         private readonly PhoneNumberUtil $phoneNumberUtil\n     ) {\n     }\n\n     public function do(): void\n     {\n         $phoneNumber = $this-\u003ephoneNumberUtil-\u003eparse('+1 650 253 0000', 'US');\n\n         // ...\n     }\n}\n```\n\nAlternatively, you can create a `libphonenumber\\PhoneNumberUtil` instance manually by calling the\n`PhoneNumberUtil::getInstance` method. For example:\n\n```php\n$utils = PhoneNumberUtil::getInstance();\n$phoneNumber = $utils-\u003eparse('+1 650 253 0000', 'US');\n```\n\nHere is an example of how you might use some of the methods provided\nby the `libphonenumber\\PhoneNumberUtil` and `libphonenumber\\PhoneNumber` classes:\n\n```php\n$utils = libphonenumber\\PhoneNumberUtil::getInstance();\n\n$phoneNumber = $utils-\u003eparse('+1 650 253 0000', 'US');\n$phoneNumber-\u003egetCountryCode(); // 1\n$phoneNumber-\u003egetNationalNumber(); // 6502530000\n\n$utils-\u003eformat($phoneNumber, PhoneNumberFormat::E164); // +16502530000\n$utils-\u003eformat($phoneNumber, PhoneNumberFormat::INTERNATIONAL); // +1 650-253-0000\n$utils-\u003eformat($phoneNumber, PhoneNumberFormat::NATIONAL); // (650) 253-0000\n$utils-\u003eformat($phoneNumber, PhoneNumberFormat::RFC3966); // tel:+1-650-253-0000\n```\n\n## Validation\n\n### Symfony Validator\n\nThe package provides a `Spiral\\PhoneNumber\\Validator\\Constraints\\PhoneNumber` constraint that can be used to validate\nphone numbers using the `spiral-packages/symfony-validator` component.\n\nTo use the `Spiral\\PhoneNumber\\Validator\\Constraints\\PhoneNumber` constraint, you will first need to make sure that\nthe `spiral-packages/symfony-validator` package is installed and enabled in your Spiral Framework application.\n\nOnce the `spiral-packages/symfony-validator` package is installed and enabled, you can use the `PhoneNumber`\nconstraint in your code like this:\n\n```php\nuse libphonenumber\\PhoneNumber;\nuse Spiral\\PhoneNumber\\Validator\\Constraints;\n\nclass User\n{\n    #[Constraints\\PhoneNumber]\n    protected ?PhoneNumber $phone = null;\n}\n```\n\nIn this example, the `PhoneNumber` constraint is applied to the **$phone** property of the **User** class using the\nattribute. This will cause the Validator to validate the **$phone** property as a phone number when\nthe User object is validated. If the value of the $phone property is not a valid phone number, the validation will fail.\n\nYou can also specify additional options when using the `PhoneNumber` constraint:\n\n```php\nuse libphonenumber\\PhoneNumber;\nuse libphonenumber\\PhoneNumberFormat;\nuse Spiral\\PhoneNumber\\Validator\\Constraints;\n\nclass User\n{\n    #[Constraints\\PhoneNumber(\n        format: PhoneNumberFormat::INTERNATIONAL,\n        defaultRegion: 'US',\n        message: 'The phone number is invalid!'\n    )]\n    protected ?PhoneNumber $phone = null;\n}\n```\n\n### Spiral Validator\n\nThe package provides a `Spiral\\PhoneNumber\\Validator\\Checker\\PhoneNumberChecker` checker that can be used to validate\nphone numbers using the `spiral/validator` component.\n\nTo use the `Spiral\\PhoneNumber\\Validator\\Checker\\PhoneNumberChecker` checker, you will first need to make sure that\nthe `spiral/validator` package is installed and enabled in your Spiral Framework application.\n\nOnce the `spiral/validator` package is installed and enabled, you can use the `PhoneNumberChecker`\nchecker in your code like this:\n\n```php\nnamespace App\\Request;\n\nuse Spiral\\Filters\\Attribute\\Input\\Post;\nuse Spiral\\Filters\\Model\\Filter;\nuse Spiral\\Filters\\Model\\FilterDefinitionInterface;\nuse Spiral\\Filters\\Model\\HasFilterDefinition;\nuse Spiral\\Validator\\FilterDefinition;\n\nfinal class UserRequest extends Filter implements HasFilterDefinition\n{\n    #[Post]\n    public string $phone;\n\n    public function filterDefinition(): FilterDefinitionInterface\n    {\n        return new FilterDefinition([\n            'phone' =\u003e ['phone'],\n            // or with custom error message\n            'phone' =\u003e [\n                ['phone', 'error' =\u003e 'Custom error message.']\n            ]\n        ]);\n    }\n}\n```\n\nIn this example, the `PhoneNumberChecker` checker is applied to the **$phone** property of the **UserRequest** class.\nThis will cause the Validator to validate the **$phone** property as a phone number when the UserRequest object\nis validated. If the value of the $phone property is not a valid phone number, the validation will fail.\n\n## Serialization\n\nThe package provides a `Spiral\\PhoneNumber\\Serializer\\Normalizer\\PhoneNumberNormalizer` class that can be used\nto serialize and deserialize `libphonenumber\\PhoneNumber` objects using the `spiral-packages/symfony-serializer` package.\n\nOnce the `spiral-packages/symfony-serializer` package is installed and enabled, the `PhoneNumberNormalizer` class\nwill be automatically registered as a normalizer for `libphonenumber\\PhoneNumber` objects.\nThis means that you can use the Symfony Serializer to serialize and deserialize `libphonenumber\\PhoneNumber`\nobjects just like any other object:\n\n```php\n$utils = \\libphonenumber\\PhoneNumberUtil::getInstance();\n\n/** @var \\Spiral\\Serializer\\SerializerManager $manager */\n$manager = $this-\u003egetContainer()-\u003eget(\\Spiral\\Serializer\\SerializerManager::class);\n\n$result = $manager-\u003egetSerializer('json')-\u003eserialize($utils-\u003eparse('+1 650 253 0000', 'US'));\n\necho $result; // \"+16502530000\"\n\n$phoneNumber = $manager-\u003egetSerializer('json')-\u003eunserialize(json_encode('+16502530000'), PhoneNumber::class);\n\nvar_dump(get_debug_type($phoneNumber)); // libphonenumber\\PhoneNumber\n```\n\n## Twig\n\nThe package provides a `Spiral\\PhoneNumber\\Twig\\Extension\\PhoneNumberExtension` class that can be used\nto add `filters` and `test` to the Twig templating engine.\n\nTo use the `PhoneNumberExtension` class, you will first need to make sure that the `spiral/twig-bridge` package\nis installed and enabled in your Spiral Framework application.\n\nOnce the `spiral/twig-bridge` package is installed and enabled, the `PhoneNumberExtension` class will be automatically\nregistered as an extension for Twig.\n\nThe PhoneNumberExtension class provides the following filters:\n\n- `phone_number_format`: Formats a phone number for out-of-country dialing purposes.\n- `phone_number_format_out_of_country_calling_number` : Formats a `libphonenumber\\Phone\n\n```php\n{{ phoneNumber | phone_number_format('NATIONAL') }}\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n```bash\ncomposer psalm\n```\n\n```bash\ncomposer cs\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzentlix%2Flibphonenumber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzentlix%2Flibphonenumber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzentlix%2Flibphonenumber/lists"}