1: <?php
2: /**
3: * Wei Framework
4: *
5: * @copyright Copyright (c) 2008-2015 Twin Huang
6: * @license http://opensource.org/licenses/mit-license.php MIT License
7: */
8:
9: namespace Wei;
10:
11: /**
12: * A service to manage service container configurations
13: *
14: * @author Twin Huang <twinhuang@qq.com>
15: */
16: class Config extends Base
17: {
18: /**
19: * Convert configuration data to JSON
20: *
21: * @param string $name The name of configuration item
22: * @return string
23: */
24: public function toJson($name)
25: {
26: return json_encode($this->wei->getConfig($name));
27: }
28:
29: /**
30: * Convert configuration data to HTML select options
31: *
32: * @param string $name The name of configuration item
33: * @return string
34: */
35: public function toOptions($name)
36: {
37: $html = '';
38: foreach ($this->wei->getConfig($name) as $value => $text) {
39: if (is_array($text)) {
40: $html .= '<optgroup label="' . $value . '">';
41: foreach ($text as $v => $t) {
42: $html .= '<option value="' . $v . '">' . $t . '</option>';
43: }
44: $html .= '</optgroup>';
45: } else {
46: $html .= '<option value="' . $value . '">' . $text . '</option>';
47: }
48: }
49: return $html;
50: }
51:
52: /**
53: * Returns the value by the map name and key
54: *
55: * @param string $name The name of the map
56: * @param string $key The key name in the map
57: * @return mixed
58: */
59: public function getMap($name, $key)
60: {
61: return $this->wei->getConfig($name . ':' . $key);
62: }
63: }
64: