Index: trunk/extensions/Survey/Survey.settings.php |
— | — | @@ -18,6 +18,14 @@ |
19 | 19 | */ |
20 | 20 | class SurveySettings { |
21 | 21 | |
| 22 | + /** |
| 23 | + * Returns the default values for the settings. |
| 24 | + * setting name (string) => setting value (mixed) |
| 25 | + * |
| 26 | + * @since 0.1 |
| 27 | + * |
| 28 | + * @return array |
| 29 | + */ |
22 | 30 | protected static function getDefaultSettings() { |
23 | 31 | return array( |
24 | 32 | 'JSDebug' => false, |
— | — | @@ -30,6 +38,15 @@ |
31 | 39 | ); |
32 | 40 | } |
33 | 41 | |
| 42 | + /** |
| 43 | + * Retruns an array with all settings after making sure they are |
| 44 | + * initialized (ie set settings have been merged with the defaults). |
| 45 | + * setting name (string) => setting value (mixed) |
| 46 | + * |
| 47 | + * @since 0.1 |
| 48 | + * |
| 49 | + * @return array |
| 50 | + */ |
34 | 51 | public static function getSettings() { |
35 | 52 | static $settings = false; |
36 | 53 | |
— | — | @@ -43,9 +60,24 @@ |
44 | 61 | return $settings; |
45 | 62 | } |
46 | 63 | |
| 64 | + /** |
| 65 | + * Gets the value of the specified setting. |
| 66 | + * |
| 67 | + * @since 0.1 |
| 68 | + * |
| 69 | + * @param string $settingName |
| 70 | + * |
| 71 | + * @throws MWException |
| 72 | + * @return mixed |
| 73 | + */ |
47 | 74 | public static function get( $settingName ) { |
48 | 75 | $settings = self::getSettings(); |
49 | | - return array_key_exists( $settingName, $settings ) ? $settings[$settingName] : null; |
| 76 | + |
| 77 | + if ( !array_key_exists( $settingName, $settings ) ) { |
| 78 | + throw new MWException( 'Attempt to get non-existing setting "' . $settingName . '"' ); |
| 79 | + } |
| 80 | + |
| 81 | + return $settings[$settingName]; |
50 | 82 | } |
51 | 83 | |
52 | 84 | } |