China   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 5
dl 0
loc 123
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A registerParameters() 0 8 1
A registerService() 0 12 1
A getHoliday() 0 4 1
A getNationality() 0 4 1
A getRegion() 0 4 1
A getName() 0 4 1
A getOfficialName() 0 4 1
A getIsoCode() 0 4 1
A getLanguages() 0 4 1
1
<?php
2
/*
3
 * This file is part of the Slince/China package.
4
 *
5
 * (c) Slince <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace China;
12
13
define('RESOURCE_DIR', __DIR__.'/../../resources/');
14
15
use China\Common\ResourceFile;
16
use China\Holiday\HolidayService;
17
use China\Holiday\HolidayServiceInterface;
18
use China\Nationality\NationalityService;
19
use China\Nationality\NationalityServiceInterface;
20
use China\Region\RegionService;
21
use China\Region\RegionServiceInterface;
22
use Slince\Di\Container;
23
24
class China
25
{
26
    /**
27
     * @var string
28
     */
29
    protected $name = '中国';
30
31
    /**
32
     * @var string
33
     */
34
    protected $officialName = '中华人民共和国';
35
36
    /**
37
     * @var string
38
     */
39
    protected $isoCode = 'CN';
40
41
    /**
42
     * @var array
43
     */
44
    protected $languages = ['zh_CN', 'zh_TW'];
45
46
    protected $container;
47
48
    public function __construct()
49
    {
50
        $this->container = new Container();
51
        $this->registerParameters();
52
        $this->registerService();
53
    }
54
55
    protected function registerParameters()
56
    {
57
        $this->container->setParameters([
58
            'resource.file.holidays' => RESOURCE_DIR.'holidays.json',
59
            'resource.file.nationalities' => RESOURCE_DIR.'nationalities.json',
60
            'resource.file.regions' => RESOURCE_DIR.'regions/regions.json',
61
        ]);
62
    }
63
64
    protected function registerService()
65
    {
66
        $this->container->set('holiday', function(Container $container){
67
            return new HolidayService(new ResourceFile($container->getParameter('resource.file.holidays')));
68
        });
69
        $this->container->set('nationality', function(Container $container){
70
            return new NationalityService(new ResourceFile($container->getParameter('resource.file.nationalities')));
71
        });
72
        $this->container->set('region', function(Container $container){
73
            return new RegionService(new ResourceFile($container->getParameter('resource.file.regions')));
74
        });
75
    }
76
77
    /**
78
     * 获取Holiday服务
79
     *
80
     * @return HolidayServiceInterface
81
     */
82
    public function getHoliday()
83
    {
84
        return $this->container->get('holiday');
85
    }
86
87
    /**
88
     * 获取Nationality服务
89
     *
90
     * @return NationalityServiceInterface
91
     */
92
    public function getNationality()
93
    {
94
        return $this->container->get('nationality');
95
    }
96
97
    /**
98
     * 获取Region服务
99
     *
100
     * @return RegionServiceInterface
101
     */
102
    public function getRegion()
103
    {
104
        return $this->container->get('region');
105
    }
106
107
    /**
108
     * 获取名称.
109
     *
110
     * @return string
111
     */
112
    public function getName()
113
    {
114
        return $this->name;
115
    }
116
117
    /**
118
     * 获取官方名称.
119
     *
120
     * @return string
121
     */
122
    public function getOfficialName()
123
    {
124
        return $this->officialName;
125
    }
126
127
    /**
128
     * 获取ISO3166两位代码
129
     *
130
     * @return string
131
     */
132
    public function getIsoCode()
133
    {
134
        return $this->isoCode;
135
    }
136
137
    /**
138
     * 获取语言
139
     *
140
     * @return array
141
     */
142
    public function getLanguages()
143
    {
144
        return $this->languages;
145
    }
146
}