1 | <?php |
||
36 | trait CommonLibLocale |
||
37 | { |
||
38 | |||
39 | protected $commonLibFlags = null; |
||
40 | protected $tCmnLb = null; |
||
41 | protected $tCmnRequest = null; |
||
42 | protected $tCmnSession = null; |
||
43 | protected $tCmnSuperGlobals = null; |
||
44 | |||
45 | private function getCommonLocaleFolder() |
||
46 | { |
||
47 | $pathes = explode(DIRECTORY_SEPARATOR, __DIR__); |
||
48 | $pathDepth = count($pathes); |
||
49 | $localePath = []; |
||
50 | foreach ($pathes as $key => $value) { |
||
51 | if ($key < ($pathDepth - 1)) { |
||
52 | $localePath[] = $value; |
||
53 | } |
||
54 | } |
||
55 | return implode(DIRECTORY_SEPARATOR, $localePath); |
||
56 | } |
||
57 | |||
58 | private function getTimestampArray($crtTime) |
||
62 | |||
63 | private function getTimestampFloat($crtTime) |
||
67 | |||
68 | protected function getTimestampRaw($returnType) |
||
72 | |||
73 | private function getTimestampString($crtTime) |
||
82 | |||
83 | /** |
||
84 | * Stores given language or default one into global session variable |
||
85 | * (In order to avoid potential language injections from other applications session will revert |
||
86 | * to the default language if application one is not among the one are not supported here) |
||
87 | * |
||
88 | * @return NOTHING |
||
89 | */ |
||
90 | private function handleLanguageIntoSession() |
||
91 | { |
||
92 | $this->settingsCommonLib(); |
||
93 | $this->initializeSprGlbAndSession(); |
||
94 | if (is_null($this->tCmnSuperGlobals->get('lang')) && is_null($this->tCmnSession->get('lang'))) { |
||
95 | $this->tCmnSession->set('lang', $this->commonLibFlags['default_language']); |
||
96 | } elseif (!is_null($this->tCmnSuperGlobals->get('lang'))) { |
||
97 | $this->tCmnSession->set('lang', filter_var($this->tCmnSuperGlobals->get('lang'), FILTER_SANITIZE_STRING)); |
||
98 | } |
||
99 | $this->normalizeLocalizationIntoSession(); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Takes care of instatiation of localization libraries |
||
104 | * used within current module for multi-languages support |
||
105 | * |
||
106 | * @return NOTHING |
||
107 | */ |
||
108 | private function handleLocalizationCommon() |
||
109 | { |
||
110 | $this->handleLanguageIntoSession(); |
||
111 | $localizationFile = $this->getCommonLocaleFolder() . '/locale/' |
||
112 | . $this->tCmnSession->get('lang') . '/LC_MESSAGES/' |
||
113 | . $this->commonLibFlags['localization_domain'] |
||
114 | . '.mo'; |
||
115 | $translations = new \Gettext\Translations; |
||
116 | $translations->addFromMoFile($localizationFile); |
||
117 | $this->tCmnLb = new \Gettext\Translator(); |
||
118 | $this->tCmnLb->loadTranslations($translations); |
||
119 | } |
||
120 | |||
121 | protected function initializeSprGlbAndSession() |
||
133 | |||
134 | private function lclManagePrerequisites() |
||
135 | { |
||
136 | if (is_null($this->tCmnLb)) { |
||
141 | |||
142 | /** |
||
143 | * Central function to deal with multi-language messages |
||
144 | * |
||
145 | * @param string $localizedStringCode |
||
146 | * @return string |
||
147 | */ |
||
148 | protected function lclMsgCmn($localizedStringCode) |
||
153 | |||
154 | protected function lclMsgCmnNumber($singularString, $pluralString, $numberToEvaluate) |
||
159 | |||
160 | private function normalizeLocalizationIntoSession() |
||
166 | |||
167 | /** |
||
168 | * Returns proper result from a mathematical division in order to avoid |
||
169 | * Zero division erorr or Infinite results |
||
170 | * |
||
171 | * @param float $fAbove |
||
172 | * @param float $fBelow |
||
173 | * @param mixed $mArguments |
||
174 | * @return decimal |
||
175 | */ |
||
176 | protected function setDividedResult($fAbove, $fBelow, $mArguments = null) |
||
190 | |||
191 | protected function setNumberFormat($content, $ftrs = null) |
||
199 | |||
200 | private function setNumberFormatFeatures($features) |
||
219 | |||
220 | /** |
||
221 | * Settings |
||
222 | * |
||
223 | * @return NOTHING |
||
224 | */ |
||
225 | private function settingsCommonLib() |
||
237 | } |
||
238 |