{"id":15524875,"url":"https://github.com/simonschaufi/typo3-phone","last_synced_at":"2025-04-23T07:41:26.535Z","repository":{"id":35046774,"uuid":"200382911","full_name":"simonschaufi/typo3-phone","owner":"simonschaufi","description":"Phone number functionality for TYPO3 that uses Google's libphonenumber library","archived":false,"fork":false,"pushed_at":"2024-04-29T19:37:25.000Z","size":127,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-05-01T22:25:02.088Z","etag":null,"topics":["libphonenumber","phone","phone-number","phonenumber","typo3","typo3-cms-extension","typo3-phone","validation","validation-library","validator"],"latest_commit_sha":null,"homepage":"https://www.simonschaufelberger.de/de/projekte/typo3-extensions/typo3-phone.html","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonschaufi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2019-08-03T14:10:17.000Z","updated_at":"2024-05-06T08:53:32.201Z","dependencies_parsed_at":"2023-11-19T19:31:01.131Z","dependency_job_id":"9be81bcf-19d8-4891-aaf9-f1d1448858e0","html_url":"https://github.com/simonschaufi/typo3-phone","commit_stats":{"total_commits":57,"total_committers":1,"mean_commits":57.0,"dds":0.0,"last_synced_commit":"126de4482912c42d0fe73955279d9c5a901f8b86"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonschaufi%2Ftypo3-phone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonschaufi%2Ftypo3-phone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonschaufi%2Ftypo3-phone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonschaufi%2Ftypo3-phone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonschaufi","download_url":"https://codeload.github.com/simonschaufi/typo3-phone/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242011147,"owners_count":20057405,"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":["libphonenumber","phone","phone-number","phonenumber","typo3","typo3-cms-extension","typo3-phone","validation","validation-library","validator"],"created_at":"2024-10-02T10:53:28.441Z","updated_at":"2025-03-05T10:33:40.666Z","avatar_url":"https://github.com/simonschaufi.png","language":"PHP","funding_links":["https://www.paypal.me/simonschaufi/20","https://github.com/sponsors/simonschaufi","https://www.buymeacoffee.com/simonschaufi"],"categories":[],"sub_categories":[],"readme":"# TYPO3 Phone\n\n[![Donate](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://www.paypal.me/simonschaufi/20)\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/simonschaufi?label=GitHub%20Sponsors)](https://github.com/sponsors/simonschaufi)\n[![Buy me a coffee](https://img.shields.io/badge/-Buy_me_a_coffee-gray?logo=buymeacoffee)](https://www.buymeacoffee.com/simonschaufi)\n[![CI](https://github.com/simonschaufi/typo3-phone/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/simonschaufi/typo3-phone/actions/workflows/ci.yml)\n[![Latest Stable Version](https://poser.pugx.org/simonschaufi/typo3-phone/v/stable)](https://packagist.org/packages/simonschaufi/typo3-phone)\n[![Total Downloads](https://poser.pugx.org/simonschaufi/typo3-phone/downloads)](https://packagist.org/packages/simonschaufi/typo3-phone)\n[![License](https://poser.pugx.org/simonschaufi/typo3-phone/license)](https://packagist.org/packages/simonschaufi/typo3-phone)\n[![TYPO3](https://img.shields.io/badge/TYPO3-12-orange.svg)](https://get.typo3.org/version/12)\n\nAdds phone number functionality to TYPO3 based on the [PHP port](https://github.com/giggsey/libphonenumber-for-php)\nof [libphonenumber by Google](https://github.com/googlei18n/libphonenumber).\n\n## Installation\n\nRun the following command to install the latest applicable version of the package:\n\n```bash\ncomposer require simonschaufi/typo3-phone\n```\n\n## Validation\n\nFor each action (here `updateAction`) you want to validate your object (in this case an Address with two properties \"phone\" and \"fax\")\nadd the following code in your controller:\n\n```php\nuse SimonSchaufi\\TYPO3Phone\\Validation\\Validator\\PhoneValidator;\n\npublic function initializeUpdateAction(): void\n{\n\tif ($this-\u003erequest-\u003ehasArgument('address') \u0026\u0026 $this-\u003erequest-\u003egetArgument('address')) {\n\t\t$addressValidator = $this-\u003evalidatorResolver-\u003egetBaseValidatorConjunction(Address::class);\n\n\t\t$validators = $addressValidator-\u003egetValidators();\n\t\t$validators-\u003erewind();\n\t\t$validator = $validators-\u003ecurrent();\n\n\t\t/** @var PhoneValidator $phoneValidator */\n\t\t$phoneValidator = $this-\u003evalidatorResolver-\u003ecreateValidator(PhoneValidator::class, [\n\t\t\t// If the user enters a number prefixed with \"+\" then the country can be guessed.\n\t\t\t// If not, the following countries listed in the array will be checked against\n\t\t\t'countries' =\u003e ['DE'],\n\t\t\t'international' =\u003e true,\n\t\t]);\n\n\t\t$validator-\u003eaddPropertyValidator('phone', $phoneValidator);\n\t\t$validator-\u003eaddPropertyValidator('fax', $phoneValidator);\n\t}\n}\n```\n\nAlternatively you can instantiate the validator anywhere in your code like this:\n\n```php\nuse SimonSchaufi\\TYPO3Phone\\Validation\\Validator\\PhoneValidator;\n\n$phoneValidator = GeneralUtility::makeInstance(PhoneValidator::class);\n$phoneValidator-\u003esetOptions([\n\t// If the user enters a number prefixed with \"+\" then the country can be guessed.\n\t// If not, the following countries listed in the array will be checked against\n\t'countries' =\u003e ['DE'],\n\t'types' =\u003e ['mobile'],\n\t'international' =\u003e true,\n]);\n\n$result = $phoneValidator-\u003evalidate('+3212345678');\n\nif ($result-\u003ehasErrors()) {\n\t// Error handling\n}\n```\n\nNote: country codes should be [*ISO 3166-1 alpha-2 compliant*](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements).\n\nTo support _any valid internationally formatted_ phone number next to the whitelisted countries, use the `international` option.\nThis can be useful when you're expecting locally formatted numbers from a specific country but also want to accept any other foreign number entered properly:\n\n```php\n$phoneValidator-\u003esetOptions([\n    'international' =\u003e true,\n]);\n```\n\nThe validator will try to extract the country from the number itself and then check if the number is valid for that country.\nIf the country could not be guessed it will be validated using the fallback countries if provided.\nNote that country guessing will only work when phone numbers are entered in *international format* (prefixed with a `+` sign, e.g. +32 ....).\nLeading double zeros will **NOT** be parsed correctly as this isn't an established consistency.\n\nTo specify constraints on the number type, set the allowed types, e.g.:\n\n```php\n$phoneValidator-\u003esetOptions([\n    'types' =\u003e ['mobile'],\n]);\n```\nThe most common types are `mobile` and `fixed_line`, but feel free to use any of the types defined [here](https://github.com/giggsey/libphonenumber-for-php/blob/master/src/PhoneNumberType.php).\n\nYou can also enable lenient validation by using the `lenient` option.\nWith leniency enabled, only the length of the number is checked instead of actual carrier patterns.\n\n```php\n$phoneValidator-\u003esetOptions([\n    'lenient' =\u003e true,\n]);\n```\n\n### Validation outside of Extbase\n\nIf you **don't** want to use the extbase validator and instead a more low level approach, use the following code:\n\nInfo: In this case the Address object has a property \"country\" that is of type `\\SJBR\\StaticInfoTables\\Domain\\Model\\Country`\n\n```php\nuse SimonSchaufi\\TYPO3Phone\\Exceptions\\NumberParseException;\nuse SimonSchaufi\\TYPO3Phone\\PhoneNumber;\n\nif (!empty($address-\u003egetPhone())) {\n\ttry {\n\t\t$phoneNumber = (new PhoneNumber($address-\u003egetPhone(), [$address-\u003egetCountry()-\u003egetIsoCodeA2()]))-\u003eformatInternational();\n\t\t$address-\u003esetPhone($phoneNumber);\n\t} catch (NumberParseException $exception) {\n\t\t// Error handling\n\t}\n}\n```\n\n## Utility PhoneNumber class\n\nA phone number can be wrapped in the `SimonSchaufi\\TYPO3Phone\\PhoneNumber` class to enhance it with useful utility\nmethods. It's safe to directly reference these objects in views or when saving to the database as they will degrade\ngracefully to the E.164 format.\n\n```php\nuse SimonSchaufi\\TYPO3Phone\\PhoneNumber;\n\n(string) new PhoneNumber('+3212/34.56.78');     // +3212345678\n(string) new PhoneNumber('012 34 56 78', 'BE'); // +3212345678\n```\n\n### Formatting\n\nA PhoneNumber can be formatted in various ways:\n\n```php\nuse SimonSchaufi\\TYPO3Phone\\PhoneNumber;\n\n$phone = new PhoneNumber('012/34.56.78', 'BE');\n\n$phone-\u003eformat($format);       // See libphonenumber\\PhoneNumberFormat\n$phone-\u003eformatE164();          // +3212345678\n$phone-\u003eformatInternational(); // +32 12 34 56 78\n$phone-\u003eformatRFC3966();       // +32-12-34-56-78\n$phone-\u003eformatNational();      // 012 34 56 78\n\n// Formats so the number can be called straight from the provided country.\n$phone-\u003eformatForCountry('BE'); // 012 34 56 78\n$phone-\u003eformatForCountry('NL'); // 00 32 12 34 56 78\n$phone-\u003eformatForCountry('US'); // 011 32 12 34 56 78\n\n// Formats so the number can be clicked on and called straight from the provided country using a cellphone.\n$phone-\u003eformatForMobileDialingInCountry('BE'); // 012345678\n$phone-\u003eformatForMobileDialingInCountry('NL'); // +3212345678\n$phone-\u003eformatForMobileDialingInCountry('US'); // +3212345678\n```\n\n### Number information\n\nGet some information about the phone number:\n\n```php\nuse SimonSchaufi\\TYPO3Phone\\PhoneNumber;\n\n$phone = new PhoneNumber('012 34 56 78', 'BE');\n\n$phone-\u003egetType();              // 'fixed_line'\n$phone-\u003eisOfType('fixed_line'); // true\n$phone-\u003egetCountry();           // 'BE'\n$phone-\u003eisOfCountry('BE');      // true\n```\n\n### Equality comparison\n\nCheck if a given phone number is (not) equal to another one:\n\n```php\nuse SimonSchaufi\\TYPO3Phone\\PhoneNumber;\n\n$phone = new PhoneNumber('012 34 56 78', 'BE');\n\n$phone-\u003eequals('012/34.56.78', 'BE')       // true\n$phone-\u003eequals('+32 12 34 56 78')          // true\n$phone-\u003eequals($anotherPhoneObject)        // true/false\n\n$phone-\u003enotEquals('045 67 89 10', 'BE')    // true\n$phone-\u003enotEquals('+32 45 67 89 10')       // true\n$phone-\u003enotEquals($anotherPhoneObject)     // true/false\n```\n\n## Database considerations\n\n\u003e Disclaimer: Phone number handling is quite different in each application. The topics mentioned below are therefore meant as a set of thought starters; support will **not** be provided.\n\nStoring phone numbers in a database has always been a speculative topic and there's simply no silver bullet.\nIt all depends on your application's requirements. Here are some things to take into account, along with an implementation suggestion.\nYour ideal database setup will probably be a combination of some of the pointers detailed below.\n\n### Uniqueness\n\nThe E.164 format globally and uniquely identifies a phone number across the world.\nIt also inherently implies a specific country and can be supplied as-is to the `phone()` helper.\n\nYou'll need:\n\n* One column to store the phone number\n* To format the phone number to E.164 before persisting it\n\nExample:\n\n* User input = `012/45.65.78`\n* Database column\n  * `phone` (varchar) = `+3212456578`\n\n### Presenting the phone number the way it was inputted\n\nIf you store formatted phone numbers the raw user input will irretrievably get lost.\nIt may be beneficial to present your users with their very own inputted phone number,\nfor example in terms of improved user experience.\n\nYou'll need:\n* Two columns to store the raw input and the correlated country\n\nExample:\n\n* User input = `012/34.56.78`\n* Database columns\n  * `phone` (varchar) = `012/34.56.78`\n  * `phone_country` (varchar) = `BE`\n\n### Supporting searches\n\nSearching through phone numbers can quickly become ridiculously complex and will always require deep understanding of\nthe context and extent of your application. Here's _a_ possible approach covering quite a lot of \"natural\" use cases.\n\nYou'll need:\n* Three additional columns to store searchable variants of the phone number:\n  * Normalized input (raw input with all non-alpha characters stripped)\n  * National formatted phone number (with all non-alpha characters stripped)\n  * E.164 formatted phone number\n* An extensive search query utilizing the searchable variants\n\nExample:\n\n* User input = `12/34.56.78`\n* Database columns\n  * `phone_normalized` (varchar) = `12345678`\n  * `phone_national` (varchar) = `012345678`\n  * `phone_e164` (varchar) = `+3212345678`\n\n## Need help with integrating this extension into your website?\n\nPlease contact me via my website: https://www.simonschaufelberger.de/de/kontakt.html and I will help you!\n\n## Giving thanks\n\nThis extension is heavily inspired by https://github.com/Propaganistas/Laravel-Phone. Thank you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonschaufi%2Ftypo3-phone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonschaufi%2Ftypo3-phone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonschaufi%2Ftypo3-phone/lists"}