Index: trunk/extensions/Maps/Services/Maps_MappingService.php |
— | — | @@ -79,6 +79,89 @@ |
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 | + /** |
83 | 166 | * Constructor. Creates a new instance of MapsMappingService. |
84 | 167 | * |
85 | 168 | * @since 0.6.3 |
— | — | @@ -191,6 +274,21 @@ |
192 | 275 | } |
193 | 276 | |
194 | 277 | /** |
| 278 | + * @see iMappingService::getFeatureInstance |
| 279 | + * |
| 280 | + * @since 0.6.6 |
| 281 | + */ |
| 282 | + public function getFeatureInstance( $featureName ) { |
| 283 | + $className = $this->getFeature( $featureName ); |
| 284 | + |
| 285 | + if ( $className === false || !class_exists( $className ) ) { |
| 286 | + // TODO: log/throw error, as this should not happen |
| 287 | + } |
| 288 | + |
| 289 | + return new $className( $this ); |
| 290 | + } |
| 291 | + |
| 292 | + /** |
195 | 293 | * @see iMappingService::getAliases |
196 | 294 | * |
197 | 295 | * @since 0.6.3 |
Index: trunk/extensions/Maps/Services/iMappingService.php |
— | — | @@ -91,6 +91,17 @@ |
92 | 92 | function getFeature( $featureName ); |
93 | 93 | |
94 | 94 | /** |
| 95 | + * Returns an instance of the class handling the provided feature with this service, or false if there is none. |
| 96 | + * |
| 97 | + * @since 0.6.6 |
| 98 | + * |
| 99 | + * @param string $featureName. |
| 100 | + * |
| 101 | + * @return iMappingFeature or false |
| 102 | + */ |
| 103 | + function getFeatureInstance( $featureName ); |
| 104 | + |
| 105 | + /** |
95 | 106 | * Returns a list of aliases. |
96 | 107 | * |
97 | 108 | * @since 0.6.5 |
Index: trunk/extensions/Maps/Includes/Maps_Mapper.php |
— | — | @@ -95,69 +95,15 @@ |
96 | 96 | $location = MapsCoordinateParser::parseAndFormat( $location ); |
97 | 97 | } |
98 | 98 | } |
99 | | - |
| 99 | + |
100 | 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 | | - * @param string $service |
105 | | - * @param string $feature |
106 | | - * |
107 | | - * @return string |
| 101 | + * @deprecated Method moved to MapsMappingService. Will be removed in 0.7. |
108 | 102 | */ |
109 | 103 | public static function getValidService( $service, $feature ) { |
110 | | - global $egMapsServices, $egMapsDefaultService, $egMapsDefaultServices, $shouldChange; |
111 | | - |
112 | | - // Get rid of any aliases. |
113 | | - $service = self::getMainServiceName( $service ); |
114 | | - |
115 | | - // If the service is not loaded into maps, it should be changed. |
116 | | - $shouldChange = !array_key_exists( $service, $egMapsServices ); |
117 | | - |
118 | | - // If it should not be changed, ensure the service supports this feature. |
119 | | - if ( ! $shouldChange ) { |
120 | | - $shouldChange = $egMapsServices[$service]->getFeature( $feature ) === false; |
121 | | - } |
122 | | - |
123 | | - // Change the service to the most specific default value available. |
124 | | - // Note: the default services should support their corresponding features. |
125 | | - // If they don't, a fatal error will occur later on. |
126 | | - if ( $shouldChange ) { |
127 | | - if ( array_key_exists( $feature, $egMapsDefaultServices ) ) { |
128 | | - $service = $egMapsDefaultServices[$feature]; |
129 | | - } |
130 | | - else { |
131 | | - $service = $egMapsDefaultService; |
132 | | - } |
133 | | - } |
134 | | - |
135 | | - return $service; |
| 104 | + MapsMappingService::getValidService( $service, $feature ); |
136 | 105 | } |
137 | 106 | |
138 | 107 | /** |
139 | | - * Checks if the service name is an alias for an actual service, |
140 | | - * and changes it into the main service name if this is the case. |
141 | | - * |
142 | | - * @param string $service |
143 | | - * |
144 | | - * @return string |
145 | | - */ |
146 | | - private static function getMainServiceName( $service ) { |
147 | | - global $egMapsServices; |
148 | | - |
149 | | - if ( !array_key_exists( $service, $egMapsServices ) ) { |
150 | | - foreach ( $egMapsServices as $serviceObject ) { |
151 | | - if ( $serviceObject->hasAlias( $service ) ) { |
152 | | - $service = $serviceObject->getName(); |
153 | | - break; |
154 | | - } |
155 | | - } |
156 | | - } |
157 | | - |
158 | | - return $service; |
159 | | - } |
160 | | - |
161 | | - /** |
162 | 108 | * Determines if a value is a valid map dimension, and optionally corrects it. |
163 | 109 | * |
164 | 110 | * @since 0.6 |
Index: trunk/extensions/Maps/Features/Maps_ParserFunctions.php |
— | — | @@ -82,16 +82,12 @@ |
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | | - // Make sure the service name is valid, and then get the class associated with it. |
87 | | - $serviceName = MapsMapper::getValidService( $setService ? $serviceName : '', $parserFunction ); |
88 | | - $service = $egMapsServices[$serviceName]; |
| 86 | + // Get the instance of the service class. |
| 87 | + $service = MapsMappingService::getServiceInstance( $setService ? $serviceName : '', $parserFunction ); |
89 | 88 | |
90 | | - // Get the name of the class handling the current parser function and service. |
91 | | - $className = $service->getFeature( $parserFunction ); |
92 | | - $mapClass = new $className( $service ); |
| 89 | + // Get an instance of the class handling the current parser function and service. |
| 90 | + $mapClass = $service->getFeatureInstance( $parserFunction ); |
93 | 91 | |
94 | | - $manager = new ValidatorManager(); |
95 | | - |
96 | 92 | /* |
97 | 93 | * Assembliy of the allowed parameters and their information. |
98 | 94 | * The main parameters (the ones that are shared by everything) are overidden |
— | — | @@ -103,6 +99,8 @@ |
104 | 100 | $parameterInfo = array_merge_recursive( $parameterInfo, $service->getParameterInfo() ); |
105 | 101 | $parameterInfo = array_merge_recursive( $parameterInfo, $mapClass->getSpecificParameterInfo() ); |
106 | 102 | |
| 103 | + $manager = new ValidatorManager(); |
| 104 | + |
107 | 105 | $displayMap = $manager->manageParameters( |
108 | 106 | $parameters, |
109 | 107 | $parameterInfo, |