From b4d4360b944d24e6df7ecb17ad7f99586f59c2fb Mon Sep 17 00:00:00 2001 From: Pyae Sone Aung Date: Mon, 6 Nov 2023 00:13:46 +0630 Subject: [PATCH] add telecom network type and extract phone number --- composer.json | 6 +- src/LaravelMyanmarToolsServiceProvider.php | 24 +++++-- src/Macros/Request/ExtractMec.php | 16 +++++ src/Macros/Request/ExtractMpt.php | 16 +++++ .../Request/ExtractMyanmarPhoneNumber.php | 16 +++++ src/Macros/Request/ExtractMytel.php | 16 +++++ src/Macros/Request/ExtractOoredoo.php | 16 +++++ src/Macros/Request/ExtractTelenor.php | 16 +++++ src/Macros/Request/TelecomNetworkType.php | 16 +++++ src/Macros/Str/ExtractMec.php | 15 +++++ src/Macros/Str/ExtractMpt.php | 15 +++++ src/Macros/Str/ExtractMyanmarPhoneNumber.php | 15 +++++ src/Macros/Str/ExtractMytel.php | 15 +++++ src/Macros/Str/ExtractOoredoo.php | 15 +++++ src/Macros/Str/ExtractTelenor.php | 15 +++++ src/Macros/Str/TelecomNetworkType.php | 15 +++++ tests/Feature/RequestTest.php | 64 +++++++++++++++++++ tests/Feature/StrTest.php | 43 +++++++++++++ 18 files changed, 346 insertions(+), 8 deletions(-) create mode 100644 src/Macros/Request/ExtractMec.php create mode 100644 src/Macros/Request/ExtractMpt.php create mode 100644 src/Macros/Request/ExtractMyanmarPhoneNumber.php create mode 100644 src/Macros/Request/ExtractMytel.php create mode 100644 src/Macros/Request/ExtractOoredoo.php create mode 100644 src/Macros/Request/ExtractTelenor.php create mode 100644 src/Macros/Request/TelecomNetworkType.php create mode 100644 src/Macros/Str/ExtractMec.php create mode 100644 src/Macros/Str/ExtractMpt.php create mode 100644 src/Macros/Str/ExtractMyanmarPhoneNumber.php create mode 100644 src/Macros/Str/ExtractMytel.php create mode 100644 src/Macros/Str/ExtractOoredoo.php create mode 100644 src/Macros/Str/ExtractTelenor.php create mode 100644 src/Macros/Str/TelecomNetworkType.php diff --git a/composer.json b/composer.json index 39e5c48..55f913b 100644 --- a/composer.json +++ b/composer.json @@ -24,8 +24,8 @@ "require": { "php": "^8.1", "illuminate/contracts": "^9.0|^10.0", - "laravel-myanmar-tools/phone-number": "^1.0.1", - "laravel-myanmar-tools/font": "^1.0", + "laravel-myanmar-tools/phone-number": "^1.1.0", + "laravel-myanmar-tools/font": "^1.0.0", "laravel-myanmar-tools/nrc": "^1.0.1" }, "require-dev": { @@ -62,4 +62,4 @@ "pestphp/pest-plugin": true } } -} +} \ No newline at end of file diff --git a/src/LaravelMyanmarToolsServiceProvider.php b/src/LaravelMyanmarToolsServiceProvider.php index eba6f24..8e047d3 100644 --- a/src/LaravelMyanmarToolsServiceProvider.php +++ b/src/LaravelMyanmarToolsServiceProvider.php @@ -102,9 +102,9 @@ private function registerCarbonMacros(): void private function registerLang(): void { - $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', $this->getPackageName()); + $this->loadTranslationsFrom(__DIR__.'/../resources/lang', $this->getPackageName()); $this->publishes([ - __DIR__ . '/../resources/lang' => base_path('/lang/vendor/' . $this->getPackageName()), + __DIR__.'/../resources/lang' => base_path('/lang/vendor/'.$this->getPackageName()), ]); } @@ -113,13 +113,20 @@ private function strMacros(): array return [ // Telecom 'isMyanmarPhoneNumber' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\IsMyanmarPhoneNumber::class, - 'telecomName' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\TelecomName::class, 'isMpt' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\IsMpt::class, 'isOoredoo' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\IsOoredoo::class, 'isTelenor' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\IsTelenor::class, 'isMec' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\IsMec::class, 'isMytel' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\IsMytel::class, 'normalizeMyanmarPhoneNumber' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\NormalizeMyanmarPhoneNumber::class, + 'telecomName' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\TelecomName::class, + 'telecomNetworkType' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\TelecomNetworkType::class, + 'extractMyanmarPhoneNumber' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\ExtractMyanmarPhoneNumber::class, + 'extractMpt' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\ExtractMpt::class, + 'extractOoredoo' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\ExtractOoredoo::class, + 'extractTelenor' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\ExtractTelenor::class, + 'extractMec' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\ExtractMec::class, + 'extractMytel' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\ExtractMytel::class, // Font 'isZawgyiFont' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Str\IsZawgyiFont::class, @@ -139,13 +146,20 @@ private function requestMacros(): array return [ // Telecom 'isMyanmarPhoneNumber' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\IsMyanmarPhoneNumber::class, - 'telecomName' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\TelecomName::class, 'isMpt' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\IsMpt::class, 'isOoredoo' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\IsOoredoo::class, 'isTelenor' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\IsTelenor::class, 'isMec' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\IsMec::class, 'isMytel' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\IsMytel::class, 'normalizeMyanmarPhoneNumber' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\NormalizeMyanmarPhoneNumber::class, + 'telecomName' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\TelecomName::class, + 'telecomNetworkType' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\TelecomNetworkType::class, + 'extractMyanmarPhoneNumber' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\ExtractMyanmarPhoneNumber::class, + 'extractMpt' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\ExtractMpt::class, + 'extractOoredoo' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\ExtractOoredoo::class, + 'extractTelenor' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\ExtractTelenor::class, + 'extractMec' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\ExtractMec::class, + 'extractMytel' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\ExtractMytel::class, // Font 'isZawgyiFont' => \PyaeSoneAung\LaravelMyanmarTools\Macros\Request\IsZawgyiFont::class, @@ -235,6 +249,6 @@ private function getPackageName(): string private function getErrorMessage($extend): mixed { - return trans($this->getPackageName() . '::validation.' . Str::snake($extend)); + return trans($this->getPackageName().'::validation.'.Str::snake($extend)); } } diff --git a/src/Macros/Request/ExtractMec.php b/src/Macros/Request/ExtractMec.php new file mode 100644 index 0000000..40dc6db --- /dev/null +++ b/src/Macros/Request/ExtractMec.php @@ -0,0 +1,16 @@ +input($key)); + }; + } +} diff --git a/src/Macros/Request/ExtractMpt.php b/src/Macros/Request/ExtractMpt.php new file mode 100644 index 0000000..fd0a351 --- /dev/null +++ b/src/Macros/Request/ExtractMpt.php @@ -0,0 +1,16 @@ +input($key)); + }; + } +} diff --git a/src/Macros/Request/ExtractMyanmarPhoneNumber.php b/src/Macros/Request/ExtractMyanmarPhoneNumber.php new file mode 100644 index 0000000..b8a5f51 --- /dev/null +++ b/src/Macros/Request/ExtractMyanmarPhoneNumber.php @@ -0,0 +1,16 @@ +input($key)); + }; + } +} diff --git a/src/Macros/Request/ExtractMytel.php b/src/Macros/Request/ExtractMytel.php new file mode 100644 index 0000000..118f60c --- /dev/null +++ b/src/Macros/Request/ExtractMytel.php @@ -0,0 +1,16 @@ +input($key)); + }; + } +} diff --git a/src/Macros/Request/ExtractOoredoo.php b/src/Macros/Request/ExtractOoredoo.php new file mode 100644 index 0000000..70bb51e --- /dev/null +++ b/src/Macros/Request/ExtractOoredoo.php @@ -0,0 +1,16 @@ +input($key)); + }; + } +} diff --git a/src/Macros/Request/ExtractTelenor.php b/src/Macros/Request/ExtractTelenor.php new file mode 100644 index 0000000..f01eea1 --- /dev/null +++ b/src/Macros/Request/ExtractTelenor.php @@ -0,0 +1,16 @@ +input($key)); + }; + } +} diff --git a/src/Macros/Request/TelecomNetworkType.php b/src/Macros/Request/TelecomNetworkType.php new file mode 100644 index 0000000..7cb6b77 --- /dev/null +++ b/src/Macros/Request/TelecomNetworkType.php @@ -0,0 +1,16 @@ +input($key)); + }; + } +} diff --git a/src/Macros/Str/ExtractMec.php b/src/Macros/Str/ExtractMec.php new file mode 100644 index 0000000..82b056d --- /dev/null +++ b/src/Macros/Str/ExtractMec.php @@ -0,0 +1,15 @@ +extractMec($value); + }; + } +} diff --git a/src/Macros/Str/ExtractMpt.php b/src/Macros/Str/ExtractMpt.php new file mode 100644 index 0000000..8c1ad55 --- /dev/null +++ b/src/Macros/Str/ExtractMpt.php @@ -0,0 +1,15 @@ +extractMpt($value); + }; + } +} diff --git a/src/Macros/Str/ExtractMyanmarPhoneNumber.php b/src/Macros/Str/ExtractMyanmarPhoneNumber.php new file mode 100644 index 0000000..8530d13 --- /dev/null +++ b/src/Macros/Str/ExtractMyanmarPhoneNumber.php @@ -0,0 +1,15 @@ +extractMyanmarPhoneNumber($value); + }; + } +} diff --git a/src/Macros/Str/ExtractMytel.php b/src/Macros/Str/ExtractMytel.php new file mode 100644 index 0000000..5e29b69 --- /dev/null +++ b/src/Macros/Str/ExtractMytel.php @@ -0,0 +1,15 @@ +extractMytel($value); + }; + } +} diff --git a/src/Macros/Str/ExtractOoredoo.php b/src/Macros/Str/ExtractOoredoo.php new file mode 100644 index 0000000..d57b2b7 --- /dev/null +++ b/src/Macros/Str/ExtractOoredoo.php @@ -0,0 +1,15 @@ +extractOoredoo($value); + }; + } +} diff --git a/src/Macros/Str/ExtractTelenor.php b/src/Macros/Str/ExtractTelenor.php new file mode 100644 index 0000000..10dc440 --- /dev/null +++ b/src/Macros/Str/ExtractTelenor.php @@ -0,0 +1,15 @@ +extractTelenor($value); + }; + } +} diff --git a/src/Macros/Str/TelecomNetworkType.php b/src/Macros/Str/TelecomNetworkType.php new file mode 100644 index 0000000..938f9f1 --- /dev/null +++ b/src/Macros/Str/TelecomNetworkType.php @@ -0,0 +1,15 @@ +getNetworkType($value); + }; + } +} diff --git a/tests/Feature/RequestTest.php b/tests/Feature/RequestTest.php index 76ca077..d4e8887 100644 --- a/tests/Feature/RequestTest.php +++ b/tests/Feature/RequestTest.php @@ -3,6 +3,7 @@ namespace PyaeSoneAung\LaravelMyanmarTools\Tests\Macro; use Illuminate\Http\Request; +use LaravelMyanmarTools\PhoneNumber\Enums\Network; use PyaeSoneAung\LaravelMyanmarTools\Tests\TestCase; class RequestTest extends TestCase @@ -170,6 +171,15 @@ public function it_can_get_telecom_name() $this->assertEquals(static::MYTEL, $request->telecomName('mytel')); } + /** @test */ + public function it_can_get_telecom_network_type() + { + $request = $this->createRequest([ + 'mpt' => static::MPT_PHONE_NO, + ]); + $this->assertEquals(Network::GSM->getValue(), $request->telecomNetworkType('mpt')); + } + /** @test */ public function it_can_normalize_myanmar_phone_number() { @@ -207,4 +217,58 @@ public function it_can_normalize_nrc() $this->assertEquals(static::NRC_EN, $request->normalizeNrc('nrc_en')); $this->assertEquals(static::NRC_MM, $request->normalizeNrc('nrc_mm', 'mm')); } + + /** @test */ + public function it_can_extract_myanmar_phone_number() + { + $request = $this->createRequest([ + 'text' => 'မောင်မောင်ရဲ့ ဖုန်းနံပါတ်များမှာ ၀၉၂၅၀၀၀၀၀၀၀ နှင့် ၀၉၉၇၀၀၀၀၀၀၀ တို့ဖြစ်ပါသည်။', + ]); + $this->assertEquals([static::MPT_PHONE_NO, static::OOREDOO_PHONE_NO], $request->extractMyanmarPhoneNumber('text')); + } + + /** @test */ + public function it_can_extract_mpt_number() + { + $request = $this->createRequest([ + 'text' => 'မောင်မောင်ရဲ့ ဖုန်းနံပါတ်မှာ 09250000000 ဖြစ်ပါသည်။', + ]); + $this->assertEquals([static::MPT_PHONE_NO], $request->extractMpt('text')); + } + + /** @test */ + public function it_can_extract_ooredoo_number() + { + $request = $this->createRequest([ + 'text' => 'မောင်မောင်ရဲ့ ဖုန်းနံပါတ်မှာ 09970000000 ဖြစ်ပါသည်။', + ]); + $this->assertEquals([static::OOREDOO_PHONE_NO], $request->extractOoredoo('text')); + } + + /** @test */ + public function it_can_extract_telenor_number() + { + $request = $this->createRequest([ + 'text' => 'မောင်မောင်ရဲ့ ဖုန်းနံပါတ်မှာ 09790000000 ဖြစ်ပါသည်။', + ]); + $this->assertEquals([static::TELENOR_PHONE_NO], $request->extractTelenor('text')); + } + + /** @test */ + public function it_can_extract_mec_number() + { + $request = $this->createRequest([ + 'text' => 'မောင်မောင်ရဲ့ ဖုန်းနံပါတ်မှာ 0930000000 ဖြစ်ပါသည်။', + ]); + $this->assertEquals([static::MEC_PHONE_NO], $request->extractMec('text')); + } + + /** @test */ + public function it_can_extract_mytel_number() + { + $request = $this->createRequest([ + 'text' => 'မောင်မောင်ရဲ့ ဖုန်းနံပါတ်မှာ 09690000000 ဖြစ်ပါသည်။', + ]); + $this->assertEquals([static::MYTEL_PHONE_NO], $request->extractMytel('text')); + } } diff --git a/tests/Feature/StrTest.php b/tests/Feature/StrTest.php index 4933af5..4f6b063 100644 --- a/tests/Feature/StrTest.php +++ b/tests/Feature/StrTest.php @@ -3,6 +3,7 @@ namespace PyaeSoneAung\LaravelMyanmarTools\Tests\Macro; use Illuminate\Support\Str; +use LaravelMyanmarTools\PhoneNumber\Enums\Network; use PyaeSoneAung\LaravelMyanmarTools\Tests\TestCase; class StrTest extends TestCase @@ -112,6 +113,12 @@ public function it_can_check_mytel_phone_number() /** @test */ public function it_can_get_telecom_name() + { + $this->assertEquals(Network::GSM->getValue(), Str::telecomNetworkType(static::MPT_PHONE_NO)); + } + + /** @test */ + public function it_can_get_telecom_network_type() { $this->assertEquals(static::MPT, Str::telecomName(static::MPT_PHONE_NO)); $this->assertEquals(static::OOREDOO, Str::telecomName(static::OOREDOO_PHONE_NO)); @@ -142,4 +149,40 @@ public function it_can_normalize_nrc() $this->assertEquals(Str::normalizeNrc('12/OuKaMa(Naing)123456'), static::NRC_EN); $this->assertEquals(Str::normalizeNrc('၁၂/ဥကမ(နိုင်)၁၂၃၄၅၆', 'mm'), static::NRC_MM); } + + /** @test */ + public function it_can_extract_myanmar_phone_number() + { + $this->assertEquals([static::MPT_PHONE_NO, static::OOREDOO_PHONE_NO], Str::extractMyanmarPhoneNumber('မောင်မောင်ရဲ့ ဖုန်းနံပါတ်များမှာ ၀၉၂၅၀၀၀၀၀၀၀ နှင့် ၀၉၉၇၀၀၀၀၀၀၀ တို့ဖြစ်ပါသည်။')); + } + + /** @test */ + public function it_can_extract_mpt_phone_number() + { + $this->assertEquals([static::MPT_PHONE_NO], Str::extractMpt('မောင်မောင်ရဲ့ ဖုန်းနံပါတ်မှာ 09250000000 ဖြစ်ပါသည်။')); + } + + /** @test */ + public function it_can_extract_ooredoo_phone_number() + { + $this->assertEquals([static::OOREDOO_PHONE_NO], Str::extractOoredoo('မောင်မောင်ရဲ့ ဖုန်းနံပါတ်မှာ 09970000000 ဖြစ်ပါသည်။')); + } + + /** @test */ + public function it_can_extract_telenor_phone_number() + { + $this->assertEquals([static::TELENOR_PHONE_NO], Str::extractTelenor('မောင်မောင်ရဲ့ ဖုန်းနံပါတ်မှာ 09790000000 ဖြစ်ပါသည်။')); + } + + /** @test */ + public function it_can_extract_mec_phone_number() + { + $this->assertEquals([static::MEC_PHONE_NO], Str::extractMec('မောင်မောင်ရဲ့ ဖုန်းနံပါတ်မှာ 0930000000 ဖြစ်ပါသည်။')); + } + + /** @test */ + public function it_can_extract_mytel_phone_number() + { + $this->assertEquals([static::MYTEL_PHONE_NO], Str::extractMytel('မောင်မောင်ရဲ့ ဖုန်းနံပါတ်မှာ 09690000000 ဖြစ်ပါသည်။')); + } }