1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
4
|
|
|
|
5
|
|
|
namespace Maps\ParserHooks; |
6
|
|
|
|
7
|
|
|
use Maps\MapsFactory; |
8
|
|
|
use ParserHook; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class for the 'coordinates' parser hooks, |
12
|
|
|
* which can transform the notation of a set of coordinates. |
13
|
|
|
* |
14
|
|
|
* @licence GNU GPL v2+ |
15
|
|
|
* @author Jeroen De Dauw < [email protected] > |
16
|
|
|
*/ |
17
|
|
|
class CoordinatesFunction extends ParserHook { |
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Renders and returns the output. |
21
|
|
|
* |
22
|
|
|
* @see ParserHook::render |
23
|
|
|
* |
24
|
|
|
* @param array $parameters |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
14 |
|
public function render( array $parameters ) { |
29
|
14 |
|
return MapsFactory::globalInstance()->getCoordinateFormatter()->format( |
30
|
14 |
|
$parameters['location'], |
31
|
14 |
|
$parameters['format'], |
32
|
14 |
|
$parameters['directional'] |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @see ParserHook::getMessage() |
38
|
|
|
*/ |
39
|
|
|
public function getMessage() { |
40
|
|
|
return 'maps-coordinates-description'; |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Gets the name of the parser hook. |
45
|
|
|
* |
46
|
|
|
* @see ParserHook::getName |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
16 |
|
protected function getName() { |
51
|
16 |
|
return 'coordinates'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Returns an array containing the parameter info. |
56
|
|
|
* |
57
|
|
|
* @see ParserHook::getParameterInfo |
58
|
|
|
* |
59
|
|
|
* @return array |
60
|
|
|
*/ |
61
|
19 |
|
protected function getParameterInfo( $type ) { |
62
|
19 |
|
global $egMapsAvailableCoordNotations; |
63
|
19 |
|
global $egMapsCoordinateNotation; |
64
|
19 |
|
global $egMapsCoordinateDirectional; |
65
|
|
|
|
66
|
19 |
|
$params = []; |
67
|
|
|
|
68
|
19 |
|
$params['location'] = [ |
69
|
|
|
'type' => 'coordinate', |
70
|
|
|
]; |
71
|
|
|
|
72
|
19 |
|
$params['format'] = [ |
73
|
19 |
|
'default' => $egMapsCoordinateNotation, |
74
|
19 |
|
'values' => $egMapsAvailableCoordNotations, |
75
|
19 |
|
'aliases' => 'notation', |
76
|
|
|
'tolower' => true, |
77
|
|
|
]; |
78
|
|
|
|
79
|
19 |
|
$params['directional'] = [ |
80
|
19 |
|
'type' => 'boolean', |
81
|
19 |
|
'default' => $egMapsCoordinateDirectional, |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
// Give grep a chance to find the usages: |
85
|
|
|
// maps-coordinates-par-location, maps-coordinates-par-format, maps-coordinates-par-directional |
86
|
19 |
|
foreach ( $params as $name => &$param ) { |
87
|
19 |
|
$param['message'] = 'maps-coordinates-par-' . $name; |
88
|
|
|
} |
89
|
|
|
|
90
|
19 |
|
return $params; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Returns the list of default parameters. |
95
|
|
|
* |
96
|
|
|
* @see ParserHook::getDefaultParameters |
97
|
|
|
* |
98
|
|
|
* @return array |
99
|
|
|
*/ |
100
|
16 |
|
protected function getDefaultParameters( $type ) { |
101
|
16 |
|
return [ 'location', 'format', 'directional' ]; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.