Index: trunk/extensions/Maps/includes/Maps_Settings.php |
— | — | @@ -13,10 +13,21 @@ |
14 | 14 | */ |
15 | 15 | final class MapsSettings extends ExtensionSettings { |
16 | 16 | |
| 17 | + /** |
| 18 | + * Initiate the settings list if not done already. |
| 19 | + * |
| 20 | + * @since 1.1 |
| 21 | + * |
| 22 | + * @return boolean True if the settings where initiates in this call. |
| 23 | + */ |
17 | 24 | protected static function initIfNeeded() { |
18 | | - parent::initIfNeeded(); |
| 25 | + $init = parent::initIfNeeded(); |
19 | 26 | |
20 | | - self::$settings['php-bc'] = self::getPhpCompatSettings(); |
| 27 | + if ( $init ) { |
| 28 | + self::$settings['php-bc'] = self::getPhpCompatSettings(); |
| 29 | + } |
| 30 | + |
| 31 | + return $init; |
21 | 32 | } |
22 | 33 | |
23 | 34 | /** |
— | — | @@ -76,8 +87,23 @@ |
77 | 88 | |
78 | 89 | abstract class ExtensionSettings { |
79 | 90 | |
| 91 | + /** |
| 92 | + * The different groups of settings. |
| 93 | + * array[ group name => array[ setting name => setting value ] ] |
| 94 | + * |
| 95 | + * @since 1.1 |
| 96 | + * @var array |
| 97 | + */ |
80 | 98 | protected static $settings = false; |
81 | 99 | |
| 100 | + /** |
| 101 | + * Cached merged settings groups. The keys are the name of the |
| 102 | + * cache, which is created by joining the group names with a |. |
| 103 | + * array[ cache name => settings[] ] |
| 104 | + * |
| 105 | + * @since 1.1 |
| 106 | + * @var array |
| 107 | + */ |
82 | 108 | protected static $mergedCaches = array(); |
83 | 109 | |
84 | 110 | /** |
— | — | @@ -89,13 +115,24 @@ |
90 | 116 | */ |
91 | 117 | protected abstract static function getDefaultSettings(); |
92 | 118 | |
| 119 | + /** |
| 120 | + * Initiate the settings list if not done already. |
| 121 | + * |
| 122 | + * @since 1.1 |
| 123 | + * |
| 124 | + * @return boolean True if the settings where initiates in this call. |
| 125 | + */ |
93 | 126 | protected static function initIfNeeded() { |
94 | | - if ( self::$settings === false ) { |
| 127 | + $init = self::$settings === false; |
| 128 | + |
| 129 | + if ( $init ) { |
95 | 130 | self::$settings = array( |
96 | 131 | 'default' => self::getDefaultSettings(), |
97 | 132 | 'php' => self::getPhpSettings() |
98 | 133 | ); |
99 | 134 | } |
| 135 | + |
| 136 | + return $init; |
100 | 137 | } |
101 | 138 | |
102 | 139 | protected static function getMergedSettings( array $groups, $cache = true ) { |
— | — | @@ -213,14 +250,25 @@ |
214 | 251 | elseif ( $invalidateCache |
215 | 252 | && ( !array_key_exists( $settingName, self::$settings[$groupName] ) |
216 | 253 | || self::$settings[$groupName][$settingName] !== $settingValue ) ) { |
217 | | - foreach ( array_keys( self::$mergedCaches ) as $cacheName ) { |
218 | | - if ( in_array( $groupName, explode( '|', $cacheName ) ) ) { |
219 | | - unset( self::$mergedCaches[$cacheName] ); |
220 | | - } |
221 | | - } |
| 254 | + self::ivalidateCachesForGroup( $groupName ); |
222 | 255 | } |
223 | 256 | |
224 | 257 | self::$settings[$groupName][$settingName] = $settingValue; |
225 | 258 | } |
226 | 259 | |
| 260 | + /** |
| 261 | + * Invalidate the cahces that contain data from the specified group. |
| 262 | + * |
| 263 | + * @since 1.1 |
| 264 | + * |
| 265 | + * @param name $group |
| 266 | + */ |
| 267 | + protected static function ivalidateCachesForGroup( $group ) { |
| 268 | + foreach ( array_keys( self::$mergedCaches ) as $cacheName ) { |
| 269 | + if ( in_array( $groupName, explode( '|', $cacheName ) ) ) { |
| 270 | + unset( self::$mergedCaches[$cacheName] ); |
| 271 | + } |
| 272 | + } |
| 273 | + } |
| 274 | + |
227 | 275 | } |