1 | <?php |
||
26 | class Pinyin |
||
27 | { |
||
28 | const NONE = 'none'; |
||
29 | const ASCII = 'ascii'; |
||
30 | const UNICODE = 'unicode'; |
||
31 | |||
32 | /** |
||
33 | * Dict loader. |
||
34 | * |
||
35 | * @var \Overtrue\Pinyin\DictLoaderInterface |
||
36 | */ |
||
37 | protected $loader; |
||
38 | |||
39 | /** |
||
40 | * Punctuations map. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $punctuations = array( |
||
45 | ',' => ',', |
||
46 | '。' => '.', |
||
47 | '!' => '!', |
||
48 | '?' => '?', |
||
49 | ':' => ':', |
||
50 | '“' => '"', |
||
51 | '”' => '"', |
||
52 | '‘' => "'", |
||
53 | '’' => "'", |
||
54 | ); |
||
55 | |||
56 | /** |
||
57 | * Constructor. |
||
58 | * |
||
59 | * @param \Overtrue\Pinyin\DictLoaderInterface $loader |
||
60 | */ |
||
61 | 10 | public function __construct(DictLoaderInterface $loader = null) |
|
65 | |||
66 | /** |
||
67 | * Convert string to pinyin. |
||
68 | * |
||
69 | * @param string $string |
||
70 | * @param string $option |
||
71 | * |
||
72 | * @return array |
||
73 | */ |
||
74 | 4 | public function convert($string, $option = self::NONE) |
|
80 | |||
81 | /** |
||
82 | * Convert string (person name) to pinyin. |
||
83 | * |
||
84 | * @param string $stringName |
||
85 | * @param string $option |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | 1 | public function name($stringName, $option = self::NONE) |
|
95 | |||
96 | /** |
||
97 | * Return a pinyin permalink from string. |
||
98 | * |
||
99 | * @param string $string |
||
100 | * @param string $delimiter |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 1 | public function permalink($string, $delimiter = '-') |
|
105 | { |
||
106 | 1 | if (!in_array($delimiter, array('_', '-', '.', ''), true)) { |
|
107 | 1 | throw new InvalidArgumentException("Delimiter must be one of: '_', '-', '', '.'."); |
|
108 | } |
||
109 | |||
110 | 1 | return implode($delimiter, $this->convert($string, false)); |
|
|
|||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Return first letters. |
||
115 | * |
||
116 | * @param string $string |
||
117 | * @param string $delimiter |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | 1 | public function abbr($string, $delimiter = '') |
|
127 | |||
128 | /** |
||
129 | * Chinese to pinyin sentense. |
||
130 | * |
||
131 | * @param string $sentence |
||
132 | * @param string $option |
||
133 | * |
||
134 | * @return string |
||
135 | */ |
||
136 | 5 | public function sentence($sentence, $withTone = false) |
|
149 | |||
150 | /** |
||
151 | * Loader setter. |
||
152 | * |
||
153 | * @param \Overtrue\Pinyin\DictLoaderInterface $loader |
||
154 | * |
||
155 | * @return $this |
||
156 | */ |
||
157 | 1 | public function setLoader(DictLoaderInterface $loader) |
|
163 | |||
164 | /** |
||
165 | * Return dict loader,. |
||
166 | * |
||
167 | * @return \Overtrue\Pinyin\DictLoaderInterface |
||
168 | */ |
||
169 | 10 | public function getLoader() |
|
173 | |||
174 | /** |
||
175 | * Preprocess. |
||
176 | * |
||
177 | * @param string $string |
||
178 | * |
||
179 | * @return string |
||
180 | */ |
||
181 | 10 | protected function prepare($string) |
|
189 | |||
190 | /** |
||
191 | * Convert Chinese to pinyin. |
||
192 | * |
||
193 | * @param string $string |
||
194 | * @param bool $isName |
||
195 | * |
||
196 | * @return string |
||
197 | */ |
||
198 | 10 | protected function romanize($string, $isName = false) |
|
214 | |||
215 | /** |
||
216 | * Convert Chinese Surname to pinyin. |
||
217 | * |
||
218 | * @param string $string |
||
219 | * @param \Overtrue\Pinyin\DictLoaderInterface $dictLoader |
||
220 | * |
||
221 | * @return string |
||
222 | */ |
||
223 | protected function convertSurname($string, $dictLoader) { |
||
235 | |||
236 | /** |
||
237 | * Split pinyin string to words. |
||
238 | * |
||
239 | * @param string $pinyin |
||
240 | * @param string $option |
||
241 | * |
||
242 | * @return array |
||
243 | */ |
||
244 | 5 | public function splitWords($pinyin, $option) |
|
256 | |||
257 | /** |
||
258 | * Format. |
||
259 | * |
||
260 | * @param string $pinyin |
||
261 | * @param bool $tone |
||
262 | * |
||
263 | * @return string |
||
264 | */ |
||
265 | 8 | protected function format($pinyin, $tone = false) |
|
283 | } |
||
284 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: