1 | <?php |
||
19 | class GPX extends AbstractDumper |
||
20 | { |
||
21 | /** |
||
22 | * {@inheritdoc} |
||
23 | */ |
||
24 | public function toString(Workout $workout) : string |
||
25 | { |
||
26 | $xmlWriter = new XMLWriter(); |
||
27 | $xmlWriter->openMemory(); |
||
28 | $xmlWriter->setIndent(true); |
||
29 | $xmlWriter->startDocument('1.0', 'UTF-8'); |
||
30 | $xmlWriter->startElement('gpx'); |
||
31 | |||
32 | $xmlWriter->writeAttribute('version', '1.1'); |
||
33 | $xmlWriter->writeAttribute('creator', 'SportTrackerConnector'); |
||
34 | $xmlWriter->writeAttributeNs( |
||
35 | 'xsi', |
||
36 | 'schemaLocation', |
||
37 | null, |
||
38 | 'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd' |
||
39 | ); |
||
40 | $xmlWriter->writeAttribute('xmlns', 'http://www.topografix.com/GPX/1/1'); |
||
41 | $xmlWriter->writeAttributeNs( |
||
42 | 'xmlns', |
||
43 | 'gpxtpx', |
||
44 | null, |
||
45 | 'http://www.garmin.com/xmlschemas/TrackPointExtension/v1' |
||
46 | ); |
||
47 | $xmlWriter->writeAttributeNs('xmlns', 'gpxx', null, 'http://www.garmin.com/xmlschemas/GpxExtensions/v3'); |
||
48 | $xmlWriter->writeAttributeNs('xmlns', 'xsi', null, 'http://www.w3.org/2001/XMLSchema-instance'); |
||
49 | |||
50 | $this->writeMetaData($xmlWriter, $workout); |
||
51 | $this->writeTracks($xmlWriter, $workout); |
||
52 | |||
53 | $xmlWriter->endElement(); |
||
54 | $xmlWriter->endDocument(); |
||
55 | |||
56 | return $xmlWriter->outputMemory(true); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Write the tracks to the GPX. |
||
61 | * |
||
62 | * @param XMLWriter $xmlWriter The XML writer. |
||
63 | * @param Workout $workout The workout. |
||
64 | */ |
||
65 | private function writeTracks(XMLWriter $xmlWriter, Workout $workout) |
||
76 | |||
77 | /** |
||
78 | * Write the track points to the GPX. |
||
79 | * |
||
80 | * @param XMLWriter $xmlWriter The XML writer. |
||
81 | * @param TrackPoint[] $trackPoints The track points to write. |
||
82 | */ |
||
83 | private function writeTrackPoints(XMLWriter $xmlWriter, array $trackPoints) |
||
106 | |||
107 | /** |
||
108 | * Write the extensions into the GPX. |
||
109 | * |
||
110 | * @param XMLWriter $xmlWriter The XMLWriter. |
||
111 | * @param ExtensionInterface[] $extensions The extensions to write. |
||
112 | * @throws InvalidArgumentException If an extension is not known. |
||
113 | */ |
||
114 | protected function writeExtensions(XMLWriter $xmlWriter, array $extensions) |
||
128 | |||
129 | /** |
||
130 | * Write the metadata in the GPX. |
||
131 | * |
||
132 | * @param XMLWriter $xmlWriter The XML writer. |
||
133 | * @param Workout $workout The workout. |
||
134 | */ |
||
135 | protected function writeMetaData(XMLWriter $xmlWriter, Workout $workout) |
||
145 | } |
||
146 |