]> git.street.me.uk Git - andy/gpx.git/blob - src/libgpx/gpx.php
Initial commit
[andy/gpx.git] / src / libgpx / gpx.php
1 <?php
2 /**
3  * gpx.php
4  *
5  * Copyright 2018 Andy Street <andy@street.me.uk>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301, USA.
21  *
22  *
23  */
24
25 namespace libgpx;
26
27 use \DateTimeInterface;
28
29 /**
30  * A GPX file.
31  *
32  * @see https://www.topografix.com/gpx.asp
33  *
34  * @author Andy Street <andy@street.me.uk>
35  */
36 class GPX implements Geographic
37 {
38
39   /**
40    * The program that created the GPX file.
41    *
42    * @var string
43    */
44   protected $creator;
45
46   /**
47    * The name of the GPX file.
48    *
49    * @var string
50    */
51   protected $name;
52
53   /**
54    * A description of the contents of the GPX file.
55    *
56    * @var string
57    */
58   protected $desc;
59
60   /**
61    * The person or organization who created the GPX file.
62    *
63    * @var Person
64    */
65   protected $author;
66
67   /**
68    * Copyright and license information governing use of the file.
69    *
70    * @var Copyright
71    */
72   protected $copyright;
73
74   /**
75    * Links to other resources that describe this GPX file.
76    *
77    * @var Link[]
78    */
79   protected $links = [];
80
81   /**
82    * The creation time of the file.
83    *
84    * @var DateTimeInterface
85    */
86   protected $time;
87
88   /**
89    * A list of keywords classifying this GPX file.
90    *
91    * @var string[]
92    */
93   protected $keywords = [];
94
95   /**
96    * Fetch the name of the program that created the GPX file.
97    *
98    * @return string|null The creator or null if not set.
99    */
100   public function getCreator()
101   {
102     return $this->creator;
103   }
104
105   /**
106    * Set the name of the program that created the GPX file.
107    *
108    * @param string|null $creator The program name or null to delete.
109    * @return void
110    */
111   public function setCreator(string $creator = null)
112   {
113     $this->creator = $creator;
114   }
115
116   /**
117    * Fetch the file name.
118    *
119    * @return string|null The name or null if not set.
120    */
121   public function getName()
122   {
123     return $this->name;
124   }
125
126   /**
127    * Set the name of the file.
128    *
129    * @param string|null $name The file name or null to delete.
130    * @return void
131    */
132   public function setName(string $name = null)
133   {
134     $this->name = $name;
135   }
136
137   /**
138    * Fetch the description of the file.
139    *
140    * @return string|null The description or null if not set.
141    */
142   public function getDesc()
143   {
144     return $this->desc;
145   }
146
147   /**
148    * Set the description of the file.
149    *
150    * @param string|null $desc The description or null to delete.
151    * @return void
152    */
153   public function setDesc(string $desc = null)
154   {
155     $this->desc = $desc;
156   }
157
158   /**
159    * Fetch the author of the file.
160    *
161    * @return Person|null The author or null if not set.
162    */
163   public function getAuthor()
164   {
165     return $this->author;
166   }
167
168   /**
169    * Set the author of the file.
170    *
171    * @param Person|null $author The author or null to delete.
172    * @return void
173    */
174   public function setAuthor(Person $author = null)
175   {
176     $this->author = $author;
177   }
178
179   /**
180    * Fetch the copyright details for the file.
181    *
182    * @return Copyright|null The copyright or null if not set.
183    */
184   public function getCopyright()
185   {
186     return $this->copyright;
187   }
188
189   /**
190    * Set the copyright details for the file.
191    *
192    * @param Copyright|null $copyright The copyright detail or null to delete.
193    * @return void
194    */
195   public function setCopyright(Copyright $copyright = null)
196   {
197     $this->copyright = $copyright;
198   }
199
200   /**
201    * Fetch links to other resources.
202    *
203    * @return Link[]
204    */
205   public function getLinks()
206   {
207     return $this->links;
208   }
209
210   /**
211    * Add a link to an related resource.
212    *
213    * @param Link $link The link to add.
214    * @return void
215    */
216   public function addLink(Link $link)
217   {
218     if (!in_array($link, $this->links, true))
219       $this->links[] = $link;
220   }
221
222   /**
223    * Remove an existing link from the list.
224    *
225    * @param Link $link The link to remove.
226    * @return void
227    */
228   public function removeLink(Link $link)
229   {
230     $key = array_search($link, $this->links, true);
231     if ($key !== null)
232       unset($this->links[$key]);
233   }
234
235   /**
236    * Fetch the time the GPX file was created.
237    *
238    * @return DateTimeInterface|null A timestamp or null if not set.
239    */
240   public function getTime()
241   {
242     return $this->time;
243   }
244
245   /**
246    * Set the time at which the file was created.
247    *
248    * @param DateTimeInterface $time The creation time or null to delete.
249    */
250   public function setTime(DateTimeInterface $time = null)
251   {
252     $this->time = $time;
253   }
254
255   /**
256    * Fetch a list of keywords for this GPX file.
257    *
258    * @return string[] The keywords
259    */
260   public function getKeywords()
261   {
262     return $this->keywords;
263   }
264
265   /**
266    * Add a keyword for this GPX file.
267    *
268    * @param string $keyword The keyword to add.
269    * @return void
270    */
271   public function addKeyword(string $keyword)
272   {
273     if (!in_array($keyword, $this->keywords))
274       $this->keywords[] = $keyword;
275   }
276
277   /**
278    * Remove an existing keyword from the list.
279    *
280    * @param string $keyword The keyword to remove.
281    * @return void
282    */
283   public function removeKeyword(string $keyword)
284   {
285     $key = array_search($keyword, $this->keywords);
286     if ($key !== null)
287       unset($this->keywords[$key]);
288   }
289
290   /**
291    * Fetch a bounding box that covers the feature.
292    *
293    * @return Bounds|null A bounding box covering the extent of the feature or
294    *         null if not applicable.
295    */
296   public function getBounds()
297   {
298     //TODO: Implement this properly when waypoints, routes and tracks have
299     //      been implemented.
300     return null;
301   }
302
303 }