Language::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * @package Cadmium\Framework\Language
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace {
11
12
	abstract class Language {
13
14
		protected static $phrases = [];
15
16
		/**
17
		 * Add a phrase to the list
18
		 */
19
20
		private static function addPhrase(string $name, string $value) {
21
22
			if (preg_match(REGEX_LANGUAGE_PHRASE_NAME, $name)) self::$phrases[$name] = $value;
23
		}
24
25
		/**
26
		 * Load a phrases list from a file
27
		 *
28
		 * @return bool : true on success or false on failure
29
		 */
30
31
		public static function load(string $file_name) : bool {
32
33
			if (!is_array($phrases = Explorer::include($file_name))) return false;
34
35
			foreach ($phrases as $name => $value) if (is_scalar($value)) self::addPhrase($name, $value);
36
37
			# ------------------------
38
39
			return true;
40
		}
41
42
		/**
43
		 * Get a phrase
44
		 *
45
		 * @return string|false : the phrase if exists, otherwise false
46
		 */
47
48
		public static function get(string $name) {
49
50
			return (self::$phrases[$name] ?? false);
51
		}
52
53
		/**
54
		 * Get the phrases array
55
		 */
56
57
		public static function getPhrases() : array {
58
59
			return static::$phrases;
60
		}
61
	}
62
}
63