Skip to content

Commit

Permalink
Merge pull request #42 from nguyenanhung/v3.x
Browse files Browse the repository at this point in the history
Release v3.x - Version 3.0.6
  • Loading branch information
nguyenanhung authored Sep 25, 2021
2 parents 78b9ea8 + 63f3bfb commit 32a9fa1
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 159 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ $str = 'Nguyễn An Hưng';

d($utils->getVersion()); // show "2.0.5"
d($utils::slugify($str)); // show "nguyen-an-hung"
d($utils::convert_vi_to_en($str)); // show "nguyen-an-hung"

```

## Support
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"ext-mbstring": "*",
"nguyenanhung/benchmark": "^2.0 || ^1.0",
"nguyenanhung/filesystem-helper": "^2.0 || ^1.0",
"monolog/monolog": "^2.0 || ^1.26",
"cocur/slugify": "^4.0"
"nguyenanhung/slug-helper": "^2.0 || ^1.0",
"monolog/monolog": "^2.0 || ^1.26"
},
"require-dev": {
"kint-php/kint": ">=3.0"
Expand Down
4 changes: 2 additions & 2 deletions src/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
interface Project
{
const VERSION = '3.0.5';
const VERSION = '3.0.6';

/**
* Hàm lấy thông tin phiên bản Packages
Expand All @@ -29,5 +29,5 @@ interface Project
* @copyright: 713uk13m <[email protected]>
* @time : 9/27/18 18:32
*/
public function getVersion();
public function getVersion(): string;
}
68 changes: 0 additions & 68 deletions src/Repository/DataRepository.php

This file was deleted.

25 changes: 0 additions & 25 deletions src/Repository/config/convert_vi_to_en.php

This file was deleted.

64 changes: 4 additions & 60 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

namespace nguyenanhung\MyDebug;

use Exception;
use Cocur\Slugify\Slugify;
use nguyenanhung\MyDebug\Repository\DataRepository;
use nguyenanhung\Libraries\Slug\SlugUrl;

/**
* Class Utils
Expand All @@ -34,67 +32,13 @@ class Utils implements Project
*
* @param string $str Chuỗi ký tự đầu vào
*
* @return array|mixed|string|string[] Đầu ra rà 1 chuỗi ký tự
* @return string Đầu ra rà 1 chuỗi ký tự
* @author: 713uk13m <[email protected]>
* @time : 10/9/18 00:31
*
*/
public static function slugify(string $str = '')
public static function slugify(string $str = ''): string
{
if (!class_exists(Slugify::class)) {
if (function_exists('log_message')) {
$message = 'Không tồn tại class Slugify';
log_message('error', $message);
}

return self::convert_vi_to_en($str);
}
try {
$slugify = new Slugify();

return $slugify->slugify($str);
} catch (Exception $e) {
if (function_exists('log_message')) {
log_message('error', 'Error Message: ' . $e->getMessage());
log_message('error', 'Error TraceAsString: ' . $e->getTraceAsString());
}

return self::convert_vi_to_en($str);
}
}

/**
* Function convert_vi_to_en
*
* Hàm chuyển đổi ký tự từ tiếng Việt,
* và các ký tự đặc biệt sang ký tự không dấu
*
* Sử dụng trong trường hợp class slugify nó không chạy
*
* @param string $str Chuỗi ký tự đầu vào
*
* @return array|mixed|string|string[] Đầu ra rà 1 chuỗi ký tự
* @author: 713uk13m <[email protected]>
* @time : 10/13/18 01:17
*
*/
public static function convert_vi_to_en(string $str = '')
{
$str = trim($str);
$str = function_exists('mb_strtolower') ? mb_strtolower($str) : strtolower($str);
$data = DataRepository::getData('convert_vi_to_en');
if (!empty($str)) {
$str = str_replace($data['vn_array'], $data['en_array'], $str);
$str = str_replace($data['special_array'], $data['separator'], $str);
$str = str_replace(' ', $data['separator'], $str);
while (strpos($str, '--') > 0) {
$str = str_replace('--', $data['separator'], $str);
}
while (strpos($str, '--') === 0) {
$str = str_replace('--', $data['separator'], $str);
}
}

return $str;
return (new SlugUrl())->slugify($str);
}
}
2 changes: 1 addition & 1 deletion test/test_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

d($utils->getVersion());
d($utils::slugify($str));
d($utils::convert_vi_to_en($str));

0 comments on commit 32a9fa1

Please sign in to comment.