Completed
Branch master (e11b09)
by Jakub
07:16
created
src/Bridges/NetteApplication/IAppRequestAwareLocaleResolver.php 1 patch
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -11,6 +11,10 @@
 block discarded – undo
11 11
  * @author Jakub Konečný
12 12
  */
13 13
 interface IAppRequestAwareLocaleResolver extends ILocaleResolver {
14
+
15
+  /**
16
+   * @return void
17
+   */
14 18
   function onRequest(Application $application, Request $request);
15 19
 }
16 20
 ?>
17 21
\ No newline at end of file
Please login to merge, or discard this patch.
src/Loaders/ILoader.php 2 patches
Doc Comments   +8 added lines patch added patch discarded remove patch
@@ -10,8 +10,16 @@
 block discarded – undo
10 10
  */
11 11
 interface ILoader {
12 12
   function getLang(): string;
13
+
14
+  /**
15
+   * @return void
16
+   */
13 17
   function setLang(string $lang);
14 18
   function getDefaultLang(): string;
19
+
20
+  /**
21
+   * @return void
22
+   */
15 23
   function setDefaultLang(string $defaultLang);
16 24
   function getResources(): array;
17 25
   function getTexts(): array;
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Translation\Loaders;
5 5
 
Please login to merge, or discard this patch.
src/Resolvers/ILoaderAwareLocaleResolver.php 1 patch
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -11,6 +11,7 @@
 block discarded – undo
11 11
 interface ILoaderAwareLocaleResolver extends ILocaleResolver {
12 12
   /**
13 13
    * Inject loader
14
+   * @return void
14 15
    */
15 16
   function setLoader(ILoader $loader): void;
16 17
 }
Please login to merge, or discard this patch.
src/Resolvers/ManualLocaleResolver.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Translation\Resolvers;
5 5
 
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
   /** @var string|NULL */
17 17
   protected $lang = NULL;
18 18
   
19
-  function getLang(): ?string {
19
+  function getLang(): ? string {
20 20
     return $this->lang;
21 21
   }
22 22
   
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     $this->lang = $lang;
25 25
   }
26 26
   
27
-  function resolve(): ?string {
27
+  function resolve(): ? string {
28 28
     return $this->getLang();
29 29
   }
30 30
 }
Please login to merge, or discard this patch.
src/Resolvers/ChainLocaleResolver.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Translation\Resolvers;
5 5
 
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
     $this[] = $resolver;
22 22
   }
23 23
   
24
-  function resolve(): ?string {
25
-    foreach($this as $resolver) {
24
+  function resolve(): ? string {
25
+    foreach ($this as $resolver) {
26 26
       $lang = $resolver->resolve();
27
-      if(!is_null($lang)) {
27
+      if (!is_null($lang)) {
28 28
         return $lang;
29 29
       }
30 30
     }
Please login to merge, or discard this patch.
src/Resolvers/EnvironmentLocaleResolver.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Translation\Resolvers;
5 5
 
@@ -17,9 +17,9 @@  discard block
 block discarded – undo
17 17
   /** @var string */
18 18
   protected $varName = "TRANSLATOR_LANGUAGE";
19 19
   
20
-  function getLang(): ?string {
20
+  function getLang(): ? string {
21 21
     $lang = getenv($this->varName);
22
-    if($lang) {
22
+    if ($lang) {
23 23
       return $lang;
24 24
     }
25 25
     return NULL;
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     $this->varName = $varName;
38 38
   }
39 39
   
40
-  function resolve(): ?string {
40
+  function resolve(): ? string {
41 41
     return $this->getLang();
42 42
   }
43 43
 }
Please login to merge, or discard this patch.
src/Resolvers/SessionLocaleResolver.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Translation\Resolvers;
5 5
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
   protected $varName = "lang";
27 27
   
28 28
   function __construct(Session $session = NULL) {
29
-    if(is_null($session)) {
29
+    if (is_null($session)) {
30 30
       $request = (new RequestFactory)->createHttpRequest();
31 31
       $response = new Response;
32 32
       $session = new Session($request, $response);
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
     $this->section = $session->getSection(get_class($this));
36 36
   }
37 37
   
38
-  function getLang(): ?string {
39
-    if(empty($this->section->{$this->varName})) {
38
+  function getLang(): ? string {
39
+    if (empty($this->section->{$this->varName})) {
40 40
       return NULL;
41 41
     }
42 42
     return $this->section->{$this->varName};
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
   /**
58 58
    * Resolve language
59 59
    */
60
-  function resolve(): ?string {
60
+  function resolve(): ? string {
61 61
     return $this->getLang();
62 62
   }
63 63
 }
Please login to merge, or discard this patch.
src/Resolvers/HeaderLocaleResolver.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Translation\Resolvers;
5 5
 
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
   protected $request;
23 23
   
24 24
   function __construct(IRequest $request = NULL) {
25
-    if(is_null($request)) {
25
+    if (is_null($request)) {
26 26
       $request = (new RequestFactory)->createHttpRequest();
27 27
     }
28 28
     $this->request = $request;
@@ -38,28 +38,28 @@  discard block
 block discarded – undo
38 38
    * Taken from Nette\Http\Request::detectLanguage()
39 39
    * @author David Grudl
40 40
    */
41
-  function resolve(): ?string {
42
-    if(is_null($this->loader)) {
41
+  function resolve(): ? string {
42
+    if (is_null($this->loader)) {
43 43
       throw new LoaderNotSetException("Loader is not available, cannot detect possible languages.");
44 44
     }
45 45
     $header = $this->request->getHeader("Accept-Language");
46 46
     $langs = $this->loader->getAvailableLanguages();
47
-    if(is_null($header)) {
47
+    if (is_null($header)) {
48 48
       return NULL;
49 49
     }
50
-    $s = strtolower($header);  // case insensitive
51
-    $s = strtr($s, '_', '-');  // cs_CZ means cs-CZ
52
-    rsort($langs);             // first more specific
50
+    $s = strtolower($header); // case insensitive
51
+    $s = strtr($s, '_', '-'); // cs_CZ means cs-CZ
52
+    rsort($langs); // first more specific
53 53
     $pattern = ')(?:-[^\s,;=]+)?\s*(?:;\s*q=([0-9.]+))?#';
54 54
     preg_match_all('#(' . implode('|', $langs) . $pattern, $s, $matches);
55
-    if(!$matches[0]) {
55
+    if (!$matches[0]) {
56 56
       return NULL;
57 57
     }
58 58
     $max = 0;
59 59
     $lang = NULL;
60
-    foreach($matches[1] as $key => $value) {
60
+    foreach ($matches[1] as $key => $value) {
61 61
       $q = ($matches[2][$key] === '') ? 1.0 : (float) $matches[2][$key];
62
-      if($q > $max) {
62
+      if ($q > $max) {
63 63
         $max = $q;
64 64
         $lang = $value;
65 65
       }
Please login to merge, or discard this patch.
src/Resolvers/FallbackLocaleResolver.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(strict_types=1);
2
+declare(strict_types = 1);
3 3
 
4 4
 namespace Nexendrie\Translation\Resolvers;
5 5
 
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
    *
19 19
    * @return NULL
20 20
    */
21
-  function resolve(): ?string {
21
+  function resolve(): ? string {
22 22
     return NULL;
23 23
   }
24 24
 }
Please login to merge, or discard this patch.