1 | <?php |
||
17 | abstract class LatLongParserBase extends StringValueParser { |
||
18 | |||
19 | const FORMAT_NAME = 'geo-coordinate'; |
||
20 | |||
21 | /** |
||
22 | * The symbols representing the different directions for usage in directional notation. |
||
23 | * @since 0.1 |
||
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 | * @since 0.1 |
||
33 | */ |
||
34 | const OPT_SEPARATOR_SYMBOL = 'separator'; |
||
35 | |||
36 | /** |
||
37 | * Delimiters used to split a coordinate string when unable to split by using the separator. |
||
38 | * @var string[] |
||
39 | */ |
||
40 | protected $defaultDelimiters; |
||
41 | |||
42 | /** |
||
43 | * @since 0.1 |
||
44 | * |
||
45 | * @param ParserOptions|null $options |
||
46 | */ |
||
47 | public function __construct( ParserOptions $options = null ) { |
||
57 | |||
58 | /** |
||
59 | * Parses a single coordinate segment (either latitude or longitude) and returns it as a float. |
||
60 | * |
||
61 | * @since 0.1 |
||
62 | * |
||
63 | * @param string $coordinateSegment |
||
64 | * |
||
65 | * @throws ParseException |
||
66 | * @return float |
||
67 | */ |
||
68 | abstract protected function getParsedCoordinate( $coordinateSegment ); |
||
69 | |||
70 | /** |
||
71 | * Returns whether a coordinate split into its two segments is in the representation expected by |
||
72 | * this parser. |
||
73 | * |
||
74 | * @since 0.1 |
||
75 | * |
||
76 | * @param string[] $normalizedCoordinateSegments |
||
77 | * |
||
78 | * @return boolean |
||
79 | */ |
||
80 | abstract protected function areValidCoordinates( array $normalizedCoordinateSegments ); |
||
81 | |||
82 | /** |
||
83 | * @see StringValueParser::stringParse |
||
84 | * |
||
85 | * @since 0.1 |
||
86 | * |
||
87 | * @param string $value |
||
88 | * |
||
89 | * @throws ParseException |
||
90 | * @return LatLongValue |
||
91 | */ |
||
92 | protected function stringParse( $value ) { |
||
110 | |||
111 | /** |
||
112 | * Returns a string trimmed and with control characters and characters with ASCII values above |
||
113 | * 126 removed. SPACE characters within the string are not removed to retain the option to split |
||
114 | * the string using that character. |
||
115 | * |
||
116 | * @since 0.1 |
||
117 | * |
||
118 | * @param string $string |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | protected function removeInvalidChars( $string ) { |
||
139 | |||
140 | /** |
||
141 | * Splits a string into two strings using the separator specified in the options. If the string |
||
142 | * could not be split using the separator, the method will try to split the string by analyzing |
||
143 | * the used symbols. If the string could not be split into two parts, an empty array is |
||
144 | * returned. |
||
145 | * |
||
146 | * @since 0.1 |
||
147 | * |
||
148 | * @param string $normalizedCoordinateString |
||
149 | * |
||
150 | * @throws ParseException if unable to split input string into two segments |
||
151 | * @return string[] |
||
152 | */ |
||
153 | protected function splitString( $normalizedCoordinateString ) { |
||
206 | |||
207 | /** |
||
208 | * Turns directional notation (N/E/S/W) of a single coordinate into non-directional notation |
||
209 | * (+/-). |
||
210 | * This method assumes there are no preceding or tailing spaces. |
||
211 | * |
||
212 | * @since 0.1 |
||
213 | * |
||
214 | * @param string $coordinateSegment |
||
215 | * |
||
216 | * @return string |
||
217 | */ |
||
218 | protected function resolveDirection( $coordinateSegment ) { |
||
249 | |||
250 | } |
||
251 |