@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | */ |
27 | 27 | private function getHostFromServer(array &$aURL, string $sKey) |
28 | 28 | { |
29 | - if(empty($aURL['host']) && !empty($_SERVER[$sKey])) |
|
29 | + if (empty($aURL['host']) && !empty($_SERVER[$sKey])) |
|
30 | 30 | { |
31 | - if(strpos($_SERVER[$sKey], ':') > 0) |
|
31 | + if (strpos($_SERVER[$sKey], ':') > 0) |
|
32 | 32 | { |
33 | 33 | list($aURL['host'], $aURL['port']) = explode(':', $_SERVER[$sKey]); |
34 | 34 | } |
@@ -49,16 +49,16 @@ discard block |
||
49 | 49 | { |
50 | 50 | $aURL = []; |
51 | 51 | // Try to get the request URL |
52 | - if(!empty($_SERVER['REQUEST_URI'])) |
|
52 | + if (!empty($_SERVER['REQUEST_URI'])) |
|
53 | 53 | { |
54 | 54 | $_SERVER['REQUEST_URI'] = str_replace(['"', "'", '<', '>'], ['%22', '%27', '%3C', '%3E'], $_SERVER['REQUEST_URI']); |
55 | 55 | $aURL = parse_url($_SERVER['REQUEST_URI']); |
56 | 56 | } |
57 | 57 | |
58 | 58 | // Fill in the empty values |
59 | - if(empty($aURL['scheme'])) |
|
59 | + if (empty($aURL['scheme'])) |
|
60 | 60 | { |
61 | - if(!empty($_SERVER['HTTP_SCHEME'])) |
|
61 | + if (!empty($_SERVER['HTTP_SCHEME'])) |
|
62 | 62 | { |
63 | 63 | $aURL['scheme'] = $_SERVER['HTTP_SCHEME']; |
64 | 64 | } |
@@ -71,24 +71,24 @@ discard block |
||
71 | 71 | $this->getHostFromServer($aURL, 'HTTP_X_FORWARDED_HOST'); |
72 | 72 | $this->getHostFromServer($aURL, 'HTTP_HOST'); |
73 | 73 | $this->getHostFromServer($aURL, 'SERVER_NAME'); |
74 | - if(empty($aURL['host'])) |
|
74 | + if (empty($aURL['host'])) |
|
75 | 75 | { |
76 | 76 | throw new Error(); |
77 | 77 | } |
78 | 78 | |
79 | - if(empty($aURL['port']) && !empty($_SERVER['SERVER_PORT'])) |
|
79 | + if (empty($aURL['port']) && !empty($_SERVER['SERVER_PORT'])) |
|
80 | 80 | { |
81 | 81 | $aURL['port'] = $_SERVER['SERVER_PORT']; |
82 | 82 | } |
83 | 83 | |
84 | - if(!empty($aURL['path']) && strlen(basename($aURL['path'])) == 0) |
|
84 | + if (!empty($aURL['path']) && strlen(basename($aURL['path'])) == 0) |
|
85 | 85 | { |
86 | 86 | unset($aURL['path']); |
87 | 87 | } |
88 | 88 | |
89 | - if(empty($aURL['path'])) |
|
89 | + if (empty($aURL['path'])) |
|
90 | 90 | { |
91 | - if(!empty($_SERVER['PATH_INFO'])) |
|
91 | + if (!empty($_SERVER['PATH_INFO'])) |
|
92 | 92 | { |
93 | 93 | $sPath = parse_url($_SERVER['PATH_INFO']); |
94 | 94 | } |
@@ -96,29 +96,29 @@ discard block |
||
96 | 96 | { |
97 | 97 | $sPath = parse_url($_SERVER['PHP_SELF']); |
98 | 98 | } |
99 | - if(isset($sPath['path'])) |
|
99 | + if (isset($sPath['path'])) |
|
100 | 100 | { |
101 | 101 | $aURL['path'] = str_replace(['"', "'", '<', '>'], ['%22', '%27', '%3C', '%3E'], $sPath['path']); |
102 | 102 | } |
103 | 103 | unset($sPath); |
104 | 104 | } |
105 | 105 | |
106 | - if(empty($aURL['query'])) |
|
106 | + if (empty($aURL['query'])) |
|
107 | 107 | { |
108 | 108 | $aURL['query'] = empty($_SERVER['QUERY_STRING']) ? '' : $_SERVER['QUERY_STRING']; |
109 | 109 | } |
110 | 110 | |
111 | - if(!empty($aURL['query'])) |
|
111 | + if (!empty($aURL['query'])) |
|
112 | 112 | { |
113 | 113 | $aURL['query'] = '?' . $aURL['query']; |
114 | 114 | } |
115 | 115 | |
116 | 116 | // Build the URL: Start with scheme, user and pass |
117 | 117 | $sURL = $aURL['scheme'] . '://'; |
118 | - if(!empty($aURL['user'])) |
|
118 | + if (!empty($aURL['user'])) |
|
119 | 119 | { |
120 | 120 | $sURL .= $aURL['user']; |
121 | - if(!empty($aURL['pass'])) |
|
121 | + if (!empty($aURL['pass'])) |
|
122 | 122 | { |
123 | 123 | $sURL .= ':' . $aURL['pass']; |
124 | 124 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $sURL .= $aURL['host']; |
130 | 130 | |
131 | 131 | // Add the port if needed |
132 | - if(!empty($aURL['port']) && |
|
132 | + if (!empty($aURL['port']) && |
|
133 | 133 | (($aURL['scheme'] == 'http' && $aURL['port'] != 80) || |
134 | 134 | ($aURL['scheme'] == 'https' && $aURL['port'] != 443))) |
135 | 135 | { |
@@ -144,13 +144,13 @@ discard block |
||
144 | 144 | |
145 | 145 | $aURL = explode("?", $sURL); |
146 | 146 | |
147 | - if(1 < count($aURL)) |
|
147 | + if (1 < count($aURL)) |
|
148 | 148 | { |
149 | 149 | $aQueries = explode("&", $aURL[1]); |
150 | 150 | |
151 | - foreach($aQueries as $sKey => $sQuery) |
|
151 | + foreach ($aQueries as $sKey => $sQuery) |
|
152 | 152 | { |
153 | - if("jxnGenerate" == substr($sQuery, 0, 11)) |
|
153 | + if ("jxnGenerate" == substr($sQuery, 0, 11)) |
|
154 | 154 | { |
155 | 155 | unset($aQueries[$sKey]); |
156 | 156 | } |
@@ -34,13 +34,13 @@ |
||
34 | 34 | public static function read(string $sConfigFile) |
35 | 35 | { |
36 | 36 | $sConfigFile = realpath($sConfigFile); |
37 | - if(!is_readable($sConfigFile)) |
|
37 | + if (!is_readable($sConfigFile)) |
|
38 | 38 | { |
39 | 39 | throw new Exception\FileAccess($sConfigFile); |
40 | 40 | } |
41 | 41 | $sFileContent = file_get_contents($sConfigFile); |
42 | 42 | $aConfigOptions = json_decode($sFileContent, true); |
43 | - if(!is_array($aConfigOptions)) |
|
43 | + if (!is_array($aConfigOptions)) |
|
44 | 44 | { |
45 | 45 | throw new Exception\FileContent($sConfigFile); |
46 | 46 | } |
@@ -32,12 +32,12 @@ |
||
32 | 32 | public static function read(string $sConfigFile) |
33 | 33 | { |
34 | 34 | $sConfigFile = realpath($sConfigFile); |
35 | - if(!is_readable($sConfigFile)) |
|
35 | + if (!is_readable($sConfigFile)) |
|
36 | 36 | { |
37 | 37 | throw new Exception\FileAccess($sConfigFile); |
38 | 38 | } |
39 | 39 | $aConfigOptions = include($sConfigFile); |
40 | - if(!is_array($aConfigOptions)) |
|
40 | + if (!is_array($aConfigOptions)) |
|
41 | 41 | { |
42 | 42 | throw new Exception\FileContent($sConfigFile); |
43 | 43 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function __construct(array $aOptions = [], string $sKeys = '') |
48 | 48 | { |
49 | - if(count($aOptions) > 0) |
|
49 | + if (count($aOptions) > 0) |
|
50 | 50 | { |
51 | 51 | $this->setOptions($aOptions, $sKeys); |
52 | 52 | } |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | $sPrefix = trim((string)$sPrefix); |
81 | 81 | $nDepth = intval($nDepth); |
82 | 82 | // Check the max depth |
83 | - if($nDepth < 0 || $nDepth > 9) |
|
83 | + if ($nDepth < 0 || $nDepth > 9) |
|
84 | 84 | { |
85 | 85 | throw new Exception\DataDepth($sPrefix, $nDepth); |
86 | 86 | } |
87 | - foreach($aOptions as $sName => $xOption) |
|
87 | + foreach ($aOptions as $sName => $xOption) |
|
88 | 88 | { |
89 | - if(is_int($sName)) |
|
89 | + if (is_int($sName)) |
|
90 | 90 | { |
91 | 91 | continue; |
92 | 92 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | // Save the value of this option |
97 | 97 | $this->aOptions[$sFullName] = $xOption; |
98 | 98 | // Save the values of its sub-options |
99 | - if(is_array($xOption)) |
|
99 | + if (is_array($xOption)) |
|
100 | 100 | { |
101 | 101 | // Recursively read the options in the array |
102 | 102 | $this->_setOptions($xOption, $sFullName, $nDepth + 1); |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | { |
118 | 118 | // Find the config array in the input data |
119 | 119 | $aKeys = explode('.', (string)$sKeys); |
120 | - foreach($aKeys as $sKey) |
|
120 | + foreach ($aKeys as $sKey) |
|
121 | 121 | { |
122 | - if(($sKey)) |
|
122 | + if (($sKey)) |
|
123 | 123 | { |
124 | - if(!array_key_exists($sKey, $aOptions) || !is_array($aOptions[$sKey])) |
|
124 | + if (!array_key_exists($sKey, $aOptions) || !is_array($aOptions[$sKey])) |
|
125 | 125 | { |
126 | 126 | return $this; |
127 | 127 | } |
@@ -170,14 +170,13 @@ discard block |
||
170 | 170 | $sPrefix = rtrim(trim($sPrefix), '.') . '.'; |
171 | 171 | $sPrefixLen = strlen($sPrefix); |
172 | 172 | $aOptions = []; |
173 | - foreach($this->aOptions as $sName => $xValue) |
|
173 | + foreach ($this->aOptions as $sName => $xValue) |
|
174 | 174 | { |
175 | - if(substr($sName, 0, $sPrefixLen) == $sPrefix) |
|
175 | + if (substr($sName, 0, $sPrefixLen) == $sPrefix) |
|
176 | 176 | { |
177 | 177 | $iNextDotPos = strpos($sName, '.', $sPrefixLen); |
178 | 178 | $sOptionName = $iNextDotPos === false ? |
179 | - substr($sName, $sPrefixLen) : |
|
180 | - substr($sName, $sPrefixLen, $iNextDotPos - $sPrefixLen); |
|
179 | + substr($sName, $sPrefixLen) : substr($sName, $sPrefixLen, $iNextDotPos - $sPrefixLen); |
|
181 | 180 | $aOptions[$sOptionName] = $sPrefix . $sOptionName; |
182 | 181 | } |
183 | 182 | } |
@@ -35,16 +35,16 @@ |
||
35 | 35 | public static function read(string $sConfigFile) |
36 | 36 | { |
37 | 37 | $sConfigFile = realpath($sConfigFile); |
38 | - if(!extension_loaded('yaml')) |
|
38 | + if (!extension_loaded('yaml')) |
|
39 | 39 | { |
40 | 40 | throw new Exception\YamlExtension(); |
41 | 41 | } |
42 | - if(!is_readable($sConfigFile)) |
|
42 | + if (!is_readable($sConfigFile)) |
|
43 | 43 | { |
44 | 44 | throw new Exception\FileAccess($sConfigFile); |
45 | 45 | } |
46 | 46 | $aConfigOptions = yaml_parse_file($sConfigFile); |
47 | - if(!is_array($aConfigOptions)) |
|
47 | + if (!is_array($aConfigOptions)) |
|
48 | 48 | { |
49 | 49 | throw new Exception\FileContent($sConfigFile); |
50 | 50 | } |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | */ |
62 | 62 | private function _loadTranslations(string $sLanguage, string $sPrefix, array $aTranslations) |
63 | 63 | { |
64 | - foreach($aTranslations as $sName => $xTranslation) |
|
64 | + foreach ($aTranslations as $sName => $xTranslation) |
|
65 | 65 | { |
66 | 66 | $sName = trim($sName); |
67 | 67 | $sName = ($sPrefix) ? $sPrefix . '.' . $sName : $sName; |
68 | - if(!is_array($xTranslation)) |
|
68 | + if (!is_array($xTranslation)) |
|
69 | 69 | { |
70 | 70 | // Save this translation |
71 | 71 | $this->aTranslations[$sLanguage][$sName] = $xTranslation; |
@@ -88,17 +88,17 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function loadTranslations(string $sFilePath, string $sLanguage) |
90 | 90 | { |
91 | - if(!file_exists($sFilePath)) |
|
91 | + if (!file_exists($sFilePath)) |
|
92 | 92 | { |
93 | 93 | return; |
94 | 94 | } |
95 | 95 | $aTranslations = require($sFilePath); |
96 | - if(!is_array($aTranslations)) |
|
96 | + if (!is_array($aTranslations)) |
|
97 | 97 | { |
98 | 98 | return; |
99 | 99 | } |
100 | 100 | // Load the translations |
101 | - if(!array_key_exists($sLanguage, $this->aTranslations)) |
|
101 | + if (!array_key_exists($sLanguage, $this->aTranslations)) |
|
102 | 102 | { |
103 | 103 | $this->aTranslations[$sLanguage] = []; |
104 | 104 | } |
@@ -117,20 +117,20 @@ discard block |
||
117 | 117 | public function trans(string $sText, array $aPlaceHolders = [], string $sLanguage = '') |
118 | 118 | { |
119 | 119 | $sText = trim($sText); |
120 | - if(!$sLanguage) |
|
120 | + if (!$sLanguage) |
|
121 | 121 | { |
122 | 122 | $sLanguage = $this->xConfig->getOption('language', 'en'); |
123 | 123 | } |
124 | - if(!$sLanguage) |
|
124 | + if (!$sLanguage) |
|
125 | 125 | { |
126 | 126 | $sLanguage = $this->sDefaultLocale; |
127 | 127 | } |
128 | - if(!array_key_exists($sLanguage, $this->aTranslations) || !array_key_exists($sText, $this->aTranslations[$sLanguage])) |
|
128 | + if (!array_key_exists($sLanguage, $this->aTranslations) || !array_key_exists($sText, $this->aTranslations[$sLanguage])) |
|
129 | 129 | { |
130 | 130 | return $sText; |
131 | 131 | } |
132 | 132 | $message = $this->aTranslations[$sLanguage][$sText]; |
133 | - foreach($aPlaceHolders as $name => $value) |
|
133 | + foreach ($aPlaceHolders as $name => $value) |
|
134 | 134 | { |
135 | 135 | $message = str_replace(':' . $name, $value, $message); |
136 | 136 | } |