Download the PHP package settermjd/laminas-twilio-phone-number-validator without Composer
On this page you can find all versions of the php package settermjd/laminas-twilio-phone-number-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laminas-twilio-phone-number-validator
Phone Number Validator that uses Twilio's Lookup (V2) API
This is a custom laminas-validator class that checks if a phone number is valid by using Twilio's Lookup API.
Overview
The package provides a custom laminas-validator class that checks if a phone number is valid by using Twilio's Lookup API, providing a simple way of validating phone numbers are valid, based on communications provider data, accessed through Twilio.
Requirements
To use the application, you'll need the following:
- A Twilio account (free or paid). Create an account if you don't already have one.
- PHP 8.3 or 8.4
- Composer installed globally
- Git
Getting Started
Add the Package as a Project Dependency
To use the package in your project, first, either add it in composer.json's require
attribute, as in the example below.
Or, use composer require
to add it:
How to Use the Validator
You can use it directly, as in the following example, to validate a phone number.
Or, you can use it in conjunction with laminas-inputfilter, as in the following example.
In both of the above examples, the VerifyPhoneNumber
validator is initialised with a Twilio\Rest\Client
object, which in turn is initialised with a Twilio Account SID and Auth Token.
To retrieve these, open the Twilio Console in your browser of choice, then copy the Account SID and Auth Token from the Account Info, as you can see in the screenshot below.
[!CAUTION] Use a package such as PHP Dotenv to keep credentials, such as the Twilio Account SID and Auth Token out of code, and avoid them accidentally being tracked by Git (or your version control tool of choice), or your deployment tool's secrets manager is strongly encouraged.
Supply query parameters
The previous example didn't supply any query parameters. They allow you to retrieve additional data during the lookup, such as when the SIM was last swapped, and whether call forwarding is enabled.
[!CAUTION] Be aware that some query parameters, such as in
Field
s require data packages which will incur charges on your account. Please double-check your code before running it so that you don't accidentally incur excessive unintended Lookup charges.
Filter and validate query parameters
To ensure that the query parameters provided to the validator are valid, you can use the QueryParametersInputFilter
.
This is a custom laminas-inputfilter class which ensures that the query parameter data provided is valid, and doesn't contain malicious information or values unsupported by the Lookup API.
In the example above, the query parameters ($suppliedQueryParameters
) are checked with QueryParametersInputFilter
.
If the data is valid, then the VerifyPhoneNumber
validator is instantiated and used; that code is exactly the same as in the first example above.
Add Caching Support
The validator is PSR-16-compliant.
So, if you want to further enhance performance, when initialising a VerifyPhoneNumber
object, provide an object that implements CacheInterface as the third argument; the example below uses laminas-cache.
If you're not sure which PSR-16 implementation to use, check out the full list of providers on Packagist.
Contributing
If you want to contribute to the project, whether you have found issues with it or just want to improve it, here's how:
- Issues: ask questions and submit your feature requests, bug reports, etc
- Pull requests: send your improvements
Did You Find the Project Useful?
If the project was useful, and you want to say thank you and/or support its active development, here's how:
- Add a GitHub Star to the project
- Write an interesting article about the project wherever you blog
All versions of laminas-twilio-phone-number-validator with dependencies
laminas/laminas-coding-standard Version ^3.0
laminas/laminas-inputfilter Version ^2.31
laminas/laminas-validator Version ^2.60.0
twilio/sdk Version ^8.3
vlucas/phpdotenv Version ^5.6