r75351 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75350‎ | r75351 | r75352 >
Date:12:45, 25 October 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Extended layer handling to have multiple types of layers, each of which can be supported by one or more mapping services
Modified paths:
  • /trunk/extensions/Maps/Maps.i18n.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_ImageLayer.php (added) (history)
  • /trunk/extensions/Maps/includes/Maps_Layer.php (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_LayerPage.php (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_Layers.php (modified) (history)
  • /trunk/extensions/Maps/includes/criteria/CriterionMapLayer.php (added) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/CriterionOLLayer.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/Maps_ParamOLLayers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps.i18n.php
@@ -28,6 +28,9 @@
2929 'maps-layer-value' => 'Value',
3030 'maps-layer-errors' => 'Errors',
3131 'maps-error-invalid-layerdef' => 'This layer definition is not valid.',
 32+ 'maps-error-invalid-layertype' => 'There are no layers of type "$1". Only {{PLURAL:$3|this type is|these types are}} supported: $2',
 33+ 'validation-error-invalid-layer' => 'Parameter $1 must be a valid layer.',
 34+ 'validation-error-invalid-layers' => 'Parameter $1 must be one or more valid layers.',
3235
3336 // Validation
3437 'validation-error-invalid-location' => 'Parameter $1 must be a valid location.',
@@ -41,8 +44,6 @@
4245
4346 'validation-error-invalid-goverlay' => 'Parameter $1 must be a valid overlay.',
4447 'validation-error-invalid-goverlays' => 'Parameter $1 must be one or more valid overlays.',
45 - 'validation-error-invalid-ollayer' => 'Parameter $1 must be a valid layer.',
46 - 'validation-error-invalid-ollayers' => 'Parameter $1 must be one or more valid layers.',
4748
4849 // Coordinate handling
4950 'maps-abb-north' => 'N',
Index: trunk/extensions/Maps/Maps.php
@@ -61,8 +61,10 @@
6262 $wgAutoloadClasses['MapsGeoFunctions'] = $incDir . 'Maps_GeoFunctions.php';
6363 $wgAutoloadClasses['MapsGeocoders'] = $incDir . 'Maps_Geocoders.php';
6464 $wgAutoloadClasses['MapsGeocoder'] = $incDir . 'Maps_Geocoder.php';
 65+ $wgAutoloadClasses['MapsImageLayer'] = $incDir . 'Maps_ImageLayer.php';
6566 $wgAutoloadClasses['MapsLayer'] = $incDir . 'Maps_Layer.php';
6667 $wgAutoloadClasses['MapsLayerPage'] = $incDir . 'Maps_LayerPage.php';
 68+ $wgAutoloadClasses['MapsLayers'] = $incDir . 'Maps_Layers.php';
6769 $wgAutoloadClasses['iMappingFeature'] = $incDir . 'iMappingFeature.php';
6870 $wgAutoloadClasses['iMappingService'] = $incDir . 'iMappingService.php';
6971 $wgAutoloadClasses['MapsMappingServices'] = $incDir . 'Maps_MappingServices.php';
@@ -74,6 +76,7 @@
7577 $wgAutoloadClasses['CriterionIsImage'] = $criDir . 'CriterionIsImage.php';
7678 $wgAutoloadClasses['CriterionIsLocation'] = $criDir . 'CriterionIsLocation.php';
7779 $wgAutoloadClasses['CriterionMapDimension'] = $criDir . 'CriterionMapDimension.php';
 80+ $wgAutoloadClasses['CriterionMapLayer'] = $criDir . 'CriterionMapLayer.php';
7881
7982 // Autoload the "includes/features/" classes.
8083 $ftDir = $incDir . '/features/';
@@ -133,6 +136,9 @@
134137 // Since 0.7.1
135138 $wgHooks['ArticleFromTitle'][] = 'MapsHooks::onArticleFromTitle';
136139
 140+ // Since 0.7.2
 141+ $wgHooks['MappingLayersInitialization'][] = 'MapsImageLayer::register';
 142+
137143 $egMapsFeatures = array();
138144
139145 // Include the settings file.
Index: trunk/extensions/Maps/includes/Maps_LayerPage.php
@@ -9,6 +9,8 @@
1010 * @ingroup Maps
1111 *
1212 * @author Jeroen De Dauw
 13+ *
 14+ * TODO: check for the page being not created yet (then it's not invalid if there is nothing there...)
1315 */
1416 class MapsLayerPage extends Article {
1517
@@ -22,6 +24,15 @@
2325 protected $cachedLayer = false;
2426
2527 /**
 28+ * Cached key-value pairs or false.
 29+ *
 30+ * @since 0.7.2
 31+ *
 32+ * @var false or array
 33+ */
 34+ protected $keyValuePairs = false;
 35+
 36+ /**
2637 * Constructor.
2738 *
2839 * @since 0.7.1
@@ -42,8 +53,33 @@
4354
4455 $wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
4556
46 - $layer = $this->getLayer();
47 -
 57+ if ( MapsLayers::hasLayer( $this->getLayerType() ) ) {
 58+ $this->displayLayerDefinition( MapsLayers::getLayer( $this->getLayerType() ) );
 59+ }
 60+ else {
 61+ $availableLayerTypes = MapsLayers::getAvailableLayers();
 62+ $wgOut->addHTML(
 63+ '<span class="errorbox">' .
 64+ htmlspecialchars( wfMsgExt(
 65+ 'maps-error-invalid-layertype',
 66+ 'parsemag',
 67+ $this->getLayerType(),
 68+ $availableLayerTypes,
 69+ count( $availableLayerTypes )
 70+ ) ) .
 71+ '</span><br />'
 72+ );
 73+ }
 74+ }
 75+
 76+ /**
 77+ * Displays the layer definition as a table.
 78+ *
 79+ * @since 0.7.2
 80+ *
 81+ * @param MapsLayer $layer
 82+ */
 83+ protected function displayLayerDefinition( MapsLayer $layer ) {
4884 $errorHeader = '';
4985
5086 if ( !$layer->isValid() ) {
@@ -121,7 +157,7 @@
122158 );
123159 }
124160
125 - $wgOut->addHTML( Html::rawElement( 'table', array( 'width' => '100%', 'class' => 'wikitable sortable' ), implode( "\n", $rows ) ) );
 161+ $wgOut->addHTML( Html::rawElement( 'table', array( 'width' => '100%', 'class' => 'wikitable sortable' ), implode( "\n", $rows ) ) );
126162 }
127163
128164 /**
@@ -131,9 +167,14 @@
132168 *
133169 * @return boolean
134170 */
135 - public function hasValidDefinition() {
136 - $layer = $this->getLayer();
137 - return $layer->isValid();
 171+ public function hasValidDefinition( $service = null ) {
 172+ if ( MapsLayers::hasLayer( $this->getLayerType(), $service ) ) {
 173+ $layer = $this->getLayer();
 174+ return $layer->isValid();
 175+ }
 176+ else {
 177+ return false;
 178+ }
138179 }
139180
140181 /**
@@ -145,7 +186,7 @@
146187 */
147188 public function getLayer() {
148189 if ( $this->cachedLayer === false ) {
149 - $this->cachedLayer = new MapsLayer( $this->getProperties() );
 190+ $this->cachedLayer = MapsLayers::getLayer( $this->getLayerType(), $this->getProperties() );
150191 }
151192
152193 return $this->cachedLayer;
@@ -158,24 +199,53 @@
159200 *
160201 * @return array
161202 */
162 - protected function getProperties() {
163 - $properties = array();
 203+ final protected function getProperties() {
 204+ $properties = $this->getKeyValuePairs();
164205
165 - if ( is_null( $this->mContent ) ) {
166 - $this->loadContent();
 206+ if ( array_key_exists( 'type', $properties ) ) {
 207+ unset( $properties['type'] );
167208 }
168209
169 - foreach ( explode( "\n", $this->mContent ) as $line ) {
170 - $parts = explode( '=', $line, 2 );
 210+ return $properties;
 211+ }
 212+
 213+ /**
 214+ * Gets the layer type of false if none is set.
 215+ *
 216+ * @since 0.7.2
 217+ *
 218+ * @return string or false
 219+ */
 220+ final protected function getLayerType() {
 221+ $properties = $this->getKeyValuePairs();
 222+ return array_key_exists( 'type' , $properties ) ? $properties['type'] : false;
 223+ }
 224+
 225+ /**
 226+ * Returns all key-value pairs stored in the page.
 227+ *
 228+ * @since 0.7.2
 229+ *
 230+ * @return array
 231+ */
 232+ final protected function getKeyValuePairs() {
 233+ if ( $this->keyValuePairs === false ) {
 234+ $this->keyValuePairs = array();
171235
172 - if ( count( $parts ) == 2 ) {
173 - $properties[strtolower( str_replace( ' ', '', $parts[0] ) )] = $parts[1];
 236+ if ( is_null( $this->mContent ) ) {
 237+ $this->loadContent();
174238 }
 239+
 240+ foreach ( explode( "\n", $this->mContent ) as $line ) {
 241+ $parts = explode( '=', $line, 2 );
 242+
 243+ if ( count( $parts ) == 2 ) {
 244+ $this->keyValuePairs[strtolower( str_replace( ' ', '', $parts[0] ) )] = $parts[1];
 245+ }
 246+ }
175247 }
176 -
177 - $properties['type'] = array_key_exists( 'type', $properties ) ? $properties['type'] : MapsLayer::getDefaultType();
178248
179 - return $properties;
 249+ return $this->keyValuePairs;
180250 }
181251
182252 }
\ No newline at end of file
Index: trunk/extensions/Maps/includes/Maps_Layer.php
@@ -9,23 +9,29 @@
1010 * @ingroup Maps
1111 *
1212 * @author Jeroen De Dauw
13 - *
14 - * TODO: this should be probebly integrated into the mapping service system.
1513 */
16 -class MapsLayer {
 14+abstract class MapsLayer {
 15+
 16+ /**
 17+ * Returns an array of parameter definitions.
 18+ *
 19+ * @since 0.7.2
 20+ *
 21+ * @param array $params Array that can already hold definitions for common parameters.
 22+ *
 23+ * @return array
 24+ */
 25+ protected abstract function getParameterDefinitions( array $params );
1726
1827 /**
19 - * List of layer type definitions.
 28+ * Returns a string containing the JavaScript definition of this layer.
 29+ * Only call this function when you are sure the layer is valid!
2030 *
2131 * @since 0.7.1
2232 *
23 - * @var array
 33+ * @return string
2434 */
25 - protected static $types = array(
26 - 'image' => array(
27 - 'class' => 'OpenLayers.Layer.Image',
28 - )
29 - );
 35+ public abstract function getJavaScriptDefinition();
3036
3137 /**
3238 * @since 0.7.1
@@ -51,17 +57,6 @@
5258 protected $hasValidated = false;
5359
5460 /**
55 - * Returns the default layer type.
56 - *
57 - * @since 0.7.1
58 - *
59 - * @return string
60 - */
61 - public static function getDefaultType() {
62 - return 'image';
63 - }
64 -
65 - /**
6661 * Constructor.
6762 *
6863 * @since 0.7.1
@@ -73,17 +68,6 @@
7469 }
7570
7671 /**
77 - * Returns the type of the layer.
78 - *
79 - * @since 0.7.1
80 - *
81 - * @param string
82 - */
83 - public function getType() {
84 - return array_key_exists( 'type', $this->properties ) ? $this->properties['type'] : self::getDefaultType();
85 - }
86 -
87 - /**
8872 * Returns the error messages, optionaly filtered by an error tag.
8973 *
9074 * @since 0.7.1
@@ -116,38 +100,6 @@
117101 }
118102
119103 /**
120 - * Returns an array of parameter definitions.
121 - *
122 - * @since 0.7.1
123 - *
124 - * @return array
125 - */
126 - protected function getParameterDefinitions() {
127 - $params = array();
128 -
129 - $params[] = new Parameter( 'lowerbound', Parameter::TYPE_FLOAT );
130 - $params[] = new Parameter( 'upperbound', Parameter::TYPE_FLOAT );
131 - $params[] = new Parameter( 'leftbound', Parameter::TYPE_FLOAT );
132 - $params[] = new Parameter( 'rightbound', Parameter::TYPE_FLOAT );
133 - $params[] = new Parameter( 'width', Parameter::TYPE_FLOAT );
134 - $params[] = new Parameter( 'height', Parameter::TYPE_FLOAT );
135 -
136 - $params['type'] = new Parameter( 'type' );
137 - $params['type']->addCriteria( New CriterionInArray( array_keys( self::$types ) ) );
138 - $params['type']->addManipulations( new ParamManipulationFunctions( 'strtolower' ) );
139 -
140 - $params[] = new Parameter( 'zoomlevels', Parameter::TYPE_INTEGER, false );
141 -
142 - $params['label'] = new Parameter( 'label' );
143 -
144 - $params['source'] = new Parameter( 'source' );
145 - $params['source']->addCriteria( new CriterionIsImage() );
146 - $params['source']->addManipulations( new MapsParamImage() );
147 -
148 - return $params;
149 - }
150 -
151 - /**
152104 * Validates the layer.
153105 *
154106 * @since 0.7.1
@@ -155,7 +107,7 @@
156108 protected function validate() {
157109 $validator = new Validator();
158110
159 - $validator->setParameters( $this->properties, $this->getParameterDefinitions() );
 111+ $validator->setParameters( $this->properties, $this->getParameterDefinitions( array() ) );
160112 $validator->validateParameters();
161113
162114 if ( $validator->hasFatalError() !== false ) {
@@ -181,38 +133,4 @@
182134 return count( $this->errors ) == 0;
183135 }
184136
185 - /**
186 - * Returns a string containing the JavaScript definition of this layer.
187 - * Only call this function when you are sure the layer is valid!
188 - *
189 - * @since 0.7.1
190 - *
191 - * @return string
192 - */
193 - public function getJavaScriptDefinition() {
194 - foreach ( $this->properties as $name => $value ) {
195 - ${ $name } = MapsMapper::encodeJsVar( $value );
196 - }
197 -
198 - $class = self::$types[$this->getType()]['class'];
199 -
200 - $options = array( 'isImage' => true );
201 -
202 - if ( $this->properties !== false ) {
203 - $options['numZoomLevels'] = $zoomlevels;
204 - }
205 -
206 - $options = Xml::encodeJsVar( (object)$options );
207 -
208 - return <<<EOT
209 - new $class(
210 - $label,
211 - $source,
212 - new OpenLayers.Bounds($leftbound, $lowerbound, $rightbound, $upperbound),
213 - new OpenLayers.Size($width, $height),
214 - {$options}
215 - )
216 -EOT;
217 - }
218 -
219137 }
Index: trunk/extensions/Maps/includes/services/OpenLayers/Maps_ParamOLLayers.php
@@ -70,9 +70,9 @@
7171
7272 if ( $title->getNamespace() == Maps_NS_LAYER && $title->exists() ) {
7373 $layerPage = new MapsLayerPage( $title );
74 - $layer = $layerPage->getLayer();
7574
76 - if ( $layer->isValid() ) {
 75+ if ( $layerPage->hasValidDefinition( 'openlayers' ) ) {
 76+ $layer = $layerPage->getLayer();
7777 if ( !in_array( $layerOrGroup, $layerNames ) ) {
7878 $layerDefs[] = $layer->getJavaScriptDefinition();
7979 $layerNames[] = $layerOrGroup;
Index: trunk/extensions/Maps/includes/services/OpenLayers/CriterionOLLayer.php
@@ -3,7 +3,7 @@
44 /**
55 * Parameter criterion stating that the value must be an OpenLayers layer.
66 *
7 - * @since 0.7
 7+ * @since 0.7.1
88 *
99 * @file CriterionOLLayer.php
1010 * @ingroup Maps
@@ -12,52 +12,28 @@
1313 *
1414 * @author Jeroen De Dauw
1515 */
16 -class CriterionOLLayer extends ItemParameterCriterion {
 16+class CriterionOLLayer extends CriterionMapLayer {
1717
 18+
1819 /**
1920 * Constructor.
2021 *
2122 * @since 0.7
2223 */
2324 public function __construct() {
24 - parent::__construct();
25 - }
 25+ parent::__construct( 'openlayers' );
 26+ }
2627
2728 /**
2829 * @see ItemParameterCriterion::validate
2930 */
3031 protected function doValidation( $value, Parameter $parameter, array $parameters ) {
31 - $dynamicLayers = MapsOpenLayers::getLayerNames( true );
32 -
3332 // Dynamic layers, defined in the settings file or localsettings.
34 - if ( in_array( strtolower( $value ), $dynamicLayers ) ) {
 33+ if ( in_array( strtolower( $value ), MapsOpenLayers::getLayerNames( true ) ) ) {
3534 return true;
3635 }
37 -
38 - // Image layers.
39 - $title = Title::newFromText( $value, Maps_NS_LAYER );
4036
41 - if ( $title->getNamespace() == Maps_NS_LAYER && $title->exists() ) {
42 - $layerPage = new MapsLayerPage( $title );
43 - $layer = $layerPage->getLayer();
44 - return $layer->isValid();
45 - }
46 -
47 - return false;
 37+ return parent::doValidation( $value, $parameter, $parameters );
4838 }
4939
50 - /**
51 - * @see ItemParameterCriterion::getItemErrorMessage
52 - */
53 - protected function getItemErrorMessage( Parameter $parameter ) {
54 - return wfMsgExt( 'validation-error-invalid-ollayer', 'parsemag', $parameter->getOriginalName() );
55 - }
56 -
57 - /**
58 - * @see ItemParameterCriterion::getFullListErrorMessage
59 - */
60 - protected function getFullListErrorMessage( Parameter $parameter ) {
61 - return wfMsgExt( 'validation-error-invalid-ollayers', 'parsemag', $parameter->getOriginalName() );
62 - }
63 -
6440 }
Index: trunk/extensions/Maps/includes/Maps_ImageLayer.php
@@ -0,0 +1,82 @@
 2+<?php
 3+
 4+/**
 5+ * Class for describing image layers.
 6+ *
 7+ * @since 0.7.2
 8+ *
 9+ * @file Maps_ImageLayer.php
 10+ * @ingroup Maps
 11+ *
 12+ * @author Jeroen De Dauw
 13+ */
 14+class MapsImageLayer extends MapsLayer {
 15+
 16+ /**
 17+ * Registeres the layer.
 18+ *
 19+ * @since 0.7.2
 20+ */
 21+ public static function register() {
 22+ MapsLayers::registerLayer( 'image', __CLASS__, 'openlayers' );
 23+ return true;
 24+ }
 25+
 26+ /**
 27+ * @see MapsLayer::getParameterDefinitions
 28+ *
 29+ * @since 0.7.2
 30+ *
 31+ * @return array
 32+ */
 33+ protected function getParameterDefinitions( array $params ) {
 34+ $params[] = new Parameter( 'lowerbound', Parameter::TYPE_FLOAT );
 35+ $params[] = new Parameter( 'upperbound', Parameter::TYPE_FLOAT );
 36+ $params[] = new Parameter( 'leftbound', Parameter::TYPE_FLOAT );
 37+ $params[] = new Parameter( 'rightbound', Parameter::TYPE_FLOAT );
 38+ $params[] = new Parameter( 'width', Parameter::TYPE_FLOAT );
 39+ $params[] = new Parameter( 'height', Parameter::TYPE_FLOAT );
 40+
 41+ $params[] = new Parameter( 'zoomlevels', Parameter::TYPE_INTEGER, false );
 42+
 43+ $params['label'] = new Parameter( 'label' );
 44+
 45+ $params['source'] = new Parameter( 'source' );
 46+ $params['source']->addCriteria( new CriterionIsImage() );
 47+ $params['source']->addManipulations( new MapsParamImage() );
 48+
 49+ return $params;
 50+ }
 51+
 52+ /**
 53+ * @see MapsLayer::getJavaScriptDefinition
 54+ *
 55+ * @since 0.7.1
 56+ *
 57+ * @return string
 58+ */
 59+ public function getJavaScriptDefinition() {
 60+ foreach ( $this->properties as $name => $value ) {
 61+ ${ $name } = MapsMapper::encodeJsVar( $value );
 62+ }
 63+
 64+ $options = array( 'isImage' => true );
 65+
 66+ if ( $this->properties !== false ) {
 67+ $options['numZoomLevels'] = $zoomlevels;
 68+ }
 69+
 70+ $options = Xml::encodeJsVar( (object)$options );
 71+
 72+ return <<<EOT
 73+ new OpenLayers.Layer.Image(
 74+ $label,
 75+ $source,
 76+ new OpenLayers.Bounds($leftbound, $lowerbound, $rightbound, $upperbound),
 77+ new OpenLayers.Size($width, $height),
 78+ {$options}
 79+ )
 80+EOT;
 81+ }
 82+
 83+}
\ No newline at end of file
Property changes on: trunk/extensions/Maps/includes/Maps_ImageLayer.php
___________________________________________________________________
Added: svn:eol-style
184 + native
Index: trunk/extensions/Maps/includes/criteria/CriterionMapLayer.php
@@ -0,0 +1,57 @@
 2+<?php
 3+
 4+/**
 5+ * Parameter criterion stating that the value must be a layer.
 6+ *
 7+ * @since 0.7.2
 8+ *
 9+ * @file CriterionmapLayer.php
 10+ * @ingroup Maps
 11+ * @ingroup Criteria
 12+ *
 13+ * @author Jeroen De Dauw
 14+ */
 15+class CriterionMapLayer extends ItemParameterCriterion {
 16+
 17+ protected $service;
 18+
 19+ /**
 20+ * Constructor.
 21+ *
 22+ * @since 0.7
 23+ */
 24+ public function __construct( $service ) {
 25+ parent::__construct();
 26+
 27+ $this->service = $service;
 28+ }
 29+
 30+ /**
 31+ * @see ItemParameterCriterion::validate
 32+ */
 33+ protected function doValidation( $value, Parameter $parameter, array $parameters ) {
 34+ $title = Title::newFromText( $value, Maps_NS_LAYER );
 35+
 36+ if ( $title->getNamespace() == Maps_NS_LAYER && $title->exists() ) {
 37+ $layerPage = new MapsLayerPage( $title );
 38+ return $layerPage->hasValidDefinition( $this->service );
 39+ }
 40+
 41+ return false;
 42+ }
 43+
 44+ /**
 45+ * @see ItemParameterCriterion::getItemErrorMessage
 46+ */
 47+ protected function getItemErrorMessage( Parameter $parameter ) {
 48+ return wfMsgExt( 'validation-error-invalid-layer', 'parsemag', $parameter->getOriginalName() );
 49+ }
 50+
 51+ /**
 52+ * @see ItemParameterCriterion::getFullListErrorMessage
 53+ */
 54+ protected function getFullListErrorMessage( Parameter $parameter ) {
 55+ return wfMsgExt( 'validation-error-invalid-layers', 'parsemag', $parameter->getOriginalName() );
 56+ }
 57+
 58+}
Property changes on: trunk/extensions/Maps/includes/criteria/CriterionMapLayer.php
___________________________________________________________________
Added: svn:eol-style
159 + native
Index: trunk/extensions/Maps/includes/Maps_Layers.php
@@ -12,7 +12,22 @@
1313 */
1414 class MapsLayers {
1515
 16+ /**
 17+ * List that maps layer types (keys) to their classes (values).
 18+ *
 19+ * @since 0.7.2
 20+ *
 21+ * @var array of string
 22+ */
1623 protected static $classes = array();
 24+
 25+ /**
 26+ * List that maps layer types (keys) to the services that support them (values).
 27+ *
 28+ * @since 0.7.2
 29+ *
 30+ * @var array of array of string
 31+ */
1732 protected static $services = array();
1833
1934 /**
@@ -20,29 +35,64 @@
2136 *
2237 * @since 0.7.2
2338 *
24 - * @param $string $type
 39+ * @param string $type
 40+ * @param array $properties
2541 *
2642 * @return MapsLayer
2743 */
28 - public static function getLayer( $type ) {
 44+ public static function getLayer( $type, array $properties ) {
 45+ self::initializeLayers();
 46+
2947 if ( self::hasLayer( $type ) ) {
30 - return new self::$classes[$type]();
 48+ return new self::$classes[$type]( $properties );
3149 }
3250 else {
3351 throw new exception( "There is no layer class for layer of type $type." );
3452 }
3553 }
 54+
 55+ /**
 56+ * Returns the available layer types, optionaly filtered by them requiring the
 57+ * support of the $service parameter.
 58+ *
 59+ * @since 0.7.2
 60+ *
 61+ * @param string $service
 62+ *
 63+ * @return array
 64+ */
 65+ public static function getAvailableLayers( $service = null ) {
 66+ self::initializeLayers();
 67+
 68+ if ( is_null( $service ) ) {
 69+ return array_keys( self::$classes );
 70+ }
 71+ else {
 72+ $layers = array();
 73+
 74+ foreach ( self::$services as $layerType => $supportedServices ) {
 75+ if ( in_array( $service, $supportedServices ) ) {
 76+ $layers[] = $layerType;
 77+ }
 78+ }
 79+
 80+ return $layers;
 81+ }
 82+ }
3683
3784 /**
3885 * Returns if there is a layer class for the provided layer type.
3986 *
4087 * @since 0.7.2
4188 *
42 - * @param $string $type
 89+ * @param string $type
 90+ * @param string $service
4391 *
4492 * @return boolean
4593 */
4694 public static function hasLayer( $type, $service = null ) {
 95+ self::initializeLayers();
 96+
4797 if ( array_key_exists( $type, self::$classes ) && array_key_exists( $type, self::$services ) ) {
4898 return is_null( $service ) || in_array( $service, self::$services[$type] );
4999 }
@@ -54,6 +104,10 @@
55105 /**
56106 * Register a layer.
57107 *
 108+ * @param string $type
 109+ * @param string $layerClass
 110+ * @param $serviceIdentifier
 111+ *
58112 * @since 0.7.2
59113 */
60114 public static function registerLayer( $type, $layerClass, $serviceIdentifier ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r75352Changes for 0.7.2 - follow up to r75351jeroendedauw13:31, 25 October 2010

Status & tagging log