r70288 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70287‎ | r70288 | r70289 >
Date:19:45, 1 August 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6.6 - Added MapsMappingServices class and moved over some code to it
Modified paths:
  • /trunk/extensions/Maps/Features/Maps_ParserFunctions.php (modified) (history)
  • /trunk/extensions/Maps/Includes/Maps_Mapper.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Services/Maps_MappingService.php (modified) (history)
  • /trunk/extensions/Maps/Services/Maps_MappingServices.php (added) (history)

Diff [purge]

Index: trunk/extensions/Maps/Services/Maps_MappingService.php
@@ -79,89 +79,6 @@
8080 private $dependencies = array();
8181
8282 /**
83 - * Retuns an instance of a MapsMappingService. The service name is validated
84 - * and aliases are resolved and a check is made if the feature is supported.
85 - * If the feature is not supported, or the service does not exist, defaulting
86 - * will be used.
87 - *
88 - * @since 0.6.6
89 - *
90 - * @param string $service
91 - * @param string $feature
92 - *
93 - * @return iMappingService
94 - */
95 - public static function getServiceInstance( $service, $feature ) {
96 - global $egMapsServices;
97 - return $egMapsServices[self::getValidService( $service, $feature )];
98 - }
99 -
100 - /**
101 - * Returns a valid service. When an invalid service is provided, the default one will be returned.
102 - * Aliases are also chancged into the main service names @see MapsMapper::getMainServiceName.
103 - *
104 - * @since 0.6.6
105 - *
106 - * @param string $service
107 - * @param string $feature
108 - *
109 - * @return string
110 - */
111 - public static function getValidService( $service, $feature ) {
112 - global $egMapsServices, $egMapsDefaultService, $egMapsDefaultServices, $shouldChange;
113 -
114 - // Get rid of any aliases.
115 - $service = self::getMainServiceName( $service );
116 -
117 - // If the service is not loaded into maps, it should be changed.
118 - $shouldChange = !array_key_exists( $service, $egMapsServices );
119 -
120 - // If it should not be changed, ensure the service supports this feature.
121 - if ( !$shouldChange ) {
122 - $shouldChange = $egMapsServices[$service]->getFeature( $feature ) === false;
123 - }
124 -
125 - // Change the service to the most specific default value available.
126 - // Note: the default services should support their corresponding features.
127 - // If they don't, a fatal error will occur later on.
128 - if ( $shouldChange ) {
129 - if ( array_key_exists( $feature, $egMapsDefaultServices ) ) {
130 - $service = $egMapsDefaultServices[$feature];
131 - }
132 - else {
133 - $service = $egMapsDefaultService;
134 - }
135 - }
136 -
137 - return $service;
138 - }
139 -
140 - /**
141 - * Checks if the service name is an alias for an actual service,
142 - * and changes it into the main service name if this is the case.
143 - *
144 - * @since 0.6.6
145 - *
146 - * @param string $service
147 - *
148 - * @return string
149 - */
150 - private static function getMainServiceName( $service ) {
151 - global $egMapsServices;
152 -
153 - if ( !array_key_exists( $service, $egMapsServices ) ) {
154 - foreach ( $egMapsServices as $serviceObject ) {
155 - if ( $serviceObject->hasAlias( $service ) ) {
156 - $service = $serviceObject->getName();
157 - break;
158 - }
159 - }
160 - }
161 -
162 - return $service;
163 - }
164 -
165 - /**
16683 * Constructor. Creates a new instance of MapsMappingService.
16784 *
16885 * @since 0.6.3
Index: trunk/extensions/Maps/Services/Maps_MappingServices.php
@@ -0,0 +1,114 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the MapsMappingServices class.
 6+ *
 7+ * @file Maps_MappingServices.php
 8+ * @ingroup Maps
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if ( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+/**
 18+ * Class serving as a factory for the MapsMappingService classes.
 19+ *
 20+ * @since 0.6.6
 21+ *
 22+ * @author Jeroen De Dauw
 23+ */
 24+class MapsMappingServices {
 25+
 26+ protected static $services = array();
 27+
 28+ public static function registerService() {
 29+
 30+ }
 31+
 32+ /**
 33+ * Retuns an instance of a MapsMappingService. The service name is validated
 34+ * and aliases are resolved and a check is made if the feature is supported.
 35+ * If the feature is not supported, or the service does not exist, defaulting
 36+ * will be used.
 37+ *
 38+ * @since 0.6.6
 39+ *
 40+ * @param string $service
 41+ * @param string $feature
 42+ *
 43+ * @return iMappingService
 44+ */
 45+ public static function getServiceInstance( $service, $feature ) {
 46+ global $egMapsServices;
 47+ return $egMapsServices[self::getValidService( $service, $feature )];
 48+ }
 49+
 50+ /**
 51+ * Returns a valid service. When an invalid service is provided, the default one will be returned.
 52+ * Aliases are also chancged into the main service names @see MapsMapper::getMainServiceName.
 53+ *
 54+ * @since 0.6.6
 55+ *
 56+ * @param string $service
 57+ * @param string $feature
 58+ *
 59+ * @return string
 60+ */
 61+ public static function getValidService( $service, $feature ) {
 62+ global $egMapsServices, $egMapsDefaultService, $egMapsDefaultServices, $shouldChange;
 63+
 64+ // Get rid of any aliases.
 65+ $service = self::getMainServiceName( $service );
 66+
 67+ // If the service is not loaded into maps, it should be changed.
 68+ $shouldChange = !array_key_exists( $service, $egMapsServices );
 69+
 70+ // If it should not be changed, ensure the service supports this feature.
 71+ if ( !$shouldChange ) {
 72+ $shouldChange = $egMapsServices[$service]->getFeature( $feature ) === false;
 73+ }
 74+
 75+ // Change the service to the most specific default value available.
 76+ // Note: the default services should support their corresponding features.
 77+ // If they don't, a fatal error will occur later on.
 78+ if ( $shouldChange ) {
 79+ if ( array_key_exists( $feature, $egMapsDefaultServices ) ) {
 80+ $service = $egMapsDefaultServices[$feature];
 81+ }
 82+ else {
 83+ $service = $egMapsDefaultService;
 84+ }
 85+ }
 86+
 87+ return $service;
 88+ }
 89+
 90+ /**
 91+ * Checks if the service name is an alias for an actual service,
 92+ * and changes it into the main service name if this is the case.
 93+ *
 94+ * @since 0.6.6
 95+ *
 96+ * @param string $service
 97+ *
 98+ * @return string
 99+ */
 100+ protected static function getMainServiceName( $service ) {
 101+ global $egMapsServices;
 102+
 103+ if ( !array_key_exists( $service, $egMapsServices ) ) {
 104+ foreach ( $egMapsServices as $serviceObject ) {
 105+ if ( $serviceObject->hasAlias( $service ) ) {
 106+ $service = $serviceObject->getName();
 107+ break;
 108+ }
 109+ }
 110+ }
 111+
 112+ return $service;
 113+ }
 114+
 115+}
\ No newline at end of file
Property changes on: trunk/extensions/Maps/Services/Maps_MappingServices.php
___________________________________________________________________
Added: svn:eol-style
1116 + native
Index: trunk/extensions/Maps/Includes/Maps_Mapper.php
@@ -97,10 +97,10 @@
9898 }
9999
100100 /**
101 - * @deprecated Method moved to MapsMappingService. Will be removed in 0.7.
 101+ * @deprecated Method moved to MapsMappingServices. Will be removed in 0.7.
102102 */
103103 public static function getValidService( $service, $feature ) {
104 - MapsMappingService::getValidService( $service, $feature );
 104+ MapsMappingServices::getValidService( $service, $feature );
105105 }
106106
107107 /**
Index: trunk/extensions/Maps/Maps.php
@@ -103,6 +103,7 @@
104104
105105 // Load the "service/" classes and interfaces.
106106 require_once $egMapsDir . 'Services/iMappingService.php';
 107+ $wgAutoloadClasses['MapsMappingServices'] = $egMapsDir . 'Services/Maps_MappingServices.php';
107108 $wgAutoloadClasses['MapsMappingService'] = $egMapsDir . 'Services/Maps_MappingService.php';
108109
109110 wfRunHooks( 'MappingServiceLoad' );
Index: trunk/extensions/Maps/Features/Maps_ParserFunctions.php
@@ -83,7 +83,7 @@
8484 }
8585
8686 // Get the instance of the service class.
87 - $service = MapsMappingService::getServiceInstance( $setService ? $serviceName : '', $parserFunction );
 87+ $service = MapsMappingServices::getServiceInstance( $setService ? $serviceName : '', $parserFunction );
8888
8989 // Get an instance of the class handling the current parser function and service.
9090 $mapClass = $service->getFeatureInstance( $parserFunction );

Status & tagging log