Format::getLocale()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 3
nc 3
nop 0
1
<?php
2
/* @description     Transformation Style Sheets - Revolutionising PHP templating    *
3
 * @author          Tom Butler [email protected]                                             *
4
 * @copyright       2017 Tom Butler <[email protected]> | https://r.je/                      *
5
 * @license         http://www.opensource.org/licenses/bsd-license.php  BSD License *
6
 * @version         1.2                                                             */
7
namespace Transphporm\Module;
8
/** Module for loading a formatter with a locale */
9
class Format implements \Transphporm\Module {
10
	private $locale;
11
12
	public function __construct($locale = null) {
13
		$this->locale = $locale;
14
	}
15
16
	private function getLocale() {
17
		if (is_array($this->locale)) return $this->locale;
18
		else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true);
19
		else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
20
	}
21
22
	public function load(\Transphporm\Config $config) {
23
		$locale = $this->getLocale();
24
		$config->registerFormatter(new \Transphporm\Formatter\Number($locale));
25
		$config->registerFormatter(new \Transphporm\Formatter\Date($locale));
26
		$config->registerFormatter(new \Transphporm\Formatter\StringFormatter());
27
		$config->registerFormatter(new \Transphporm\Formatter\Nl2brFormat());
28
	}
29
}
30