cherif/algerian-mobile-phone-number
Composer 安装命令:
composer require cherif/algerian-mobile-phone-number
包简介
Algerian mobile phone number value object
README 文档
README
Algerian mobile phone number value object implementation that can be used in your domain models or to integrate with your favorite framework.
Installation
composer require cherif/algerian-mobile-phone-number
Usage:
Instantiation:
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.
API:
asString
To get the string value of the object:
$phoneNumber->asString(); // -> '0699000000'
equals
For comparaison check:
$other = AlgerianMobilePhoneNumber::fromString('0699000000'); $phoneNumber->equals($other); // -> true
isMobilis, isDjezzy and isOoredoo
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
withNumber
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
__toString
Casts the value object to string:
$phoneNumber = AlgerianMobilePhoneNumber::fromString('0699000000'); (string)$phoneNumber; // -> '0699000000'
Contribution
Contributions are welcome to make this library better.
- Clone the repo:
$ git clone git@github.com:cherifGsoul/php-algerian-mobile-phone-number.git
and enter to the cloned repository directory.
- Install dependencies:
$ composer install
Testing:
Run composer script for testing:
$ composer test
License
统计信息
- 总下载量: 67
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 24
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-06-10