Skip to content

Commit

Permalink
Reimplement directional notation
Browse files Browse the repository at this point in the history
Change-Id: I940d495180e03f44225e1d6e5ea87e7878d5cb69
  • Loading branch information
JeroenDeDauw committed Nov 30, 2013
1 parent d5a3e54 commit 01bd2ef
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 30 deletions.
7 changes: 4 additions & 3 deletions includes/Geocoders.php
Expand Up @@ -4,6 +4,7 @@

use DataValues\LatLongValue;
use MWException;
use ValueFormatters\GeoCoordinateFormatter;
use ValueParsers\ParseException;

/**
Expand Down Expand Up @@ -177,11 +178,11 @@ public static function attemptToGeocodeToString( $coordsOrAddress, $service = ''
}

$options = new \ValueFormatters\FormatterOptions( array(
\ValueFormatters\GeoCoordinateFormatter::OPT_FORMAT => $targetFormat,
// TODO \ValueFormatters\GeoCoordinateFormatter::OPT_DIRECTIONAL => $directional
GeoCoordinateFormatter::OPT_FORMAT => $targetFormat,
GeoCoordinateFormatter::OPT_DIRECTIONAL => $directional
) );

$formatter = new \ValueFormatters\GeoCoordinateFormatter( $options );
$formatter = new GeoCoordinateFormatter( $options );
return $formatter->format( $geoCoordinate );
}

Expand Down
7 changes: 4 additions & 3 deletions includes/parserhooks/Maps_Coordinates.php
@@ -1,4 +1,5 @@
<?php
use ValueFormatters\GeoCoordinateFormatter;

/**
* Class for the 'coordinates' parser hooks,
Expand Down Expand Up @@ -87,11 +88,11 @@ protected function getDefaultParameters( $type ) {
*/
public function render( array $parameters ) {
$options = new \ValueFormatters\FormatterOptions( array(
\ValueFormatters\GeoCoordinateFormatter::OPT_FORMAT => $parameters['format'],
// TODO \ValueFormatters\GeoCoordinateFormatter::OPT_DIRECTIONAL => $parameters['directional']
GeoCoordinateFormatter::OPT_FORMAT => $parameters['format'],
GeoCoordinateFormatter::OPT_DIRECTIONAL => $parameters['directional']
) );

$coordinateFormatter = new \ValueFormatters\GeoCoordinateFormatter( $options );
$coordinateFormatter = new GeoCoordinateFormatter( $options );

$output = $coordinateFormatter->format( $parameters['location'] );

Expand Down
7 changes: 4 additions & 3 deletions includes/parserhooks/Maps_Finddestination.php
@@ -1,4 +1,5 @@
<?php
use ValueFormatters\GeoCoordinateFormatter;

/**
* Class for the 'finddestination' parser hooks, which can find a
Expand Down Expand Up @@ -123,11 +124,11 @@ public function render( array $parameters ) {
);

$options = new \ValueFormatters\FormatterOptions( array(
\ValueFormatters\GeoCoordinateFormatter::OPT_FORMAT => $parameters['format'],
// TODO \ValueFormatters\GeoCoordinateFormatter::OPT_DIRECTIONAL => $parameters['directional']
GeoCoordinateFormatter::OPT_FORMAT => $parameters['format'],
GeoCoordinateFormatter::OPT_DIRECTIONAL => $parameters['directional']
) );

$formatter = new \ValueFormatters\GeoCoordinateFormatter( $options );
$formatter = new GeoCoordinateFormatter( $options );

$geoCoords = new \DataValues\LatLongValue( $destination['lat'], $destination['lon'] );
$output = $formatter->format( $geoCoords );
Expand Down
7 changes: 4 additions & 3 deletions includes/parserhooks/Maps_Geocode.php
@@ -1,4 +1,5 @@
<?php
use ValueFormatters\GeoCoordinateFormatter;

/**
* Class for the 'geocode' parser hooks, which can turn
Expand Down Expand Up @@ -112,11 +113,11 @@ public function render( array $parameters ) {
$coordinates = $parameters['location']->getCoordinates();

$options = new \ValueFormatters\FormatterOptions( array(
\ValueFormatters\GeoCoordinateFormatter::OPT_FORMAT => $parameters['format'],
// TODO \ValueFormatters\GeoCoordinateFormatter::OPT_DIRECTIONAL => $parameters['directional']
GeoCoordinateFormatter::OPT_FORMAT => $parameters['format'],
GeoCoordinateFormatter::OPT_DIRECTIONAL => $parameters['directional']
) );

$formatter = new \ValueFormatters\GeoCoordinateFormatter( $options );
$formatter = new GeoCoordinateFormatter( $options );

return $formatter->format( $coordinates );
}
Expand Down
41 changes: 23 additions & 18 deletions tests/phpunit/parserhooks/CoordinatesTest.php
Expand Up @@ -36,14 +36,18 @@ public function parametersProvider() {

$paramLists[] = array(
array(
'location' => '4,2'
'location' => '4,2',
'format' => 'dms',
'directional' => 'no',
),
'4° 0\' 0", 2° 0\' 0"'
);

$paramLists[] = array(
array(
'location' => '55 S, 37.6176330 W'
'location' => '55 S, 37.6176330 W',
'format' => 'dms',
'directional' => 'no',
),
'-55° 0\' 0", -37° 37\' 3.4788"'
);
Expand All @@ -52,26 +56,27 @@ public function parametersProvider() {
array(
'location' => '4,2',
'format' => 'float',
'directional' => 'no',
),
'4, 2'
);

// $paramLists[] = array(
// array(
// 'location' => '-4,-2',
// 'format' => 'float',
// 'directional' => 'yes',
// ),
// '4 W, 2 S'
// );
//
// $paramLists[] = array(
// array(
// 'location' => '55 S, 37.6176330 W',
// 'directional' => 'yes',
// ),
// '55° 0\' 0" W, 37° 37\' 3.4788" S'
// );
$paramLists[] = array(
array(
'location' => '-4,-2',
'format' => 'float',
'directional' => 'yes',
),
'4 S, 2 W'
);

$paramLists[] = array(
array(
'location' => '55 S, 37.6176330 W',
'directional' => 'yes',
),
'55° 0\' 0" S, 37° 37\' 3.4788" W'
);

return $paramLists;
}
Expand Down

0 comments on commit 01bd2ef

Please sign in to comment.