-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b6f285
commit 549e0a1
Showing
7 changed files
with
25 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -34,67 +32,13 @@ class Utils implements Project | |
* | ||
* @param string $str Chuỗi ký tự đầu vào | ||
* | ||
* @return mixed|null|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($str = '') | ||
{ | ||
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 mixed|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($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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,4 @@ | |
|
||
d($utils->getVersion()); | ||
d($utils::slugify($str)); | ||
d($utils::convert_vi_to_en($str)); | ||
|