@@ -9,9 +9,9 @@ discard block |
||
| 9 | 9 | namespace HexMakina\Lezer; |
| 10 | 10 | |
| 11 | 11 | use \HexMakina\LocalFS\FileSystem; |
| 12 | -use \HexMakina\Tempus\{Dato,DatoTempo,Tempo}; |
|
| 12 | +use \HexMakina\Tempus\{Dato, DatoTempo, Tempo}; |
|
| 13 | 13 | |
| 14 | -class Lezer extends \i18n{ |
|
| 14 | +class Lezer extends \i18n { |
|
| 15 | 15 | |
| 16 | 16 | private $detected_language_files = []; |
| 17 | 17 | private $detected_language_env = []; |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | $this->detect_language_env(); |
| 29 | 29 | $the_one_language = current(array_intersect($this->detect_language_files(), $this->detect_language_env())); |
| 30 | 30 | |
| 31 | - if($the_one_language) |
|
| 31 | + if ($the_one_language) |
|
| 32 | 32 | $this->setForcedLang($the_one_language); |
| 33 | 33 | |
| 34 | 34 | return $the_one_language; |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | public function detect_language_files() |
| 38 | 38 | { |
| 39 | 39 | $files = FileSystem::preg_scandir(dirname($this->filePath), '/.json$/'); |
| 40 | - if(empty($files)) |
|
| 40 | + if (empty($files)) |
|
| 41 | 41 | return []; |
| 42 | 42 | |
| 43 | - $files = implode('',$files); |
|
| 43 | + $files = implode('', $files); |
|
| 44 | 44 | $res = preg_match_all('/([a-z]{3})\.json/', $files, $m); |
| 45 | - if($res) // false or 0 is none found |
|
| 45 | + if ($res) // false or 0 is none found |
|
| 46 | 46 | $this->detected_language_files = $m[1]; |
| 47 | 47 | return $this->detected_language_files; |
| 48 | 48 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | public function compileFunction() |
| 51 | 51 | { |
| 52 | 52 | return '' |
| 53 | - . "function ".$this->prefix .'($string, $args=NULL) {'."\n" |
|
| 53 | + . "function ".$this->prefix.'($string, $args=NULL) {'."\n" |
|
| 54 | 54 | . ' if (!defined("'.$this->prefix.'::".$string))' |
| 55 | 55 | . ' return $string;' |
| 56 | 56 | . ' $return = constant("'.$this->prefix.'::".$string);'."\n" |
@@ -111,16 +111,16 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | public static function model_type_to_label($form_model) |
| 113 | 113 | { |
| 114 | - return L(sprintf('MODEL_%s_INSTANCE',get_class($form_model)::model_type())); |
|
| 114 | + return L(sprintf('MODEL_%s_INSTANCE', get_class($form_model)::model_type())); |
|
| 115 | 115 | } |
| 116 | 116 | public static function field_name_to_label($form_model, $field_name) |
| 117 | 117 | { |
| 118 | - return L(sprintf('MODEL_%s_FIELD_%s',(get_class($form_model))::model_type(), $field_name)); |
|
| 118 | + return L(sprintf('MODEL_%s_FIELD_%s', (get_class($form_model))::model_type(), $field_name)); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // options['decimals'] = int |
| 122 | 122 | // options['abbrev'] = mixed: key needs to be set |
| 123 | - public static function when($event, $options=[]) |
|
| 123 | + public static function when($event, $options = []) |
|
| 124 | 124 | { |
| 125 | 125 | try { |
| 126 | 126 | $amount_of_days = DatoTempo::days_diff(new \DateTime($event), new \DateTime()); |
@@ -129,11 +129,11 @@ discard block |
||
| 129 | 129 | return __FUNCTION__.': error'; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if($amount_of_days === -1) |
|
| 132 | + if ($amount_of_days === -1) |
|
| 133 | 133 | return L('DATETIME_RANGE_YESTERDAY'); |
| 134 | - elseif($amount_of_days === 0) |
|
| 134 | + elseif ($amount_of_days === 0) |
|
| 135 | 135 | return L('DATETIME_RANGE_TODAY'); |
| 136 | - elseif($amount_of_days === 1) |
|
| 136 | + elseif ($amount_of_days === 1) |
|
| 137 | 137 | return L('DATETIME_RANGE_TOMORROW'); |
| 138 | 138 | |
| 139 | 139 | |
@@ -149,49 +149,49 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | $date_diff = DatoTempo::days_diff_in_parts(abs($amount_of_days)); |
| 151 | 151 | $ordering = []; |
| 152 | - foreach($datetime_parts as $unit => $label) |
|
| 152 | + foreach ($datetime_parts as $unit => $label) |
|
| 153 | 153 | { |
| 154 | - if(!isset($date_diff[$unit])) |
|
| 154 | + if (!isset($date_diff[$unit])) |
|
| 155 | 155 | continue; |
| 156 | 156 | |
| 157 | 157 | $qty = (int)$date_diff[$unit]; |
| 158 | 158 | |
| 159 | - if($qty === 0) |
|
| 159 | + if ($qty === 0) |
|
| 160 | 160 | continue; |
| 161 | 161 | |
| 162 | - if(isset($options['abbrev'])) |
|
| 163 | - $label.= '_ABBREV'; |
|
| 164 | - elseif($qty > 1) |
|
| 165 | - $label.= '_PLURAL'; |
|
| 162 | + if (isset($options['abbrev'])) |
|
| 163 | + $label .= '_ABBREV'; |
|
| 164 | + elseif ($qty > 1) |
|
| 165 | + $label .= '_PLURAL'; |
|
| 166 | 166 | |
| 167 | 167 | $ordering[$unit] = $qty.' '.L($label).'.'; |
| 168 | 168 | } |
| 169 | 169 | $ret = (isset($amount_of_days) && $amount_of_days >= 0) ? L('DATETIME_RANGE_PREFIX_FUTURE') : L('DATETIME_RANGE_PREFIX_PAST'); |
| 170 | - $ret.= ' '.implode(' & ', array_slice($ordering, 0,2)); |
|
| 170 | + $ret .= ' '.implode(' & ', array_slice($ordering, 0, 2)); |
|
| 171 | 171 | |
| 172 | 172 | return $ret; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - public static function time($time_string, $short=true) |
|
| 175 | + public static function time($time_string, $short = true) |
|
| 176 | 176 | { |
| 177 | 177 | if ($short === true) |
| 178 | 178 | $time_string = substr($time_string, 0, 5); |
| 179 | 179 | return $time_string; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - public static function human_date($date_string, $short=true) |
|
| 182 | + public static function human_date($date_string, $short = true) |
|
| 183 | 183 | { |
| 184 | - if($date_string === '0000-00-00' || empty($date_string)) |
|
| 184 | + if ($date_string === '0000-00-00' || empty($date_string)) |
|
| 185 | 185 | return L('MODEL_common_VALUE_EMPTY'); |
| 186 | 186 | |
| 187 | - if(preg_match('/^[0-9]{4}$/', $date_string) === 1) |
|
| 187 | + if (preg_match('/^[0-9]{4}$/', $date_string) === 1) |
|
| 188 | 188 | return intval($date_string); |
| 189 | 189 | |
| 190 | - list($year, $month, $day) = explode('-',$date_string); |
|
| 190 | + list($year, $month, $day) = explode('-', $date_string); |
|
| 191 | 191 | |
| 192 | 192 | $ret = intval($day).' '.L("DATETIME_CALENDAR_MONTH_$month"); |
| 193 | 193 | |
| 194 | - if($short === true && Dato::format(null, 'Y') === $year) |
|
| 194 | + if ($short === true && Dato::format(null, 'Y') === $year) |
|
| 195 | 195 | return $ret; |
| 196 | 196 | else |
| 197 | 197 | return "$ret $year"; |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | public static function human_seconds($seconds) |
| 211 | 211 | { |
| 212 | 212 | $hours = floor($seconds / 3600); |
| 213 | - $mins = floor(($seconds-$hours*3600) / 60); |
|
| 213 | + $mins = floor(($seconds-$hours * 3600) / 60); |
|
| 214 | 214 | $secs = floor($seconds % 60); |
| 215 | 215 | |
| 216 | - $hours_format ='%dh %dm %ds'; |
|
| 216 | + $hours_format = '%dh %dm %ds'; |
|
| 217 | 217 | return sprintf($hours_format, $hours, $mins, $secs); |
| 218 | 218 | } |
| 219 | 219 | |