Algerian mobile phone number value object implementation that can be used in your domain models or to integrate with your favorite framework.
composer require cherif/algerian-mobile-phone-number
The class doesn't have a public constructor, it has a named constructor instead in order to preseve its invariants:
use Cherif\AlgerianMobilePhoneNumber\AlgerianMobilePhoneNumber;
$phoneNumber = AlgerianMobilePhoneNumber::fromString('0699000000');
Or:
use Cherif\AlgerianMobilePhoneNumber\AlgerianMobilePhoneNumber;
$phoneNumber = AlgerianMobilePhoneNumber::fromString('06 99 00 00 00');
Or:
use Cherif\AlgerianMobilePhoneNumber\AlgerianMobilePhoneNumber;
$phoneNumber = AlgerianMobilePhoneNumber::fromString('06-99-00-00-00'); //
The value object class accepts international phone indicative, 00213 or +213, too.
NOTE: For now only space and dash "-" separated numbers are accepted.
To get the string value of the object:
$phoneNumber->asString(); // -> '0699000000'
For comparaison check:
$other = AlgerianMobilePhoneNumber::fromString('0699000000');
$phoneNumber->equals($other); // -> true
To know if the object respresents a Mobilis, Djezzy or Ooredoo phone number
$phoneNumber = AlgerianMobilePhoneNumber::fromString('0699000000');
$phoneNumber->isMobilis(); // -> true
$phoneNumber->isDjezzy(); // -> false
$phoneNumber->isOoredoo(); // -> false
use Cherif\AlgerianMobilePhoneNumber\AlgerianMobilePhoneNumber;
$phoneNumber = AlgerianMobilePhoneNumber::fromString('06-99-00-00-00');
$phoneNumber->withNumber('07-99-00-00-00'); // Will return a new instance that represents the new number
Casts the value object to string:
$phoneNumber = AlgerianMobilePhoneNumber::fromString('0699000000');
(string)$phoneNumber; // -> '0699000000'
Contributions are welcome to make this library better.
- Clone the repo:
$ git clone [email protected]:cherifGsoul/php-algerian-mobile-phone-number.git
and enter to the cloned repository directory.
- Install dependencies:
$ composer install
Run composer script for testing:
$ composer test