1 | <?php |
||
13 | class MapsDistanceParser { |
||
14 | |||
15 | private static $validatedDistanceUnit = false; |
||
16 | |||
17 | private static $unitRegex = false; |
||
18 | |||
19 | /** |
||
20 | * Parses a distance optionally containing a unit to a float value in meters. |
||
21 | * |
||
22 | * @since 0.6 |
||
23 | * |
||
24 | * @param string $distance |
||
25 | * |
||
26 | * @return float The distance in meters. |
||
27 | */ |
||
28 | 2 | public static function parseDistance( $distance ) { |
|
45 | |||
46 | /** |
||
47 | * Formats a given distance in meters to a distance in an optionally specified notation. |
||
48 | * |
||
49 | * @since 0.6 |
||
50 | * |
||
51 | * @param float $meters |
||
52 | * @param string $unit |
||
53 | * @param integer $decimals |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | 2 | public static function formatDistance( $meters, $unit = null, $decimals = 2 ) { |
|
62 | |||
63 | /** |
||
64 | * Shortcut for converting from one unit to another. |
||
65 | * |
||
66 | * @since 0.6 |
||
67 | * |
||
68 | * @param string $distance |
||
69 | * @param string $unit |
||
70 | * @param integer $decimals |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | 1 | public static function parseAndFormat( $distance, $unit = null, $decimals = 2 ) { |
|
77 | |||
78 | /** |
||
79 | * Returns if the provided string is a valid distance. |
||
80 | * |
||
81 | * @since 0.6 |
||
82 | * |
||
83 | * @param string $distance |
||
84 | * |
||
85 | * @return boolean |
||
86 | */ |
||
87 | 3 | public static function isDistance( $distance ) { |
|
94 | |||
95 | /** |
||
96 | * Returns the unit to meter ratio in a safe way, by first resolving the unit. |
||
97 | * |
||
98 | * @since 0.6.2 |
||
99 | * |
||
100 | * @param string $unit |
||
101 | * |
||
102 | * @return float |
||
103 | */ |
||
104 | 4 | public static function getUnitRatio( $unit = null ) { |
|
108 | |||
109 | /** |
||
110 | * Returns a valid unit. If the provided one is invalid, the default will be used. |
||
111 | * |
||
112 | * @since 0.6.2 |
||
113 | * |
||
114 | * @param string $unit |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 5 | public static function getValidUnit( $unit = null ) { |
|
137 | |||
138 | /** |
||
139 | * Returns a list of all suported units. |
||
140 | * |
||
141 | * @since 0.6 |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | 1 | public static function getUnits() { |
|
149 | |||
150 | /** |
||
151 | * Normalizes a potential distance by removing spaces and truning comma's into dots. |
||
152 | * |
||
153 | * @since 0.6.5 |
||
154 | * |
||
155 | * @param $distance String |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | 3 | protected static function normalizeDistance( $distance ) { |
|
179 | |||
180 | 3 | private static function initUnitRegex() { |
|
186 | |||
187 | } |