Download the PHP package pbarabadze/geo-phone-number without Composer
On this page you can find all versions of the php package pbarabadze/geo-phone-number. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pbarabadze/geo-phone-number
More information about pbarabadze/geo-phone-number
Files in pbarabadze/geo-phone-number
Package geo-phone-number
Short Description A Laravel library for parsing, formatting, and validating Georgian phone numbers.
License MIT
Informations about the package geo-phone-number
GeoPhoneNumber
GeoPhoneNumber is a PHP package that helps you determine the provider (Magti, Silknet, Cellfie) for a given phone number in Georgia. The package normalizes, parses, and formats phone numbers, and it can check if the number belongs to a specific provider.
Features
- Normalize phone numbers by removing non-numeric characters and ensuring the country code.
- Parse phone numbers to extract parts (
main
(6-digit national format) andfull
12 digit, international format). - Determine the phone number provider (
Magti
,Silknet
, orCellfie
). - Format phone numbers in different styles (
international (e164)
, andnational (6-digit)
). - Handle invalid phone numbers and missing providers with clear error messages.
Requirements
PHP 7.3
or higher
Installation
To install GeoPhoneNumber via Composer, run the following command:
Usage
Here’s an example of how to use the package:
Functions
getProvider($phoneNumber): string
Returns the provider name (Magti
, Silknet
, or Cellfie
) for the given phone number.
- Throws
RuntimeException
if no provider is found for the number. - Throws
InvalidArgumentException
if the phone number is invalid.
isMagti($phoneNumber): bool
Returns true
if the phone number belongs to Magti, false
otherwise.
isSilknet($phoneNumber): bool
Returns true
if the phone number belongs to Silknet, false
otherwise.
isCellfie($phoneNumber): bool
Returns true
if the phone number belongs to Cellfie, false
otherwise.
formatNumber($phoneNumber, string $format = 'international'): ?string
Formats a phone number in different styles: international (e164)
and national
.
- Options for
$format
:international
: Formats the number in international format (+9955xxxxxxxx
).national
: Formats the number in national format (5xxxxxxxx
).default
: Formats the number in E.164 format (+9955xxxxxxxx
).
Returns the formatted number, or null
if the number is invalid.
parseNumber($phoneNumber): array
Parses a phone number into its components.
- Returns an array with
main
(the main part of the number) andfull
(the full normalized phone number). - Throws
InvalidArgumentException
if the phone number is too short or invalid.
normalizeNumber($phoneNumber): string
Normalizes a phone number by removing non-numeric characters and ensuring it starts with the correct country code (995
for Georgia).
- Throws
InvalidArgumentException
if the phone number length is not exactly 12 characters after normalization.
Error Handling
- Invalid Argument: If a phone number is invalid (e.g., too short, contains invalid characters), an
InvalidArgumentException
is thrown. - No Provider Found: If no provider is found for a given phone number, a
RuntimeException
is thrown.
License
This package is licensed under the MIT License. See the LICENSE file for more information.