1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the mucts/laravel-pinyin. |
4
|
|
|
* |
5
|
|
|
* This source file is subject to the MIT license that is bundled |
6
|
|
|
* with this source code in the file LICENSE. |
7
|
|
|
* |
8
|
|
|
* @version 1.0 |
9
|
|
|
* @author herry<[email protected]> |
10
|
|
|
* @copyright © 2020 MuCTS.com All Rights Reserved. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use MuCTS\Laravel\Pinyin\Facades\Pinyin; |
15
|
|
|
use MuCTS\Pinyin\Interfaces\DictLoader; |
16
|
|
|
|
17
|
|
|
if (!function_exists('pinyin')) { |
18
|
|
|
/** |
19
|
|
|
* Get the Pinyin of given string. |
20
|
|
|
* |
21
|
|
|
* @param string $str |
22
|
|
|
* @param int $option |
23
|
|
|
* @param DictLoader|string $loader |
24
|
|
|
* @return array |
25
|
|
|
* @author herry<[email protected]> |
26
|
|
|
*/ |
27
|
|
|
function pinyin(string $str, int $option = \MuCTS\Pinyin\Pinyin::DEFAULT, $loader = null) |
28
|
|
|
{ |
29
|
|
|
return Pinyin::setLoader($loader)->convert($str, $option); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
if (!function_exists('pinyin_abbr')) { |
34
|
|
|
/** |
35
|
|
|
* Get the fist letters of given string. |
36
|
|
|
* |
37
|
|
|
* @param string $str |
38
|
|
|
* @param string|int $delimiter |
39
|
|
|
* @param int $option |
40
|
|
|
* @param DictLoader|string|null $loader |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
function pinyin_abbr(string $str, $delimiter = '', int $option = \MuCTS\Pinyin\Pinyin::DEFAULT, $loader = null) |
44
|
|
|
{ |
45
|
|
|
return Pinyin::setLoader($loader)->abbr($str, $delimiter, $option); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
if (!function_exists('pinyin_permalink')) { |
51
|
|
|
/** |
52
|
|
|
* Get a pinyin permalink from string. |
53
|
|
|
* @param string $str |
54
|
|
|
* @param string|int $delimiter |
55
|
|
|
* @param int $option |
56
|
|
|
* @param DictLoader|string|null $loader |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
function pinyin_permalink(string $str, $delimiter = '-', int $option = \MuCTS\Pinyin\Pinyin::DEFAULT, $loader = null): string |
60
|
|
|
{ |
61
|
|
|
return Pinyin::setLoader($loader)->permalink($str, $delimiter, $option); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (!function_exists('pinyin_sentence')) { |
66
|
|
|
/** |
67
|
|
|
* Get the fist pinyin and letters of given string. |
68
|
|
|
* |
69
|
|
|
* @param string $string |
70
|
|
|
* @param string|int $delimiter |
71
|
|
|
* @param int $option |
72
|
|
|
* @param DictLoader|string|null $loader |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
function pinyin_sentence($string, $delimiter = ' ', $option = \MuCTS\Pinyin\Pinyin::NO_TONE, $loader = null) |
76
|
|
|
{ |
77
|
|
|
return Pinyin::setLoader($loader)->sentence($string, $delimiter, $option); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
if (!function_exists('pinyin_name')) { |
82
|
|
|
/** |
83
|
|
|
* Convert string (person name) to pinyin. |
84
|
|
|
* |
85
|
|
|
* @param string $string |
86
|
|
|
* @param int $option |
87
|
|
|
* @param DictLoader|string|null $loader |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
function pinyin_name(string $string, int $option = \MuCTS\Pinyin\Pinyin::NAME, $loader = null) |
91
|
|
|
{ |
92
|
|
|
return Pinyin::setLoader($loader)->name($string, $option); |
93
|
|
|
} |
94
|
|
|
} |