Index: trunk/extensions/Maps/includes/Maps_Layers.php |
— | — | @@ -0,0 +1,74 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Static class for layer functionality. |
| 6 | + * |
| 7 | + * @since 0.7.2 |
| 8 | + * |
| 9 | + * @file Maps_Layers.php |
| 10 | + * @ingroup Maps |
| 11 | + * |
| 12 | + * @author Jeroen De Dauw |
| 13 | + */ |
| 14 | +class MapsLayers { |
| 15 | + |
| 16 | + protected static $classes = array(); |
| 17 | + protected static $services = array(); |
| 18 | + |
| 19 | + /** |
| 20 | + * Returns a new instance of a layer class for the provided layer type. |
| 21 | + * |
| 22 | + * @since 0.7.2 |
| 23 | + * |
| 24 | + * @param $string $type |
| 25 | + * |
| 26 | + * @return MapsLayer |
| 27 | + */ |
| 28 | + public static function getLayer( $type ) { |
| 29 | + if ( self::hasLayer( $type ) ) { |
| 30 | + return new self::$classes[$type](); |
| 31 | + } |
| 32 | + else { |
| 33 | + throw new exception( "There is no layer class for layer of type $type." ); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Returns if there is a layer class for the provided layer type. |
| 39 | + * |
| 40 | + * @since 0.7.2 |
| 41 | + * |
| 42 | + * @param $string $type |
| 43 | + * |
| 44 | + * @return boolean |
| 45 | + */ |
| 46 | + public static function hasLayer( $type, $service = null ) { |
| 47 | + if ( array_key_exists( $type, self::$classes ) && array_key_exists( $type, self::$services ) ) { |
| 48 | + return is_null( $service ) || in_array( $service, self::$services[$type] ); |
| 49 | + } |
| 50 | + else { |
| 51 | + return false; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Register a layer. |
| 57 | + * |
| 58 | + * @since 0.7.2 |
| 59 | + */ |
| 60 | + public static function registerLayer( $type, $layerClass, $serviceIdentifier ) { |
| 61 | + self::$classes[$type] = $layerClass; |
| 62 | + self::$services[$type][] = $serviceIdentifier; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Initializes the layers functionality by registering the layer types |
| 67 | + * by firing the hook. |
| 68 | + * |
| 69 | + * @since 0.7.2 |
| 70 | + */ |
| 71 | + protected static function initializeLayers() { |
| 72 | + wfRunHooks( 'MappingLayersInitialization' ); |
| 73 | + } |
| 74 | + |
| 75 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Maps/includes/Maps_Layers.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 76 | + native |