1 | <?php |
||
18 | abstract class LatLongParserBase implements ValueParser { |
||
19 | |||
20 | const FORMAT_NAME = 'geo-coordinate'; |
||
21 | |||
22 | /** |
||
23 | * The symbols representing the different directions for usage in directional notation. |
||
24 | */ |
||
25 | const OPT_NORTH_SYMBOL = 'north'; |
||
26 | const OPT_EAST_SYMBOL = 'east'; |
||
27 | const OPT_SOUTH_SYMBOL = 'south'; |
||
28 | const OPT_WEST_SYMBOL = 'west'; |
||
29 | |||
30 | /** |
||
31 | * The symbol to use as separator between latitude and longitude. |
||
32 | */ |
||
33 | const OPT_SEPARATOR_SYMBOL = 'separator'; |
||
34 | |||
35 | /** |
||
36 | * Delimiters used to split a coordinate string when unable to split by using the separator. |
||
37 | * @var string[] |
||
38 | */ |
||
39 | protected $defaultDelimiters; |
||
40 | |||
41 | /** |
||
42 | * @var ParserOptions |
||
43 | */ |
||
44 | protected $options; |
||
45 | |||
46 | public function __construct( ParserOptions $options = null ) { |
||
58 | |||
59 | /** |
||
60 | * Parses a single coordinate segment (either latitude or longitude) and returns it as a float. |
||
61 | * |
||
62 | * @param string $coordinateSegment |
||
63 | * |
||
64 | * @throws ParseException |
||
65 | * @return float |
||
66 | */ |
||
67 | abstract protected function getParsedCoordinate( $coordinateSegment ); |
||
68 | |||
69 | /** |
||
70 | * Returns whether a coordinate split into its two segments is in the representation expected by |
||
71 | * this parser. |
||
72 | * |
||
73 | * @param string[] $normalizedCoordinateSegments |
||
74 | * |
||
75 | * @return boolean |
||
76 | */ |
||
77 | abstract protected function areValidCoordinates( array $normalizedCoordinateSegments ); |
||
78 | |||
79 | /** |
||
80 | * @see ValueParser::parse |
||
81 | * |
||
82 | * @param string $value |
||
83 | * |
||
84 | * @throws ParseException |
||
85 | * @return LatLongValue |
||
86 | */ |
||
87 | public function parse( $value ) { |
||
105 | |||
106 | /** |
||
107 | * Returns a string trimmed and with control characters and characters with ASCII values above |
||
108 | * 126 removed. SPACE characters within the string are not removed to retain the option to split |
||
109 | * the string using that character. |
||
110 | * |
||
111 | * @param string $string |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | protected function removeInvalidChars( $string ) { |
||
132 | |||
133 | /** |
||
134 | * Splits a string into two strings using the separator specified in the options. If the string |
||
135 | * could not be split using the separator, the method will try to split the string by analyzing |
||
136 | * the used symbols. If the string could not be split into two parts, an empty array is |
||
137 | * returned. |
||
138 | * |
||
139 | * @param string $normalizedCoordinateString |
||
140 | * |
||
141 | * @throws ParseException if unable to split input string into two segments |
||
142 | * @return string[] |
||
143 | */ |
||
144 | protected function splitString( $normalizedCoordinateString ) { |
||
197 | |||
198 | /** |
||
199 | * Turns directional notation (N/E/S/W) of a single coordinate into non-directional notation |
||
200 | * (+/-). |
||
201 | * This method assumes there are no preceding or tailing spaces. |
||
202 | * |
||
203 | * @param string $coordinateSegment |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | protected function resolveDirection( $coordinateSegment ) { |
||
238 | |||
239 | protected function getOption( $optionName ) { |
||
242 | |||
243 | } |
||
244 |