Completed
Push — master ( 9f0ecb...4a849c )
by Oleg
06:13
created

Language::__set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 2
1
<?php /** MicroLanguage */
2
3
namespace Micro\Web;
4
5
use Micro\base\Exception;
6
use Micro\Base\Injector;
7
8
/**
9
 * Language getter language tags from *.ini files
10
 *
11
 * @author Oleg Lunegov <[email protected]>
12
 * @link https://github.com/linpax/microphp-framework
13
 * @copyright Copyright (c) 2013 Oleg Lunegov
14
 * @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
15
 * @package Micro
16
 * @subpackage Web
17
 * @version 1.0
18
 * @since 1.0
19
 */
20
class Language extends \stdClass
21
{
22
    /** @var array $language language array */
23
    private $language = [];
24
    /** @var string $defaultLang default language */
25
    private $defaultLang = 'en';
26
27
    /**
28
     * Constructor language
29
     *
30
     * @access public
31
     *
32
     * @param string $viewNameFile path to view
33
     *
34
     * @result void
35
     */
36
    public function __construct($viewNameFile)
37
    {
38
        $viewName = substr($viewNameFile, 0, -3);
39
40
        $lang = (new Injector)->param('lang');
41
        $lang = $lang ?: $this->defaultLang;
42
43
        if (!file_exists($viewName.$lang.'.ini')) {
44
            return;
45
        }
46
47
        $this->language = parse_ini_file($viewName.$lang.'.ini', true);
48
    }
49
50
    /**
51
     * Get param value
52
     *
53
     * @access public
54
     *
55
     * @param string $name element name
56
     *
57
     * @return mixed
58
     * @throws Exception
59
     */
60
    public function __get($name)
61
    {
62
        if (!empty($this->language[$name])) {
63
            return $this->language[$name];
64
        } else {
65
            throw new Exception($name.' not defined into lang file');
66
        }
67
    }
68
69
    /**
70
     * @param string $name
71
     * @param mixed $value
72
     */
73
    public function __set($name, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
    {
75
    }
76
77
    /**
78
     * @param string $name
79
     * @return boolean
80
     */
81
    public function __isset($name)
82
    {
83
        return (bool)$this->$name;
84
    }
85
}
86