Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
PyaeSoneAungRgn committed Sep 25, 2023
1 parent 9f11d7a commit 53e83a6
Show file tree
Hide file tree
Showing 25 changed files with 51 additions and 165 deletions.
111 changes: 8 additions & 103 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,17 @@
![Laravel Myanmar Tools Preview](https://repository-images.githubusercontent.com/456939111/b87f140f-f733-4f22-94bb-33dc10fef5f1)

[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/PyaeSoneAungRgn/laravel-myanmar-tools/run-tests.yml?branch=3.x&label=test)](https://github.com/PyaeSoneAungRgn/laravel-myanmar-tools/actions/workflows/run-tests.yml)
[![Packagist Version](https://img.shields.io/packagist/v/pyaesoneaung/laravel-myanmar-tools)](https://packagist.org/packages/pyaesoneaung/laravel-myanmar-tools)
[![Packagist Downloads](https://img.shields.io/packagist/dt/pyaesoneaung/laravel-myanmar-tools)](https://packagist.org/packages/pyaesoneaung/laravel-myanmar-tools)

# Myanmar Tools For Laravel

A package for Myanmar tools which extend Laravel’s core.

- ⚡️ Simple & Powerful
- 🇲🇲 Include Myanmar Font, Phone Number, NRC and Date tools
- ⚙️ Extend Str, Eloquent Builder, Query Builder, Request, Collection, Validator and Carbon
- 🤝 Support Laravel 10.\* | 9.\* | 8.\* | 7.\* | 6.\*

## Installation

```bash
composer require pyaesoneaung/laravel-myanmar-tools
```

## Version Compatibilities

| Laravel | Package |
| ------------- | ------------- |
| 9.x - 10.x | 3.x |
| 6.x - 10.x | 2.x |

## Documentation

📚 Read the full documentation at [laravel-myanmar-tools.com](https://laravel-myanmar-tools.com)

## Basic Usage

Str

```php
use Illuminate\Support\Str;

Str::zgToUni('ျမန္မာျပည္');

// မြန်မာပြည်
```

Eloquent Builder

```php
use App\Models\Customer;

Customer::whereMpt('phone')->first();
```

Request

```php
// https://{domain}.com/{path}?phone=09250000000

$request->telecomName('phone');

// mpt
```

Collection

```php
$data = ['မြန်မာပြည်'];

collect($data)->uniToZg()->toArray();

// ['ျမန္မာျပည္']
```

Validation

```php
$request->validate([
'phone' => ['required', 'mpt'],
]);
```

Carbon

```php
use Illuminate\Support\Carbon;

Carbon::parse('2023-07-19')->isMartyrsDay();

// true
```

And more...

📚 Checkout the full documentation at [laravel-myanmar-tools.com](https://laravel-myanmar-tools.com)

## Testing

```bash
composer test
```

## Credits
## Introduction

- [A set of useful Laravel collection macros](https://github.com/spatie/laravel-collection-macros)
- [myanmar-phone-number-php](https://github.com/johnreginald/myanmar-phone-number-php)
- [Myanmar Tools (Zawgyi detection & conversion)](https://github.com/google/myanmar-tools)
- [Rabbit-PHP](https://github.com/Rabbit-Converter/Rabbit-PHP)
- [NRCPrefix](https://github.com/greenlikeorange/NRCPrefix)
A package for Myanmar tools which extend Laravel's core.

## Official Documentation

## Thanks JetBrains
Documentation for Laravel Myanmar Tools can be found on the [laravelmyanmartools.com](https://www.laravel-myanmar-tools.com/).

<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" width="100"></a>
## License

JetBrains support Myanmar Tools For Laravel by providing [Open Source License](https://www.jetbrains.com/community/opensource/#support).
Laravel Myanmar Tools is open-sourced software licensed under the MIT license.
10 changes: 9 additions & 1 deletion src/Helpers/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PyaeSoneAung\LaravelMyanmarTools\Helpers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use PyaeSoneAung\LaravelMyanmarTools\Exceptions\UnsupportedDatabaseDriver;

class Database
Expand All @@ -12,7 +13,7 @@ public static function getRegexOpreator(): string
$driver = DB::getDriverName();
$supporrtedDrivers = [
'mysql',
'pgsql'
'pgsql',
];

if (! in_array($driver, $supporrtedDrivers)) {
Expand All @@ -23,4 +24,11 @@ public static function getRegexOpreator(): string
? '~'
: 'REGEXP';
}

public static function sanitizeRegex(string $val): string
{
return Str::of($val)
->replaceFirst('/', '')
->replaceLast('/', '');
}
}
15 changes: 0 additions & 15 deletions src/Helpers/RegularExpression.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Macros/Collection/UniToZg.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class UniToZg
{
public function __invoke()
{
return function (?string $key = null): Collection {
return function (string $key = null): Collection {
/** @var \Illuminate\Support\Collection $this */
return $this->map(function ($item) use ($key) {
if ($key) {
Expand Down
2 changes: 1 addition & 1 deletion src/Macros/Collection/WhereMec.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WhereMec
{
public function __invoke()
{
return function (?string $key = null): Collection {
return function (string $key = null): Collection {
/** @var \Illuminate\Support\Collection $this */
return $this->filter(function ($item) use ($key) {
if ($key) {
Expand Down
2 changes: 1 addition & 1 deletion src/Macros/Collection/WhereMpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WhereMpt
{
public function __invoke()
{
return function (?string $key = null): Collection {
return function (string $key = null): Collection {
/** @var \Illuminate\Support\Collection $this */
return $this->filter(function ($item) use ($key) {
if ($key) {
Expand Down
2 changes: 1 addition & 1 deletion src/Macros/Collection/WhereMyanmarPhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WhereMyanmarPhoneNumber
{
public function __invoke()
{
return function (?string $key = null): Collection {
return function (string $key = null): Collection {
/** @var \Illuminate\Support\Collection $this */
return $this->filter(function ($item) use ($key) {
if ($key) {
Expand Down
2 changes: 1 addition & 1 deletion src/Macros/Collection/WhereMytel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WhereMytel
{
public function __invoke()
{
return function (?string $key = null): Collection {
return function (string $key = null): Collection {
/** @var \Illuminate\Support\Collection $this */
return $this->filter(function ($item) use ($key) {
if ($key) {
Expand Down
2 changes: 1 addition & 1 deletion src/Macros/Collection/WhereOoredoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WhereOoredoo
{
public function __invoke()
{
return function (?string $key = null): Collection {
return function (string $key = null): Collection {
/** @var \Illuminate\Support\Collection $this */
return $this->filter(function ($item) use ($key) {
if ($key) {
Expand Down
2 changes: 1 addition & 1 deletion src/Macros/Collection/WhereTelenor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WhereTelenor
{
public function __invoke()
{
return function (?string $key = null): Collection {
return function (string $key = null): Collection {
/** @var \Illuminate\Support\Collection $this */
return $this->filter(function ($item) use ($key) {
if ($key) {
Expand Down
2 changes: 1 addition & 1 deletion src/Macros/Collection/ZgToUni.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ZgToUni
{
public function __invoke()
{
return function (?string $key = null): Collection {
return function (string $key = null): Collection {
/** @var \Illuminate\Support\Collection $this */
return $this->map(function ($item) use ($key) {
if ($key) {
Expand Down
3 changes: 1 addition & 2 deletions src/Macros/Eloquent/WhereMec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Database\Eloquent\Builder;
use LaravelMyanmarTools\PhoneNumber\Enums\Telecom;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\RegularExpression;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\Database;

class WhereMec
Expand All @@ -16,7 +15,7 @@ public function __invoke()
return $this->where(
$column,
Database::getRegexOpreator(),
RegularExpression::sanitize(Telecom::MEC->getRegex())
Database::sanitizeRegex(Telecom::MEC->getRegex())
);
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/Macros/Eloquent/WhereMpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Database\Eloquent\Builder;
use LaravelMyanmarTools\PhoneNumber\Enums\Telecom;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\RegularExpression;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\Database;

class WhereMpt
Expand All @@ -16,7 +15,7 @@ public function __invoke()
return $this->where(
$column,
Database::getRegexOpreator(),
RegularExpression::sanitize(Telecom::MPT->getRegex())
Database::sanitizeRegex(Telecom::MPT->getRegex())
);
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/Macros/Eloquent/WhereMyanmarPhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Database\Eloquent\Builder;
use LaravelMyanmarTools\PhoneNumber\Enums\Telecom;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\RegularExpression;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\Database;

class WhereMyanmarPhoneNumber
Expand All @@ -16,7 +15,7 @@ public function __invoke()
return $this->where(
$column,
Database::getRegexOpreator(),
RegularExpression::sanitize(Telecom::ALL->getRegex())
Database::sanitizeRegex(Telecom::ALL->getRegex())
);
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/Macros/Eloquent/WhereMytel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Database\Eloquent\Builder;
use LaravelMyanmarTools\PhoneNumber\Enums\Telecom;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\RegularExpression;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\Database;

class WhereMytel
Expand All @@ -16,7 +15,7 @@ public function __invoke()
return $this->where(
$column,
Database::getRegexOpreator(),
RegularExpression::sanitize(Telecom::MYTEL->getRegex())
Database::sanitizeRegex(Telecom::MYTEL->getRegex())
);
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/Macros/Eloquent/WhereOoredoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Database\Eloquent\Builder;
use LaravelMyanmarTools\PhoneNumber\Enums\Telecom;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\RegularExpression;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\Database;

class WhereOoredoo
Expand All @@ -16,7 +15,7 @@ public function __invoke()
return $this->where(
$column,
Database::getRegexOpreator(),
RegularExpression::sanitize(Telecom::OOREDOO->getRegex())
Database::sanitizeRegex(Telecom::OOREDOO->getRegex())
);
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/Macros/Eloquent/WhereTelenor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Database\Eloquent\Builder;
use LaravelMyanmarTools\PhoneNumber\Enums\Telecom;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\RegularExpression;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\Database;

class WhereTelenor
Expand All @@ -16,7 +15,7 @@ public function __invoke()
return $this->where(
$column,
Database::getRegexOpreator(),
RegularExpression::sanitize(Telecom::TELENOR->getRegex())
Database::sanitizeRegex(Telecom::TELENOR->getRegex())
);
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/Macros/Query/WhereMec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Database\Query\Builder;
use LaravelMyanmarTools\PhoneNumber\Enums\Telecom;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\RegularExpression;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\Database;

class WhereMec
Expand All @@ -16,7 +15,7 @@ public function __invoke()
return $this->where(
$column,
Database::getRegexOpreator(),
RegularExpression::sanitize(Telecom::MEC->getRegex())
Database::sanitizeRegex(Telecom::MEC->getRegex())
);
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/Macros/Query/WhereMpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Database\Query\Builder;
use LaravelMyanmarTools\PhoneNumber\Enums\Telecom;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\RegularExpression;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\Database;

class WhereMpt
Expand All @@ -16,7 +15,7 @@ public function __invoke()
return $this->where(
$column,
Database::getRegexOpreator(),
RegularExpression::sanitize(Telecom::MPT->getRegex())
Database::sanitizeRegex(Telecom::MPT->getRegex())
);
};
}
Expand Down
3 changes: 1 addition & 2 deletions src/Macros/Query/WhereMyanmarPhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Database\Query\Builder;
use LaravelMyanmarTools\PhoneNumber\Enums\Telecom;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\RegularExpression;
use PyaeSoneAung\LaravelMyanmarTools\Helpers\Database;

class WhereMyanmarPhoneNumber
Expand All @@ -16,7 +15,7 @@ public function __invoke()
return $this->where(
$column,
Database::getRegexOpreator(),
RegularExpression::sanitize(Telecom::ALL->getRegex())
Database::sanitizeRegex(Telecom::ALL->getRegex())
);
};
}
Expand Down
Loading

0 comments on commit 53e83a6

Please sign in to comment.