]> git.openstreetmap.org Git - nominatim.git/blob - lib-php/TokenCountry.php
917ed9d25867d55834003aaf3e53720155ec0ed7
[nominatim.git] / lib-php / TokenCountry.php
1 <?php
2
3 namespace Nominatim\Token;
4
5 /**
6  * A country token.
7  */
8 class Country
9 {
10     /// Database word id, if available.
11     private $iId;
12     /// Two-letter country code (lower-cased).
13     private $sCountryCode;
14
15     public function __construct($iId, $sCountryCode)
16     {
17         $this->iId = $iId;
18         $this->sCountryCode = $sCountryCode;
19     }
20
21     public function getId()
22     {
23         return $this->iId;
24     }
25
26     /**
27      * Derive new searches by adding this token to an existing search.
28      *
29      * @param object  $oSearch      Partial search description derived so far.
30      * @param object  $oPosition    Description of the token position within
31                                     the query.
32      *
33      * @return SearchDescription[] List of derived search descriptions.
34      */
35     public function extendSearch($oSearch, $oPosition)
36     {
37         if ($oSearch->hasCountry() || !$oPosition->maybePhrase('country')) {
38             return array();
39         }
40
41         $oNewSearch = $oSearch->clone($oPosition->isLastToken() ? 1 : 6);
42         $oNewSearch->setCountry($this->sCountryCode);
43
44         return array($oNewSearch);
45     }
46
47     public function debugInfo()
48     {
49         return array(
50                 'ID' => $this->iId,
51                 'Type' => 'country',
52                 'Info' => $this->sCountryCode
53                );
54     }
55
56     public function debugCode()
57     {
58         return 'C';
59     }
60 }