1 | <?php |
||
11 | class GoogleTokenGenerator implements TokenProviderInterface |
||
12 | { |
||
13 | /** |
||
14 | * Generate and return a token. |
||
15 | * |
||
16 | * @param string $source Source language |
||
17 | * @param string $target Target language |
||
18 | * @param string $text Text to translate |
||
19 | * |
||
20 | * @return mixed A token |
||
21 | */ |
||
22 | public function generateToken($source, $target, $text) |
||
26 | |||
27 | /** |
||
28 | * Generate a valid Google Translate request token. |
||
29 | * |
||
30 | * @param string $a text to translate |
||
31 | * |
||
32 | * @return string |
||
33 | */ |
||
34 | private function TL($a) |
||
73 | |||
74 | /** |
||
75 | * @return array |
||
76 | */ |
||
77 | private function TKK() |
||
81 | |||
82 | /** |
||
83 | * Process token data by applying multiple operations. |
||
84 | * (Params are safe, no need for multibyte functions) |
||
85 | * |
||
86 | * @param int $a |
||
87 | * @param string $b |
||
88 | * |
||
89 | * @return int |
||
90 | */ |
||
91 | private function RL($a, $b) |
||
102 | |||
103 | /** |
||
104 | * Unsigned right shift implementation |
||
105 | * https://msdn.microsoft.com/en-us/library/342xfs5s(v=vs.94).aspx |
||
106 | * http://stackoverflow.com/a/43359819/2953830 |
||
107 | * |
||
108 | * @param $a |
||
109 | * @param $b |
||
110 | * |
||
111 | * @return number |
||
112 | */ |
||
113 | private function unsignedRightShift($a, $b) |
||
139 | |||
140 | /** |
||
141 | * Get JS charCodeAt equivalent result with UTF-16 encoding |
||
142 | * |
||
143 | * @param string $str |
||
144 | * @param int $index |
||
145 | * |
||
146 | * @return number |
||
147 | */ |
||
148 | private function JS_charCodeAt($str, $index) { |
||
152 | |||
153 | /** |
||
154 | * Get JS equivalent string length with UTF-16 encoding |
||
155 | * |
||
156 | * @param string $str |
||
157 | * |
||
158 | * @return number |
||
159 | */ |
||
160 | private function JS_length($str) { |
||
164 | } |
||
165 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: