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) |
||
56 | |||
57 | /** |
||
58 | * @return array |
||
59 | */ |
||
60 | private function TKK() |
||
64 | |||
65 | /** |
||
66 | * Process token data by applying multiple operations. |
||
67 | * (Params are safe, no need for multibyte functions) |
||
68 | * |
||
69 | * @param int $a |
||
70 | * @param string $b |
||
71 | * |
||
72 | * @return int |
||
73 | */ |
||
74 | private function RL($a, $b) |
||
85 | |||
86 | /** |
||
87 | * Unsigned right shift implementation |
||
88 | * https://msdn.microsoft.com/en-us/library/342xfs5s(v=vs.94).aspx |
||
89 | * http://stackoverflow.com/a/43359819/2953830 |
||
90 | * |
||
91 | * @param $a |
||
92 | * @param $b |
||
93 | * |
||
94 | * @return number |
||
95 | */ |
||
96 | private function unsignedRightShift($a, $b) |
||
122 | } |
||
123 |
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: