Index: trunk/extensions/Maps/Services/Maps_MappingService.php |
— | — | @@ -79,89 +79,6 @@ |
80 | 80 | private $dependencies = array(); |
81 | 81 | |
82 | 82 | /** |
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 | | - /** |
166 | 83 | * Constructor. Creates a new instance of MapsMappingService. |
167 | 84 | * |
168 | 85 | * @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 |
1 | 116 | + native |
Index: trunk/extensions/Maps/Includes/Maps_Mapper.php |
— | — | @@ -97,10 +97,10 @@ |
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | | - * @deprecated Method moved to MapsMappingService. Will be removed in 0.7. |
| 101 | + * @deprecated Method moved to MapsMappingServices. Will be removed in 0.7. |
102 | 102 | */ |
103 | 103 | public static function getValidService( $service, $feature ) { |
104 | | - MapsMappingService::getValidService( $service, $feature ); |
| 104 | + MapsMappingServices::getValidService( $service, $feature ); |
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -103,6 +103,7 @@ |
104 | 104 | |
105 | 105 | // Load the "service/" classes and interfaces. |
106 | 106 | require_once $egMapsDir . 'Services/iMappingService.php'; |
| 107 | + $wgAutoloadClasses['MapsMappingServices'] = $egMapsDir . 'Services/Maps_MappingServices.php'; |
107 | 108 | $wgAutoloadClasses['MapsMappingService'] = $egMapsDir . 'Services/Maps_MappingService.php'; |
108 | 109 | |
109 | 110 | wfRunHooks( 'MappingServiceLoad' ); |
Index: trunk/extensions/Maps/Features/Maps_ParserFunctions.php |
— | — | @@ -83,7 +83,7 @@ |
84 | 84 | } |
85 | 85 | |
86 | 86 | // Get the instance of the service class. |
87 | | - $service = MapsMappingService::getServiceInstance( $setService ? $serviceName : '', $parserFunction ); |
| 87 | + $service = MapsMappingServices::getServiceInstance( $setService ? $serviceName : '', $parserFunction ); |
88 | 88 | |
89 | 89 | // Get an instance of the class handling the current parser function and service. |
90 | 90 | $mapClass = $service->getFeatureInstance( $parserFunction ); |