|
4 | 4 |
|
5 | 5 | class Text extends \Faker\Provider\Text |
6 | 6 | { |
7 | | - |
8 | | - /** |
9 | | - * generates text string in arabic |
10 | | - * |
11 | | - * @example ' ولا النوم ولا القرار وكان يقال: لا يجد المريض لذة الطعام والشراب' |
12 | | - * @param integer $maxNbChars |
13 | | - * @param integer $indexSize |
14 | | - * @return string |
15 | | - * @throws \InvalidArgumentException |
16 | | - */ |
17 | | - public function realText($maxNbChars = 200, $indexSize = 2) |
| 7 | + protected static function validStart($word) |
18 | 8 | { |
19 | | - if ($maxNbChars < 10) { |
20 | | - throw new \InvalidArgumentException('maxNbChars must be at least 10'); |
21 | | - } |
22 | | - |
23 | | - if ($indexSize < 1) { |
24 | | - throw new \InvalidArgumentException('indexSize must be at least 1'); |
25 | | - } |
26 | | - |
27 | | - if ($indexSize > 5) { |
28 | | - throw new \InvalidArgumentException('indexSize must be at most 5'); |
29 | | - } |
30 | | - |
31 | | - $words = $this->getConsecutiveWords($indexSize); |
32 | | - $result = array(); |
33 | | - $resultLength = 0; |
34 | | - // take a random starting point |
35 | | - $next = static::randomKey($words); |
36 | | - while ($resultLength < $maxNbChars && isset($words[$next])) { |
37 | | - // fetch a random word to append |
38 | | - $word = static::randomElement($words[$next]); |
39 | | - |
40 | | - // calculate next index |
41 | | - $currentWords = explode(' ', $next); |
42 | | - |
43 | | - $currentWords[] = $word; |
44 | | - array_shift($currentWords); |
45 | | - $next = implode(' ', $currentWords); |
46 | | - |
47 | | - if ($resultLength == 0 && !preg_match('/^\p{Arabic}/u', $word)) { |
48 | | - continue; |
49 | | - } |
50 | | - // append the element |
51 | | - $result[] = $word; |
52 | | - $resultLength += strlen($word) + 1; |
53 | | - } |
54 | | - |
55 | | - // remove the element that caused the text to overflow |
56 | | - array_pop($result); |
57 | | - |
58 | | - // build result |
59 | | - $result = implode(' ', $result); |
60 | | - |
61 | | - return $result.'.'; |
| 9 | + return preg_match('/^\p{Arabic}/u', $word); |
62 | 10 | } |
63 | 11 |
|
64 | 12 | /** |
|
0 commit comments