Skip to content

Commit 7d6153c

Browse files
committed
Created simple shared interface for traits.
- Updated local var names in BingTrait to be more consistent - Updated test suite to use new interface on two test-suites - Update phar to error two "undefined" if git descrive fails
1 parent 9525250 commit 7d6153c

File tree

6 files changed

+68
-10
lines changed

6 files changed

+68
-10
lines changed

build/phar.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
define('SRC_DIR',ROOT_DIR.'src'.DIRECTORY_SEPARATOR);
2828
define('EXT','.phar');
2929
define('PACKAGE_NAME','polyline-encoder');
30-
define('PACKAGE_VERSION',trim(`git describe`));
30+
define('PACKAGE_VERSION',trim(`git describe 2>/dev/null || echo "undefined"`));
3131
define('PACKAGE',PACKAGE_NAME.'-'.PACKAGE_VERSION);
3232
define('PACKAGE_PHAR',PACKAGE.EXT);
3333

@@ -50,6 +50,7 @@
5050
// traits for immediate use.
5151
$main=<<<END_OF_MAIN
5252
<?php
53+
require_once('phar://polyline-encoder.phar/PolylineEncoderInterface.php');
5354
require_once('phar://polyline-encoder.phar/BingTrait.php');
5455
require_once('phar://polyline-encoder.phar/GoogleTrait.php');
5556
__HALT_COMPILER();

src/emcconville/Polyline/BingTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ public function encodePoints($points)
9292
* Convert ANSI string into array of points
9393
*
9494
* @link http://msdn.microsoft.com/en-us/library/dn306801.aspx
95-
* @param string $encoded
95+
* @param string $string
9696
* @return array or FALSE on failure
9797
*/
98-
public function decodeString($str)
98+
public function decodeString($string)
9999
{
100-
assert(is_string($str));
101-
$length = strlen($str);
100+
assert(is_string($string));
101+
$length = strlen($string);
102102
$cursor = 0;
103103
$previous = array(0,0);
104104
$points = array();
@@ -109,7 +109,7 @@ public function decodeString($str)
109109
while(true)
110110
{
111111
// Read input
112-
$remainder = strpos(BING_SAFE_CHARACTERS,$str[$cursor++]);
112+
$remainder = strpos(BING_SAFE_CHARACTERS,$string[$cursor++]);
113113
if( $remainder === FALSE )
114114
return FALSE;
115115
// Mask top bit and shift by bytes read
@@ -139,4 +139,4 @@ public function decodeString($str)
139139
return $points;
140140
}
141141
}
142-
}
142+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/**
4+
* Google Maps - Encoded Polyline Algorithm
5+
*
6+
* This library is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* @package PolylineEncoderInterface
20+
* @author E. McConville <[email protected]>
21+
* @version 1.1
22+
* @license GNU Lesser General Public License <http://www.gnu.org/licenses/lgpl.html>
23+
* @link https://github.com/emcconville/polyline-encoder
24+
*/
25+
namespace emcconville\Polyline
26+
{
27+
/**
28+
* Inform a delegate that a given class uses polyline encoding
29+
*/
30+
interface PolylineEncoderInterface
31+
{
32+
/**
33+
* Convert array of points into compressed ANSI string
34+
*
35+
* Points should be given to this method in lists of two.
36+
* array(
37+
* array({latitude1},{longitude1}),
38+
* array({latitude2},{longitude2}),
39+
* ...
40+
* array({latitudeN},{longitudeN}),
41+
* )
42+
*
43+
* @param array $points
44+
* @return string
45+
*/
46+
public function encodePoints($points);
47+
48+
/**
49+
* Convert ANSI string into array of points
50+
*
51+
* @param string $string
52+
* @return array or FALSE on error
53+
*/
54+
public function decodeString($string);
55+
}
56+
}

test/GoogleTraitBadInputTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
class GooglePolylineBadInput
3+
class GooglePolylineBadInput implements emcconville\Polyline\PolylineEncoderInterface
44
{
55
use emcconville\Polyline\GoogleTrait;
66
}
@@ -30,4 +30,4 @@ public function testBadInputDecode()
3030
{
3131
$fail = $this->object->decodeString(0xFF6633);
3232
}
33-
}
33+
}

test/GoogleTraitHackingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
class GooglePolylineHacking
3+
class GooglePolylineHacking implements emcconville\Polyline\PolylineEncoderInterface
44
{
55
use emcconville\Polyline\GoogleTrait;
66
private function polylinePrecision()

test/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<?php
2+
require_once 'src/emcconville/Polyline/PolylineEncoderInterface.php';
23
require_once 'src/emcconville/Polyline/BingTrait.php';
34
require_once 'src/emcconville/Polyline/GoogleTrait.php';

0 commit comments

Comments
 (0)