Skip to content

Commit

Permalink
added normalizeMyanmarPhoneNumber request macro
Browse files Browse the repository at this point in the history
  • Loading branch information
PyaeSoneAungRgn authored Jun 12, 2022
1 parent f084a6a commit 43fd8d3
Showing 5 changed files with 55 additions and 2 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ A package for Myanmar tools which extend Laravel’s core.
- [isMec](#ismec-1)
- [isMytel](#ismytel-1)
- [telecomName](#telecomname-1)
- [normalizeMyanmarPhoneNumber](#normalizemyanmarphonenumber-1)
- [Collection](#collection)
- [whereMyanmarPhoneNumber](#wheremyanmarphonenumber)
- [whereMpt](#wherempt)
@@ -272,6 +273,26 @@ $request->telecomName('phone'); // return 'mec'
$request->telecomName('phone'); // return 'mytel'
```

#### normalizeMyanmarPhoneNumber()

```php
// https://domain/path?phone=09250000000
$request->normalizeMyanmarPhoneNumber('phone'); // return '09250000000'

// https://domain/path?phone=(၀၉)၂၅၀၀၀၀၀၀၀
$request->normalizeMyanmarPhoneNumber('phone'); // return '09250000000'

// https://domain/path?phone=၀၉-၂၅၀၀၀၀၀၀၀
$request->normalizeMyanmarPhoneNumber('phone'); // return '09250000000'

// https://domain/path?phone=+၉၅၉၂၅၀၀၀၀၀၀၀
$request->normalizeMyanmarPhoneNumber('phone'); // return '09250000000'

// https://domain/path?phone=09 ၂၅ဝရဝရဝရဝ
$request->normalizeMyanmarPhoneNumber('phone');
// return '09250707070' (ဝလုံး နဲ့ ရကောက် ပါလျှင် 0 နဲ့ 7 လို့ပြောင်းလဲပါသည်)
```

## Collection

#### whereMyanmarPhoneNumber()
@@ -581,8 +602,10 @@ return [

## Version History

- 2.2.0
- added normalizeMyanmarPhoneNumber request macro
- 2.1.0
- added normalizeMyanmarPhoneNumber
- added normalizeMyanmarPhoneNumber str macro
- 2.0.0
- support laravel 9.\* | 8.\* | 7.\* | 6.\* :tada:
- 1.4.1
1 change: 1 addition & 0 deletions src/LaravelMyanmarToolsServiceProvider.php
Original file line number Diff line number Diff line change
@@ -84,6 +84,7 @@ private function requestMacros(): array
'isTelenor' => \PyaeSoneAung\LaravelMyanmarTools\Macro\Request\IsTelenor::class,
'isMec' => \PyaeSoneAung\LaravelMyanmarTools\Macro\Request\IsMec::class,
'isMytel' => \PyaeSoneAung\LaravelMyanmarTools\Macro\Request\IsMytel::class,
'normalizeMyanmarPhoneNumber' => \PyaeSoneAung\LaravelMyanmarTools\Macro\Request\NormalizeMyanmarPhoneNumber::class,

// Font
'isZawgyiFont' => \PyaeSoneAung\LaravelMyanmarTools\Macro\Request\IsZawgyiFont::class,
15 changes: 15 additions & 0 deletions src/Macro/Request/NormalizeMyanmarPhoneNumber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace PyaeSoneAung\LaravelMyanmarTools\Macro\Request;

use PyaeSoneAung\LaravelMyanmarTools\Packages\LaravelMyanmarToolsPackage;

class NormalizeMyanmarPhoneNumber
{
public function __invoke()
{
return function (string $key): string {
return LaravelMyanmarToolsPackage::normalizeMyanmarPhoneNumber($this->input($key));
};
}
}
1 change: 0 additions & 1 deletion src/Macro/Str/NormalizeMyanmarPhoneNumber.php
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
namespace PyaeSoneAung\LaravelMyanmarTools\Macro\Str;

use PyaeSoneAung\LaravelMyanmarTools\Packages\LaravelMyanmarToolsPackage;
use PyaeSoneAung\LaravelMyanmarTools\Packages\ZawgyiDetectorPackage;

class NormalizeMyanmarPhoneNumber
{
15 changes: 15 additions & 0 deletions tests/Macro/RequestTest.php
Original file line number Diff line number Diff line change
@@ -155,4 +155,19 @@ public function it_can_get_telecom_name()
$this->assertEquals(static::MEC, $request->telecomName('mec'));
$this->assertEquals(static::MYTEL, $request->telecomName('mytel'));
}

/** @test */
public function it_can_normalize_myanmar_phone_number()
{
$request = $this->createRequest([
'phone_1' => '(၀၉)၂၅၀၀၀၀၀၀၀',
'phone_2' => '၀၉-၂၅၀၀၀၀၀၀၀',
'phone_3' => '+၉၅၉၂၅၀၀၀၀၀၀၀',
'phone_4' => '09 ၂၅ဝရဝရဝရဝ',
]);
$this->assertEquals('09250000000', $request->normalizeMyanmarPhoneNumber('phone_1'));
$this->assertEquals('09250000000', $request->normalizeMyanmarPhoneNumber('phone_2'));
$this->assertEquals('09250000000', $request->normalizeMyanmarPhoneNumber('phone_3'));
$this->assertEquals('09250707070', $request->normalizeMyanmarPhoneNumber('phone_4'));
}
}

0 comments on commit 43fd8d3

Please sign in to comment.