1 | <?php |
||
15 | final class GPX implements DumperInterface |
||
16 | { |
||
17 | /** |
||
18 | * {@inheritdoc} |
||
19 | */ |
||
20 | public function dump(Workout $workout): string |
||
21 | { |
||
22 | $xmlWriter = new \XMLWriter(); |
||
23 | $xmlWriter->openMemory(); |
||
24 | $xmlWriter->setIndent(true); |
||
25 | $xmlWriter->startDocument('1.0', 'UTF-8'); |
||
26 | $xmlWriter->startElement('gpx'); |
||
27 | |||
28 | $xmlWriter->writeAttribute('version', '1.1'); |
||
29 | $xmlWriter->writeAttribute('creator', 'SportTrackerConnector'); |
||
30 | $xmlWriter->writeAttributeNs( |
||
31 | 'xsi', |
||
32 | 'schemaLocation', |
||
33 | null, |
||
34 | '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' |
||
35 | ); |
||
36 | $xmlWriter->writeAttribute('xmlns', 'http://www.topografix.com/GPX/1/1'); |
||
37 | $xmlWriter->writeAttributeNs( |
||
38 | 'xmlns', |
||
39 | 'gpxtpx', |
||
40 | null, |
||
41 | 'http://www.garmin.com/xmlschemas/TrackPointExtension/v1' |
||
42 | ); |
||
43 | $xmlWriter->writeAttributeNs('xmlns', 'gpxx', null, 'http://www.garmin.com/xmlschemas/GpxExtensions/v3'); |
||
44 | $xmlWriter->writeAttributeNs('xmlns', 'xsi', null, 'http://www.w3.org/2001/XMLSchema-instance'); |
||
45 | |||
46 | $this->writeMetaData($xmlWriter, $workout); |
||
47 | $this->writeTracks($xmlWriter, $workout); |
||
48 | |||
49 | $xmlWriter->endElement(); |
||
50 | $xmlWriter->endDocument(); |
||
51 | |||
52 | return $xmlWriter->outputMemory(true); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Write the tracks to the GPX. |
||
57 | * |
||
58 | * @param \XMLWriter $xmlWriter The XML writer. |
||
59 | * @param Workout $workout The workout. |
||
60 | */ |
||
61 | private function writeTracks(\XMLWriter $xmlWriter, Workout $workout) |
||
72 | |||
73 | /** |
||
74 | * Write the track points to the GPX. |
||
75 | * |
||
76 | * @param \XMLWriter $xmlWriter The XML writer. |
||
77 | * @param TrackPoint[] $trackPoints The track points to write. |
||
78 | */ |
||
79 | private function writeTrackPoints(\XMLWriter $xmlWriter, array $trackPoints) |
||
102 | |||
103 | /** |
||
104 | * Write the extensions into the GPX. |
||
105 | * |
||
106 | * @param \XMLWriter $xmlWriter The XMLWriter. |
||
107 | * @param ExtensionInterface[] $extensions The extensions to write. |
||
108 | */ |
||
109 | protected function writeExtensions(\XMLWriter $xmlWriter, array $extensions) |
||
123 | |||
124 | /** |
||
125 | * Write the metadata in the GPX. |
||
126 | * |
||
127 | * @param \XMLWriter $xmlWriter The XML writer. |
||
128 | * @param Workout $workout The workout. |
||
129 | */ |
||
130 | protected function writeMetaData(\XMLWriter $xmlWriter, Workout $workout) |
||
140 | } |
||
141 |