@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | public function setLocale(string $sLocale): void |
| 58 | 58 | { |
| 59 | - if(($sLocale = trim($sLocale))) |
|
| 59 | + if (($sLocale = trim($sLocale))) |
|
| 60 | 60 | { |
| 61 | 61 | $this->sDefaultLocale = $sLocale; |
| 62 | 62 | } |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | private function _loadTranslations(string $sLanguage, string $sPrefix, array $aTranslations): void |
| 75 | 75 | { |
| 76 | - foreach($aTranslations as $sKey => $xTranslation) |
|
| 76 | + foreach ($aTranslations as $sKey => $xTranslation) |
|
| 77 | 77 | { |
| 78 | 78 | $sKey = trim($sKey); |
| 79 | 79 | $sKey = ($sPrefix) ? $sPrefix . '.' . $sKey : $sKey; |
| 80 | - if(is_array($xTranslation)) |
|
| 80 | + if (is_array($xTranslation)) |
|
| 81 | 81 | { |
| 82 | 82 | // Recursively read the translations in the array |
| 83 | 83 | $this->_loadTranslations($sLanguage, $sKey, $xTranslation); |
@@ -100,18 +100,18 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public function loadTranslations(string $sFilePath, string $sLanguage): bool |
| 102 | 102 | { |
| 103 | - if(!file_exists($sFilePath)) |
|
| 103 | + if (!file_exists($sFilePath)) |
|
| 104 | 104 | { |
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | 107 | $aTranslations = require($sFilePath); |
| 108 | - if(!is_array($aTranslations)) |
|
| 108 | + if (!is_array($aTranslations)) |
|
| 109 | 109 | { |
| 110 | 110 | return false; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | // Load the translations |
| 114 | - if(!isset($this->aTranslations[$sLanguage])) |
|
| 114 | + if (!isset($this->aTranslations[$sLanguage])) |
|
| 115 | 115 | { |
| 116 | 116 | $this->aTranslations[$sLanguage] = []; |
| 117 | 117 | } |
@@ -133,16 +133,16 @@ discard block |
||
| 133 | 133 | public function trans(string $sText, array $aPlaceHolders = [], string $sLanguage = ''): string |
| 134 | 134 | { |
| 135 | 135 | $sText = trim($sText); |
| 136 | - if(empty($sLanguage)) |
|
| 136 | + if (empty($sLanguage)) |
|
| 137 | 137 | { |
| 138 | 138 | $sLanguage = $this->sDefaultLocale; |
| 139 | 139 | } |
| 140 | - if(!isset($this->aTranslations[$sLanguage][$sText])) |
|
| 140 | + if (!isset($this->aTranslations[$sLanguage][$sText])) |
|
| 141 | 141 | { |
| 142 | 142 | return $sText; |
| 143 | 143 | } |
| 144 | 144 | $sMessage = $this->aTranslations[$sLanguage][$sText]; |
| 145 | - if(!empty($aPlaceHolders)) |
|
| 145 | + if (!empty($aPlaceHolders)) |
|
| 146 | 146 | { |
| 147 | 147 | $aVars = array_map(function($sVar) { |
| 148 | 148 | return ':' . $sVar; |
@@ -162,16 +162,16 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | public function translations(string $sKey, string $sLanguage = ''): array |
| 164 | 164 | { |
| 165 | - if(empty($sLanguage)) |
|
| 165 | + if (empty($sLanguage)) |
|
| 166 | 166 | { |
| 167 | 167 | $sLanguage = $this->sDefaultLocale; |
| 168 | 168 | } |
| 169 | 169 | $aKeys = explode('.', $sKey); |
| 170 | 170 | |
| 171 | 171 | $aTranslations = $this->aRawTranslations[$sLanguage]; |
| 172 | - foreach($aKeys as $sKey) |
|
| 172 | + foreach ($aKeys as $sKey) |
|
| 173 | 173 | { |
| 174 | - if($sKey !== '') |
|
| 174 | + if ($sKey !== '') |
|
| 175 | 175 | { |
| 176 | 176 | $aTranslations = $aTranslations[$sKey] ?? []; |
| 177 | 177 | } |
@@ -81,8 +81,7 @@ |
||
| 81 | 81 | { |
| 82 | 82 | // Recursively read the translations in the array |
| 83 | 83 | $this->_loadTranslations($sLanguage, $sKey, $xTranslation); |
| 84 | - } |
|
| 85 | - else |
|
| 84 | + } else |
|
| 86 | 85 | { |
| 87 | 86 | // Save this translation |
| 88 | 87 | $this->aTranslations[$sLanguage][$sKey] = $xTranslation; |
@@ -26,43 +26,43 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | class Translator |
| 28 | 28 | { |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * The default locale |
| 31 | 31 | * |
| 32 | 32 | * @var string |
| 33 | 33 | */ |
| 34 | - protected $sDefaultLocale = 'en'; |
|
| 34 | +protected $sDefaultLocale = 'en'; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * The translations in a flattened array |
| 38 | 38 | * |
| 39 | 39 | * @var array |
| 40 | 40 | */ |
| 41 | - protected $aTranslations = []; |
|
| 41 | +protected $aTranslations = []; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * The translations as received as input |
| 45 | 45 | * |
| 46 | 46 | * @var array |
| 47 | 47 | */ |
| 48 | - protected $aRawTranslations = []; |
|
| 48 | +protected $aRawTranslations = []; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 50 | +/** |
|
| 51 | 51 | * Set the default locale |
| 52 | 52 | * |
| 53 | 53 | * @param string $sLocale |
| 54 | 54 | * |
| 55 | 55 | * @return void |
| 56 | 56 | */ |
| 57 | - public function setLocale(string $sLocale): void |
|
| 58 | - { |
|
| 59 | - if(($sLocale = trim($sLocale))) |
|
| 60 | - { |
|
| 61 | - $this->sDefaultLocale = $sLocale; |
|
| 62 | - } |
|
| 63 | - } |
|
| 57 | +public function setLocale(string $sLocale): void |
|
| 58 | +{ |
|
| 59 | +if(($sLocale = trim($sLocale))) |
|
| 60 | +{ |
|
| 61 | +$this->sDefaultLocale = $sLocale; |
|
| 62 | +} |
|
| 63 | +} |
|
| 64 | 64 | |
| 65 | - /** |
|
| 65 | +/** |
|
| 66 | 66 | * Recursively load translated strings from an array |
| 67 | 67 | * |
| 68 | 68 | * @param string $sLanguage The language of the translations |
@@ -71,26 +71,26 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return void |
| 73 | 73 | */ |
| 74 | - private function _loadTranslations(string $sLanguage, string $sPrefix, array $aTranslations): void |
|
| 75 | - { |
|
| 76 | - foreach($aTranslations as $sKey => $xTranslation) |
|
| 77 | - { |
|
| 78 | - $sKey = trim($sKey); |
|
| 79 | - $sKey = ($sPrefix) ? $sPrefix . '.' . $sKey : $sKey; |
|
| 80 | - if(is_array($xTranslation)) |
|
| 81 | - { |
|
| 82 | - // Recursively read the translations in the array |
|
| 83 | - $this->_loadTranslations($sLanguage, $sKey, $xTranslation); |
|
| 84 | - } |
|
| 85 | - else |
|
| 86 | - { |
|
| 87 | - // Save this translation |
|
| 88 | - $this->aTranslations[$sLanguage][$sKey] = $xTranslation; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 74 | +private function _loadTranslations(string $sLanguage, string $sPrefix, array $aTranslations): void |
|
| 75 | +{ |
|
| 76 | +foreach($aTranslations as $sKey => $xTranslation) |
|
| 77 | +{ |
|
| 78 | +$sKey = trim($sKey); |
|
| 79 | +$sKey = ($sPrefix) ? $sPrefix . '.' . $sKey : $sKey; |
|
| 80 | +if(is_array($xTranslation)) |
|
| 81 | +{ |
|
| 82 | + // Recursively read the translations in the array |
|
| 83 | + $this->_loadTranslations($sLanguage, $sKey, $xTranslation); |
|
| 84 | +} |
|
| 85 | +else |
|
| 86 | +{ |
|
| 87 | + // Save this translation |
|
| 88 | + $this->aTranslations[$sLanguage][$sKey] = $xTranslation; |
|
| 89 | +} |
|
| 90 | +} |
|
| 91 | +} |
|
| 92 | 92 | |
| 93 | - /** |
|
| 93 | +/** |
|
| 94 | 94 | * Load translated strings from a file |
| 95 | 95 | * |
| 96 | 96 | * @param string $sFilePath The file full path |
@@ -98,30 +98,30 @@ discard block |
||
| 98 | 98 | * |
| 99 | 99 | * @return bool |
| 100 | 100 | */ |
| 101 | - public function loadTranslations(string $sFilePath, string $sLanguage): bool |
|
| 102 | - { |
|
| 103 | - if(!file_exists($sFilePath)) |
|
| 104 | - { |
|
| 105 | - return false; |
|
| 106 | - } |
|
| 107 | - $aTranslations = require($sFilePath); |
|
| 108 | - if(!is_array($aTranslations)) |
|
| 109 | - { |
|
| 110 | - return false; |
|
| 111 | - } |
|
| 101 | +public function loadTranslations(string $sFilePath, string $sLanguage): bool |
|
| 102 | +{ |
|
| 103 | +if(!file_exists($sFilePath)) |
|
| 104 | +{ |
|
| 105 | +return false; |
|
| 106 | +} |
|
| 107 | +$aTranslations = require($sFilePath); |
|
| 108 | +if(!is_array($aTranslations)) |
|
| 109 | +{ |
|
| 110 | +return false; |
|
| 111 | +} |
|
| 112 | 112 | |
| 113 | - // Load the translations |
|
| 114 | - if(!isset($this->aTranslations[$sLanguage])) |
|
| 115 | - { |
|
| 116 | - $this->aTranslations[$sLanguage] = []; |
|
| 117 | - } |
|
| 118 | - $this->aRawTranslations[$sLanguage] = |
|
| 119 | - array_merge($this->aRawTranslations[$sLanguage] ?? [], $aTranslations); |
|
| 120 | - $this->_loadTranslations($sLanguage, '', $aTranslations); |
|
| 121 | - return true; |
|
| 122 | - } |
|
| 113 | +// Load the translations |
|
| 114 | +if(!isset($this->aTranslations[$sLanguage])) |
|
| 115 | +{ |
|
| 116 | +$this->aTranslations[$sLanguage] = []; |
|
| 117 | +} |
|
| 118 | +$this->aRawTranslations[$sLanguage] = |
|
| 119 | +array_merge($this->aRawTranslations[$sLanguage] ?? [], $aTranslations); |
|
| 120 | +$this->_loadTranslations($sLanguage, '', $aTranslations); |
|
| 121 | +return true; |
|
| 122 | +} |
|
| 123 | 123 | |
| 124 | - /** |
|
| 124 | +/** |
|
| 125 | 125 | * Get a translated string |
| 126 | 126 | * |
| 127 | 127 | * @param string $sText The key of the translated string |
@@ -130,29 +130,29 @@ discard block |
||
| 130 | 130 | * |
| 131 | 131 | * @return string |
| 132 | 132 | */ |
| 133 | - public function trans(string $sText, array $aPlaceHolders = [], string $sLanguage = ''): string |
|
| 134 | - { |
|
| 135 | - $sText = trim($sText); |
|
| 136 | - if(empty($sLanguage)) |
|
| 137 | - { |
|
| 138 | - $sLanguage = $this->sDefaultLocale; |
|
| 139 | - } |
|
| 140 | - if(!isset($this->aTranslations[$sLanguage][$sText])) |
|
| 141 | - { |
|
| 142 | - return $sText; |
|
| 143 | - } |
|
| 144 | - $sMessage = $this->aTranslations[$sLanguage][$sText]; |
|
| 145 | - if(!empty($aPlaceHolders)) |
|
| 146 | - { |
|
| 147 | - $aVars = array_map(function($sVar) { |
|
| 148 | - return ':' . $sVar; |
|
| 149 | - }, array_keys($aPlaceHolders)); |
|
| 150 | - $sMessage = str_replace($aVars, array_values($aPlaceHolders), $sMessage); |
|
| 151 | - } |
|
| 152 | - return $sMessage; |
|
| 153 | - } |
|
| 133 | +public function trans(string $sText, array $aPlaceHolders = [], string $sLanguage = ''): string |
|
| 134 | +{ |
|
| 135 | +$sText = trim($sText); |
|
| 136 | +if(empty($sLanguage)) |
|
| 137 | +{ |
|
| 138 | +$sLanguage = $this->sDefaultLocale; |
|
| 139 | +} |
|
| 140 | +if(!isset($this->aTranslations[$sLanguage][$sText])) |
|
| 141 | +{ |
|
| 142 | +return $sText; |
|
| 143 | +} |
|
| 144 | +$sMessage = $this->aTranslations[$sLanguage][$sText]; |
|
| 145 | +if(!empty($aPlaceHolders)) |
|
| 146 | +{ |
|
| 147 | +$aVars = array_map(function($sVar) { |
|
| 148 | + return ':' . $sVar; |
|
| 149 | +}, array_keys($aPlaceHolders)); |
|
| 150 | +$sMessage = str_replace($aVars, array_values($aPlaceHolders), $sMessage); |
|
| 151 | +} |
|
| 152 | +return $sMessage; |
|
| 153 | +} |
|
| 154 | 154 | |
| 155 | - /** |
|
| 155 | +/** |
|
| 156 | 156 | * Get all the translations under a given key |
| 157 | 157 | * |
| 158 | 158 | * @param string $sKey |
@@ -160,22 +160,22 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return array |
| 162 | 162 | */ |
| 163 | - public function translations(string $sKey, string $sLanguage = ''): array |
|
| 164 | - { |
|
| 165 | - if(empty($sLanguage)) |
|
| 166 | - { |
|
| 167 | - $sLanguage = $this->sDefaultLocale; |
|
| 168 | - } |
|
| 169 | - $aKeys = explode('.', $sKey); |
|
| 163 | +public function translations(string $sKey, string $sLanguage = ''): array |
|
| 164 | +{ |
|
| 165 | +if(empty($sLanguage)) |
|
| 166 | +{ |
|
| 167 | +$sLanguage = $this->sDefaultLocale; |
|
| 168 | +} |
|
| 169 | +$aKeys = explode('.', $sKey); |
|
| 170 | 170 | |
| 171 | - $aTranslations = $this->aRawTranslations[$sLanguage]; |
|
| 172 | - foreach($aKeys as $sKey) |
|
| 173 | - { |
|
| 174 | - if($sKey !== '') |
|
| 175 | - { |
|
| 176 | - $aTranslations = $aTranslations[$sKey] ?? []; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - return $aTranslations; |
|
| 180 | - } |
|
| 171 | +$aTranslations = $this->aRawTranslations[$sLanguage]; |
|
| 172 | +foreach($aKeys as $sKey) |
|
| 173 | +{ |
|
| 174 | +if($sKey !== '') |
|
| 175 | +{ |
|
| 176 | + $aTranslations = $aTranslations[$sKey] ?? []; |
|
| 177 | +} |
|
| 178 | +} |
|
| 179 | +return $aTranslations; |
|
| 180 | +} |
|
| 181 | 181 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | { |
| 38 | 38 | return file_get_contents($sPath); |
| 39 | 39 | } |
| 40 | - catch(Exception $e) |
|
| 40 | + catch (Exception $e) |
|
| 41 | 41 | { |
| 42 | 42 | return false; |
| 43 | 43 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | { |
| 57 | 57 | return Minifier::minify($sCode); |
| 58 | 58 | } |
| 59 | - catch(Exception $e) |
|
| 59 | + catch (Exception $e) |
|
| 60 | 60 | { |
| 61 | 61 | return false; |
| 62 | 62 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function minify(string $sJsFile, string $sMinFile): bool |
| 74 | 74 | { |
| 75 | - if(($sJsCode = $this->readFile($sJsFile)) === false || |
|
| 75 | + if (($sJsCode = $this->readFile($sJsFile)) === false || |
|
| 76 | 76 | ($sMinCode = $this->minifyCode($sJsCode)) === false) |
| 77 | 77 | { |
| 78 | 78 | return false; |
@@ -36,8 +36,7 @@ discard block |
||
| 36 | 36 | try |
| 37 | 37 | { |
| 38 | 38 | return file_get_contents($sPath); |
| 39 | - } |
|
| 40 | - catch(Exception $e) |
|
| 39 | + } catch(Exception $e) |
|
| 41 | 40 | { |
| 42 | 41 | return false; |
| 43 | 42 | } |
@@ -55,8 +54,7 @@ discard block |
||
| 55 | 54 | try |
| 56 | 55 | { |
| 57 | 56 | return Minifier::minify($sCode); |
| 58 | - } |
|
| 59 | - catch(Exception $e) |
|
| 57 | + } catch(Exception $e) |
|
| 60 | 58 | { |
| 61 | 59 | return false; |
| 62 | 60 | } |
@@ -24,45 +24,45 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | class FileMinifier |
| 26 | 26 | { |
| 27 | - /** |
|
| 27 | +/** |
|
| 28 | 28 | * Read the file content |
| 29 | 29 | * |
| 30 | 30 | * @param string $sPath |
| 31 | 31 | * |
| 32 | 32 | * @return string|false |
| 33 | 33 | */ |
| 34 | - private function readFile(string $sPath): bool|string |
|
| 35 | - { |
|
| 36 | - try |
|
| 37 | - { |
|
| 38 | - return file_get_contents($sPath); |
|
| 39 | - } |
|
| 40 | - catch(Exception $e) |
|
| 41 | - { |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - } |
|
| 34 | +private function readFile(string $sPath): bool|string |
|
| 35 | +{ |
|
| 36 | +try |
|
| 37 | +{ |
|
| 38 | +return file_get_contents($sPath); |
|
| 39 | +} |
|
| 40 | +catch(Exception $e) |
|
| 41 | +{ |
|
| 42 | +return false; |
|
| 43 | +} |
|
| 44 | +} |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * Read the file content |
| 48 | 48 | * |
| 49 | 49 | * @param string $sCode |
| 50 | 50 | * |
| 51 | 51 | * @return string|false |
| 52 | 52 | */ |
| 53 | - private function minifyCode(string $sCode): bool|string |
|
| 54 | - { |
|
| 55 | - try |
|
| 56 | - { |
|
| 57 | - return Minifier::minify($sCode); |
|
| 58 | - } |
|
| 59 | - catch(Exception $e) |
|
| 60 | - { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - } |
|
| 53 | +private function minifyCode(string $sCode): bool|string |
|
| 54 | +{ |
|
| 55 | +try |
|
| 56 | +{ |
|
| 57 | +return Minifier::minify($sCode); |
|
| 58 | +} |
|
| 59 | +catch(Exception $e) |
|
| 60 | +{ |
|
| 61 | +return false; |
|
| 62 | +} |
|
| 63 | +} |
|
| 64 | 64 | |
| 65 | - /** |
|
| 65 | +/** |
|
| 66 | 66 | * Minify javascript code |
| 67 | 67 | * |
| 68 | 68 | * @param string $sJsFile The javascript file to be minified |
@@ -70,14 +70,14 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @return bool |
| 72 | 72 | */ |
| 73 | - public function minify(string $sJsFile, string $sMinFile): bool |
|
| 74 | - { |
|
| 75 | - if(($sJsCode = $this->readFile($sJsFile)) === false || |
|
| 76 | - ($sMinCode = $this->minifyCode($sJsCode)) === false) |
|
| 77 | - { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - file_put_contents($sMinFile, $sMinCode); |
|
| 81 | - return is_file($sMinFile); |
|
| 82 | - } |
|
| 73 | +public function minify(string $sJsFile, string $sMinFile): bool |
|
| 74 | +{ |
|
| 75 | +if(($sJsCode = $this->readFile($sJsFile)) === false || |
|
| 76 | +($sMinCode = $this->minifyCode($sJsCode)) === false) |
|
| 77 | +{ |
|
| 78 | +return false; |
|
| 79 | +} |
|
| 80 | +file_put_contents($sMinFile, $sMinCode); |
|
| 81 | +return is_file($sMinFile); |
|
| 82 | +} |
|
| 83 | 83 | } |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | |
| 36 | 36 | protected function setUp(): void |
| 37 | 37 | { |
| 38 | - $this->sConfigDir = __DIR__ . '/../config'; |
|
| 38 | + $this->sConfigDir = __DIR__ . '/../config'; |
|
| 39 | 39 | $this->xConfigSetter = new ConfigSetter(); |
| 40 | 40 | $this->xConfigReader = new ConfigReader($this->xConfigSetter); |
| 41 | 41 | $this->xConfig = $this->xConfigSetter->newConfig(['core' => ['language' => 'en']]); |
@@ -90,11 +90,11 @@ |
||
| 90 | 90 | $sKey = trim($sKey, ' .'); |
| 91 | 91 | $aKeys = Value::explodeName($sKey); |
| 92 | 92 | $aValues = $this->aValues; |
| 93 | - foreach($aKeys as $_sKey) |
|
| 93 | + foreach ($aKeys as $_sKey) |
|
| 94 | 94 | { |
| 95 | 95 | $aValues = $aValues[$_sKey] ?? []; |
| 96 | 96 | } |
| 97 | - if(!Value::containsOptions($aValues)) |
|
| 97 | + if (!Value::containsOptions($aValues)) |
|
| 98 | 98 | { |
| 99 | 99 | return []; |
| 100 | 100 | } |
@@ -34,13 +34,13 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | public static function containsOptions($xValue): bool |
| 36 | 36 | { |
| 37 | - if(!is_array($xValue) || count($xValue) === 0) |
|
| 37 | + if (!is_array($xValue) || count($xValue) === 0) |
|
| 38 | 38 | { |
| 39 | 39 | return false; |
| 40 | 40 | } |
| 41 | - foreach(array_keys($xValue) as $xKey) |
|
| 41 | + foreach (array_keys($xValue) as $xKey) |
|
| 42 | 42 | { |
| 43 | - if(!is_string($xKey)) |
|
| 43 | + if (!is_string($xKey)) |
|
| 44 | 44 | { |
| 45 | 45 | return false; |
| 46 | 46 | } |
@@ -35,13 +35,13 @@ |
||
| 35 | 35 | public static function read(string $sConfigFile): array |
| 36 | 36 | { |
| 37 | 37 | $sConfigFile = realpath($sConfigFile); |
| 38 | - if(!is_readable($sConfigFile)) |
|
| 38 | + if (!is_readable($sConfigFile)) |
|
| 39 | 39 | { |
| 40 | 40 | throw new FileAccess($sConfigFile); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | $aConfigOptions = include($sConfigFile); |
| 44 | - if(!is_array($aConfigOptions)) |
|
| 44 | + if (!is_array($aConfigOptions)) |
|
| 45 | 45 | { |
| 46 | 46 | throw new FileContent($sConfigFile); |
| 47 | 47 | } |
@@ -38,19 +38,19 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | public static function read(string $sConfigFile): array |
| 40 | 40 | { |
| 41 | - if(!extension_loaded('yaml')) |
|
| 41 | + if (!extension_loaded('yaml')) |
|
| 42 | 42 | { |
| 43 | 43 | throw new YamlExtension(); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $sConfigFile = realpath($sConfigFile); |
| 47 | - if(!is_readable($sConfigFile)) |
|
| 47 | + if (!is_readable($sConfigFile)) |
|
| 48 | 48 | { |
| 49 | 49 | throw new FileAccess($sConfigFile); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $aConfigOptions = yaml_parse_file($sConfigFile); |
| 53 | - if(!is_array($aConfigOptions)) |
|
| 53 | + if (!is_array($aConfigOptions)) |
|
| 54 | 54 | { |
| 55 | 55 | throw new FileContent($sConfigFile); |
| 56 | 56 | } |
@@ -37,14 +37,14 @@ |
||
| 37 | 37 | public static function read(string $sConfigFile): array |
| 38 | 38 | { |
| 39 | 39 | $sConfigFile = realpath($sConfigFile); |
| 40 | - if(!is_readable($sConfigFile)) |
|
| 40 | + if (!is_readable($sConfigFile)) |
|
| 41 | 41 | { |
| 42 | 42 | throw new FileAccess($sConfigFile); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | $sFileContent = file_get_contents($sConfigFile); |
| 46 | 46 | $aConfigOptions = json_decode($sFileContent, true); |
| 47 | - if(!is_array($aConfigOptions)) |
|
| 47 | + if (!is_array($aConfigOptions)) |
|
| 48 | 48 | { |
| 49 | 49 | throw new FileContent($sConfigFile); |
| 50 | 50 | } |
@@ -44,8 +44,7 @@ discard block |
||
| 44 | 44 | public function newConfig(array $aOptions = [], |
| 45 | 45 | string $sNamePrefix = '', string $sValuePrefix = ''): Config |
| 46 | 46 | { |
| 47 | - return count($aOptions) === 0 ? new Config() : |
|
| 48 | - $this->setOptions(new Config(), $aOptions, $sNamePrefix, $sValuePrefix); |
|
| 47 | + return count($aOptions) === 0 ? new Config() : $this->setOptions(new Config(), $aOptions, $sNamePrefix, $sValuePrefix); |
|
| 49 | 48 | } |
| 50 | 49 | |
| 51 | 50 | /** |
@@ -77,7 +76,7 @@ discard block |
||
| 77 | 76 | $xValue = $xOptionValue; |
| 78 | 77 | $sLastName = ''; |
| 79 | 78 | $aNames = Value::explodeName($sOptionName); |
| 80 | - while($this->pop($sLastName, $aNames) > 0) |
|
| 79 | + while ($this->pop($sLastName, $aNames) > 0) |
|
| 81 | 80 | { |
| 82 | 81 | $sName = implode('.', $aNames); |
| 83 | 82 | // The current value is overwritten if it is not an array of options. |
@@ -121,15 +120,15 @@ discard block |
||
| 121 | 120 | string $sNamePrefix = '', int $nDepth = 0): array |
| 122 | 121 | { |
| 123 | 122 | // Check the max depth |
| 124 | - if($nDepth < 0 || $nDepth > 9) |
|
| 123 | + if ($nDepth < 0 || $nDepth > 9) |
|
| 125 | 124 | { |
| 126 | 125 | throw new DataDepth($sNamePrefix, $nDepth); |
| 127 | 126 | } |
| 128 | 127 | |
| 129 | - foreach($aOptions as $sName => $xValue) |
|
| 128 | + foreach ($aOptions as $sName => $xValue) |
|
| 130 | 129 | { |
| 131 | 130 | $sName = trim($sName); |
| 132 | - if(!Value::containsOptions($xValue)) |
|
| 131 | + if (!Value::containsOptions($xValue)) |
|
| 133 | 132 | { |
| 134 | 133 | // Save the value of this option |
| 135 | 134 | $aValues = $this->setValue($aValues, $sNamePrefix . $sName, $xValue); |
@@ -160,11 +159,11 @@ discard block |
||
| 160 | 159 | // Find the config array in the input data |
| 161 | 160 | $sValuePrefix = trim($sValuePrefix, ' .'); |
| 162 | 161 | $aKeys = Value::explodeName($sValuePrefix); |
| 163 | - foreach($aKeys as $sKey) |
|
| 162 | + foreach ($aKeys as $sKey) |
|
| 164 | 163 | { |
| 165 | - if(($sKey)) |
|
| 164 | + if (($sKey)) |
|
| 166 | 165 | { |
| 167 | - if(!isset($aOptions[$sKey]) || !is_array($aOptions[$sKey])) |
|
| 166 | + if (!isset($aOptions[$sKey]) || !is_array($aOptions[$sKey])) |
|
| 168 | 167 | { |
| 169 | 168 | // No change if the required key is not found. |
| 170 | 169 | return new Config($xConfig->getValues(), false); |
@@ -175,7 +174,7 @@ discard block |
||
| 175 | 174 | } |
| 176 | 175 | |
| 177 | 176 | $sNamePrefix = trim($sNamePrefix, ' .'); |
| 178 | - if(($sNamePrefix)) |
|
| 177 | + if (($sNamePrefix)) |
|
| 179 | 178 | { |
| 180 | 179 | $sNamePrefix .= '.'; |
| 181 | 180 | } |
@@ -204,7 +203,7 @@ discard block |
||
| 204 | 203 | private function deleteEntries(array $aValues, string $sName): array |
| 205 | 204 | { |
| 206 | 205 | $sName = rtrim($sName, '.'); |
| 207 | - if(!array_key_exists($sName, $aValues)) |
|
| 206 | + if (!array_key_exists($sName, $aValues)) |
|
| 208 | 207 | { |
| 209 | 208 | return $aValues; |
| 210 | 209 | } |
@@ -229,7 +228,7 @@ discard block |
||
| 229 | 228 | { |
| 230 | 229 | $aValues = $xConfig->getValues(); |
| 231 | 230 | $nEntryCount = count($aValues); |
| 232 | - foreach($aNames as $sName) |
|
| 231 | + foreach ($aNames as $sName) |
|
| 233 | 232 | { |
| 234 | 233 | $aValues = $this->deleteEntries($aValues, $sName); |
| 235 | 234 | } |