1: | <?php
|
2: | namespace Duyplus\TMDBApi\Classes\Config;
|
3: |
|
4: | class Configuration
|
5: | {
|
6: |
|
7: |
|
8: |
|
9: |
|
10: | private $apikey = '';
|
11: | private $lang = 'en';
|
12: | private $timezone = 'Europe/Berlin';
|
13: | private $adult = false;
|
14: | private $debug = false;
|
15: |
|
16: | |
17: | |
18: |
|
19: | private $appender = array(
|
20: | 'movie' => array('trailers', 'images', 'credits', 'translations', 'reviews'),
|
21: | 'tvshow' => array('trailers', 'images', 'credits', 'translations', 'keywords'),
|
22: | 'season' => array('trailers', 'images', 'credits', 'translations'),
|
23: | 'episode' => array('trailers', 'images', 'credits', 'translations'),
|
24: | 'person' => array('movie_credits', 'tv_credits', 'images'),
|
25: | 'collection' => array('images'),
|
26: | 'company' => array('movies'),
|
27: | );
|
28: |
|
29: | |
30: | |
31: | |
32: | |
33: |
|
34: | public function __construct($cnf = null)
|
35: | {
|
36: |
|
37: | if (is_string($cnf)) {
|
38: | if (file_exists($cnf)) {
|
39: | include($cnf);
|
40: | if (is_array($cnf)) {
|
41: | $this->configure($cnf);
|
42: | }
|
43: | }
|
44: | } elseif (is_array($cnf)) {
|
45: | $this->configure($cnf);
|
46: | } else {
|
47: |
|
48: | $dir = dirname(__FILE__);
|
49: | $configDir = realpath($dir . '/../../Config');
|
50: | if (file_exists($configDir . '/Default.php')) {
|
51: | include($configDir . '/Default.php');
|
52: | $this->configure($cnf);
|
53: | }
|
54: | }
|
55: | }
|
56: |
|
57: |
|
58: |
|
59: |
|
60: |
|
61: | |
62: | |
63: | |
64: | |
65: |
|
66: | public function setAPIKey($apikey)
|
67: | {
|
68: | $this->apikey = $apikey;
|
69: | }
|
70: |
|
71: | |
72: | |
73: | |
74: | |
75: |
|
76: | public function setLang($lang)
|
77: | {
|
78: | $this->lang = $lang;
|
79: | }
|
80: |
|
81: | |
82: | |
83: | |
84: | |
85: |
|
86: | public function setTimeZone($timezone)
|
87: | {
|
88: | $this->timezone = $timezone;
|
89: | }
|
90: |
|
91: | |
92: | |
93: | |
94: | |
95: |
|
96: | public function setAdult($adult)
|
97: | {
|
98: | $this->adult = $adult;
|
99: | }
|
100: |
|
101: | |
102: | |
103: | |
104: | |
105: |
|
106: | public function setDebug($debug)
|
107: | {
|
108: | $this->debug = $debug;
|
109: | }
|
110: |
|
111: | |
112: | |
113: | |
114: | |
115: | |
116: |
|
117: | public function setAppender($appender, $type)
|
118: | {
|
119: | $this->appender[$type] = $appender;
|
120: | }
|
121: |
|
122: |
|
123: |
|
124: |
|
125: |
|
126: | |
127: | |
128: | |
129: | |
130: |
|
131: | public function getAPIKey()
|
132: | {
|
133: | return $this->apikey;
|
134: | }
|
135: |
|
136: | |
137: | |
138: | |
139: | |
140: |
|
141: | public function getLang()
|
142: | {
|
143: | return $this->lang;
|
144: | }
|
145: |
|
146: | |
147: | |
148: | |
149: | |
150: |
|
151: | public function getTimeZone()
|
152: | {
|
153: | return $this->timezone;
|
154: | }
|
155: |
|
156: | |
157: | |
158: | |
159: | |
160: |
|
161: | public function getAdult()
|
162: | {
|
163: | return $this->adult;
|
164: | }
|
165: |
|
166: | |
167: | |
168: | |
169: | |
170: |
|
171: | public function getDebug()
|
172: | {
|
173: | return $this->debug;
|
174: | }
|
175: |
|
176: | |
177: | |
178: | |
179: | |
180: |
|
181: | public function getAppender($type)
|
182: | {
|
183: | return $this->appender[$type];
|
184: | }
|
185: |
|
186: |
|
187: |
|
188: |
|
189: |
|
190: | |
191: | |
192: | |
193: | |
194: |
|
195: | private function configure($cnf)
|
196: | {
|
197: | if (isset($cnf['apikey'])) {
|
198: | $this->setAPIKey($cnf['apikey']);
|
199: | }
|
200: | if (isset($cnf['lang'])) {
|
201: | $this->setLang($cnf['lang']);
|
202: | }
|
203: | if (isset($cnf['timezone'])) {
|
204: | $this->setTimeZone($cnf['timezone']);
|
205: | }
|
206: | if (isset($cnf['adult'])) {
|
207: | $this->setAdult($cnf['adult']);
|
208: | }
|
209: | if (isset($cnf['debug'])) {
|
210: | $this->setDebug($cnf['debug']);
|
211: | }
|
212: | if (isset($cnf['appender']) && is_array($cnf['appender'])) {
|
213: | foreach ($cnf['appender'] as $type => $appender) {
|
214: | $this->setAppender($appender, $type);
|
215: | }
|
216: | }
|
217: | }
|
218: | } |