1: <?php
2: namespace Duyplus\TMDBApi\Classes\Config;
3:
4: class Configuration
5: {
6: //------------------------------------------------------------------------------
7: // Class Variables
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: * Data Return Configuration - Manipulate if you want to tune your results
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: * Construct Class
31: *
32: * @param array $config
33: */
34: public function __construct($cnf = null)
35: {
36: // Path to configuration file if given
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: // Load default configuration
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: // Setup Functions
59: //------------------------------------------------------------------------------
60:
61: /**
62: * Set the API Key
63: *
64: * @param string $apikey
65: */
66: public function setAPIKey($apikey)
67: {
68: $this->apikey = $apikey;
69: }
70:
71: /**
72: * Set the language code
73: *
74: * @param string $lang
75: */
76: public function setLang($lang)
77: {
78: $this->lang = $lang;
79: }
80:
81: /**
82: * Set the timezone
83: *
84: * @param string $timezone
85: */
86: public function setTimeZone($timezone)
87: {
88: $this->timezone = $timezone;
89: }
90:
91: /**
92: * Set the adult flag
93: *
94: * @param boolean $adult
95: */
96: public function setAdult($adult)
97: {
98: $this->adult = $adult;
99: }
100:
101: /**
102: * Set the debug flag
103: *
104: * @param boolean $debug
105: */
106: public function setDebug($debug)
107: {
108: $this->debug = $debug;
109: }
110:
111: /**
112: * Set the appender for a type of result
113: *
114: * @param string $type
115: * @param array $data
116: */
117: public function setAppender($appender, $type)
118: {
119: $this->appender[$type] = $appender;
120: }
121:
122: //------------------------------------------------------------------------------
123: // Get Variables
124: //------------------------------------------------------------------------------
125:
126: /**
127: * Get the API Key
128: *
129: * @return string
130: */
131: public function getAPIKey()
132: {
133: return $this->apikey;
134: }
135:
136: /**
137: * Get the language code
138: *
139: * @return string
140: */
141: public function getLang()
142: {
143: return $this->lang;
144: }
145:
146: /**
147: * Get the timezone
148: *
149: * @return string
150: */
151: public function getTimeZone()
152: {
153: return $this->timezone;
154: }
155:
156: /**
157: * Get the adult flag
158: *
159: * @return boolean
160: */
161: public function getAdult()
162: {
163: return $this->adult;
164: }
165:
166: /**
167: * Get the debug flag
168: *
169: * @return boolean
170: */
171: public function getDebug()
172: {
173: return $this->debug;
174: }
175:
176: /**
177: * Get the appender for a type of result
178: *
179: * @return array
180: */
181: public function getAppender($type)
182: {
183: return $this->appender[$type];
184: }
185:
186: //------------------------------------------------------------------------------
187: // Private Methods
188: //------------------------------------------------------------------------------
189:
190: /**
191: * Configure the class variables
192: *
193: * @param array $cnf
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: }