From f95ad549ec98656f9072221859f0c8a6d0f860e8 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Tue, 24 Feb 2026 00:11:13 +0000 Subject: [PATCH 1/6] chore: Whitespace tidy --- tests/UnitTests/phpGPX/Parsers/CopyrightParserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/UnitTests/phpGPX/Parsers/CopyrightParserTest.php b/tests/UnitTests/phpGPX/Parsers/CopyrightParserTest.php index 491b745..1051723 100644 --- a/tests/UnitTests/phpGPX/Parsers/CopyrightParserTest.php +++ b/tests/UnitTests/phpGPX/Parsers/CopyrightParserTest.php @@ -31,7 +31,7 @@ public static function createTestInstance() } protected function setUp(): void - { + { parent::setUp(); $this->testModelInstance = self::createTestInstance(); From 020645f0db91f8ebb4723887c83d5464bca6776b Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Tue, 24 Feb 2026 00:15:58 +0000 Subject: [PATCH 2/6] chore: Further whitespace tidying --- tests/CreateWaypointTest.php | 6 ++++-- tests/UnitTests/phpGPX/Parsers/BoundsParserTest.php | 2 +- tests/UnitTests/phpGPX/Parsers/EmailParserTest.php | 2 +- tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.php | 2 +- tests/UnitTests/phpGPX/Parsers/LinkParserTest.php | 2 +- tests/UnitTests/phpGPX/Parsers/PersonParserTest.php | 2 +- tests/UnitTests/phpGPX/Parsers/PointParserTest.php | 2 +- tests/UnitTests/phpGPX/Parsers/SegmentParserTest.php | 2 +- 8 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/CreateWaypointTest.php b/tests/CreateWaypointTest.php index 6b2ab9e..6d9990d 100644 --- a/tests/CreateWaypointTest.php +++ b/tests/CreateWaypointTest.php @@ -92,7 +92,7 @@ public function createWaypointFile() } public function setUp(): void - { + { $this->waypoint_created_file = dirname(__FILE__)."/waypoint_test.gpx"; $this->waypoint_saved_file = dirname(__FILE__).'/output_waypoint_test.gpx'; // remove any test file hanging around @@ -100,11 +100,13 @@ public function setUp(): void // now create the test file $this->createWaypointFile(); } + public function tearDown(): void - { + { system("rm -f {$this->waypoint_created_file}"); system("rm -f {$this->waypoint_saved_file}"); } + public function test_waypoints_load() { $origFile = $this->waypoint_created_file; diff --git a/tests/UnitTests/phpGPX/Parsers/BoundsParserTest.php b/tests/UnitTests/phpGPX/Parsers/BoundsParserTest.php index 0e84758..2f98c34 100644 --- a/tests/UnitTests/phpGPX/Parsers/BoundsParserTest.php +++ b/tests/UnitTests/phpGPX/Parsers/BoundsParserTest.php @@ -24,7 +24,7 @@ public static function createTestInstance() } protected function setUp(): void - { + { parent::setUp(); $this->testModelInstance = self::createTestInstance(); diff --git a/tests/UnitTests/phpGPX/Parsers/EmailParserTest.php b/tests/UnitTests/phpGPX/Parsers/EmailParserTest.php index 43b8bd7..5815b7c 100644 --- a/tests/UnitTests/phpGPX/Parsers/EmailParserTest.php +++ b/tests/UnitTests/phpGPX/Parsers/EmailParserTest.php @@ -29,7 +29,7 @@ public static function createTestInstance() } protected function setUp(): void - { + { parent::setUp(); $this->testModelInstance = self::createTestInstance(); diff --git a/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.php b/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.php index 54f67dc..352b0e6 100644 --- a/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.php +++ b/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.php @@ -34,7 +34,7 @@ public static function createTestInstance() } protected function setUp(): void - { + { parent::setUp(); $this->testModelInstance = self::createTestInstance(); diff --git a/tests/UnitTests/phpGPX/Parsers/LinkParserTest.php b/tests/UnitTests/phpGPX/Parsers/LinkParserTest.php index 1ec868b..7014787 100644 --- a/tests/UnitTests/phpGPX/Parsers/LinkParserTest.php +++ b/tests/UnitTests/phpGPX/Parsers/LinkParserTest.php @@ -32,7 +32,7 @@ public static function createTestInstance() } protected function setUp(): void - { + { parent::setUp(); $this->testModelInstance = self::createTestInstance(); diff --git a/tests/UnitTests/phpGPX/Parsers/PersonParserTest.php b/tests/UnitTests/phpGPX/Parsers/PersonParserTest.php index 85b6761..06f7f73 100644 --- a/tests/UnitTests/phpGPX/Parsers/PersonParserTest.php +++ b/tests/UnitTests/phpGPX/Parsers/PersonParserTest.php @@ -32,7 +32,7 @@ public static function createTestInstance() } protected function setUp(): void - { + { parent::setUp(); $this->testModelInstance = self::createTestInstance(); diff --git a/tests/UnitTests/phpGPX/Parsers/PointParserTest.php b/tests/UnitTests/phpGPX/Parsers/PointParserTest.php index 16afe0b..d2692c9 100644 --- a/tests/UnitTests/phpGPX/Parsers/PointParserTest.php +++ b/tests/UnitTests/phpGPX/Parsers/PointParserTest.php @@ -49,7 +49,7 @@ public static function createTestInstanceWithValues( } protected function setUp(): void - { + { parent::setUp(); $this->testModelInstance = self::createTestInstance(); diff --git a/tests/UnitTests/phpGPX/Parsers/SegmentParserTest.php b/tests/UnitTests/phpGPX/Parsers/SegmentParserTest.php index ead9287..e096cce 100644 --- a/tests/UnitTests/phpGPX/Parsers/SegmentParserTest.php +++ b/tests/UnitTests/phpGPX/Parsers/SegmentParserTest.php @@ -37,7 +37,7 @@ public static function createTestInstance() } protected function setUp(): void - { + { parent::setUp(); $this->testModelInstance = self::createTestInstance(); From 3553d3a8c46ea2ebdf3bf7943e3bd4d8f57da2dd Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Tue, 24 Feb 2026 00:18:29 +0000 Subject: [PATCH 3/6] chore: Final whitespace tidy --- src/phpGPX/Models/Bounds.php | 31 +++++++++++++++---------------- src/phpGPX/Models/Route.php | 2 +- src/phpGPX/Models/Track.php | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/phpGPX/Models/Bounds.php b/src/phpGPX/Models/Bounds.php index e022f02..5fd0162 100644 --- a/src/phpGPX/Models/Bounds.php +++ b/src/phpGPX/Models/Bounds.php @@ -33,27 +33,26 @@ class Bounds implements Summarizable */ public $maxLongitude; - /** - * @param ?float $minLatitude - * @param ?float $minLongitude - * @param ?float $maxLatitude - * @param ?float $maxLongitude - */ - public function __construct(?float $minLatitude, ?float $minLongitude, ?float $maxLatitude, ?float $maxLongitude) - { - $this->minLatitude = $minLatitude; - $this->minLongitude = $minLongitude; - $this->maxLatitude = $maxLatitude; - $this->maxLongitude = $maxLongitude; - } - + /** + * @param ?float $minLatitude + * @param ?float $minLongitude + * @param ?float $maxLatitude + * @param ?float $maxLongitude + */ + public function __construct(?float $minLatitude, ?float $minLongitude, ?float $maxLatitude, ?float $maxLongitude) + { + $this->minLatitude = $minLatitude; + $this->minLongitude = $minLongitude; + $this->maxLatitude = $maxLatitude; + $this->maxLongitude = $maxLongitude; + } - /** + /** * Serialize object to array * @return array */ public function toArray(): array - { + { return [ 'minlat' => $this->minLatitude, 'minlon' => $this->minLongitude, diff --git a/src/phpGPX/Models/Route.php b/src/phpGPX/Models/Route.php index e546dec..491a284 100644 --- a/src/phpGPX/Models/Route.php +++ b/src/phpGPX/Models/Route.php @@ -42,7 +42,7 @@ public function __construct() * @return Point[] */ public function getPoints(): array - { + { /** @var Point[] $points */ $points = []; diff --git a/src/phpGPX/Models/Track.php b/src/phpGPX/Models/Track.php index 39d7ac2..a4f7e01 100644 --- a/src/phpGPX/Models/Track.php +++ b/src/phpGPX/Models/Track.php @@ -39,7 +39,7 @@ public function __construct() * @return Point[] */ public function getPoints(): array - { + { /** @var Point[] $points */ $points = []; From 5f4009a941debc36bfd09e1e5d99ebc2ed13a307 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Tue, 24 Feb 2026 00:21:10 +0000 Subject: [PATCH 4/6] chore: Missed whitespace tidy --- tests/UnitTests/phpGPX/Parsers/AbstractParserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/UnitTests/phpGPX/Parsers/AbstractParserTest.php b/tests/UnitTests/phpGPX/Parsers/AbstractParserTest.php index 4272104..d731b79 100644 --- a/tests/UnitTests/phpGPX/Parsers/AbstractParserTest.php +++ b/tests/UnitTests/phpGPX/Parsers/AbstractParserTest.php @@ -37,7 +37,7 @@ abstract class AbstractParserTest extends TestCase protected $testParserClass; protected function setUp(): void - { + { $reflection = new \ReflectionClass($this->testParserClass); $this->testXmlFile = simplexml_load_file(sprintf("%s/%sTest.xml", __DIR__, $reflection->getShortName())); From 717f1dc14c1c4cebb082bc70e6a5a78eff27dcb7 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Tue, 24 Feb 2026 00:32:22 +0000 Subject: [PATCH 5/6] Remove phpdoc-md until dependencies resolved --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 5bdf28b..6f1627d 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,6 @@ "ext-dom": "*" }, "require-dev": { - "evert/phpdoc-md" : "~0.2.0", "phpunit/phpunit": "^9", "friendsofphp/php-cs-fixer": "^2.18" }, From 5ed1e17dda01a253297100ebc9abae344c0f1a3b Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Sat, 28 Feb 2026 23:23:56 +0000 Subject: [PATCH 6/6] First attempt at the line part of the style extension --- src/phpGPX/Models/Extensions.php | 9 ++ .../Models/Extensions/StyleExtension.php | 74 +++++++++++++++++ src/phpGPX/Parsers/ExtensionParser.php | 13 +++ .../Extensions/StyleExtensionParser.php | 83 +++++++++++++++++++ .../phpGPX/Parsers/ExtensionParserTest.json | 6 ++ .../phpGPX/Parsers/ExtensionParserTest.php | 12 ++- .../phpGPX/Parsers/ExtensionParserTest.xml | 8 +- 7 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 src/phpGPX/Models/Extensions/StyleExtension.php create mode 100644 src/phpGPX/Parsers/Extensions/StyleExtensionParser.php diff --git a/src/phpGPX/Models/Extensions.php b/src/phpGPX/Models/Extensions.php index 5eb37fa..61e3f28 100644 --- a/src/phpGPX/Models/Extensions.php +++ b/src/phpGPX/Models/Extensions.php @@ -7,6 +7,7 @@ namespace phpGPX\Models; use phpGPX\Helpers\SerializationHelper; +use phpGPX\Models\Extensions\StyleExtension; use phpGPX\Models\Extensions\TrackPointExtension; /** @@ -23,6 +24,13 @@ class Extensions implements Summarizable */ public $trackPointExtension; + /** + * GPX Style Extension v2 + * @see 'http://www.topografix.com/GPX/gpx_style/0/2/' + * @var StyleExtension + */ + public $styleExtension; + /** * @var [] */ @@ -36,6 +44,7 @@ public function toArray() { return [ 'trackpoint' => SerializationHelper::serialize($this->trackPointExtension), + 'line' => SerializationHelper::serialize($this->styleExtension), 'unsupported' => $this->unsupported, ]; } diff --git a/src/phpGPX/Models/Extensions/StyleExtension.php b/src/phpGPX/Models/Extensions/StyleExtension.php new file mode 100644 index 0000000..dd75d5c --- /dev/null +++ b/src/phpGPX/Models/Extensions/StyleExtension.php @@ -0,0 +1,74 @@ + SerializationHelper::stringOrNull($this->color), + 'opacity' => SerializationHelper::floatOrNull($this->opacity), + 'width' => SerializationHelper::floatOrNull($this->width), + // 'pattern' => SerializationHelper::stringOrNull($this->pattern), + 'linecap' => SerializationHelper::stringOrNull($this->linecap), + // 'dasharray' => SerializationHelper::stringOrNull($this->dasharray), + // 'extensions' => SerializationHelper::stringOrNull($this->extensions), + ]; + } +} diff --git a/src/phpGPX/Parsers/ExtensionParser.php b/src/phpGPX/Parsers/ExtensionParser.php index 4b6154b..6655a88 100644 --- a/src/phpGPX/Parsers/ExtensionParser.php +++ b/src/phpGPX/Parsers/ExtensionParser.php @@ -7,7 +7,9 @@ namespace phpGPX\Parsers; use phpGPX\Models\Extensions; +use phpGPX\Models\Extensions\StyleExtension; use phpGPX\Models\Extensions\TrackPointExtension; +use phpGPX\Parsers\Extensions\StyleExtensionParser; use phpGPX\Parsers\Extensions\TrackPointExtensionParser; /** @@ -39,6 +41,12 @@ public static function parse($nodes) $extensions->trackPointExtension = TrackPointExtensionParser::parse($node); } break; + case StyleExtension::EXTENSION_NAMESPACE: + $node = $nodes->children($namespace)->{StyleExtension::EXTENSION_NAME}; + if (!empty($node)) { + $extensions->styleExtension = StyleExtensionParser::parse($node); + } + break; default: foreach ($nodes->children($namespace) as $child_key => $value) { $extensions->unsupported[$key ? "$key:$child_key" : "$child_key"] = (string) $value; @@ -64,6 +72,11 @@ public static function toXML(Extensions $extensions, \DOMDocument &$document) $node->appendChild($child); } + if (null !== $extensions->styleExtension) { + $child = StyleExtensionParser::toXML($extensions->styleExtension, $document); + $node->appendChild($child); + } + if (!empty($extensions->unsupported)) { foreach ($extensions->unsupported as $key => $value) { $child = $document->createElement($key, $value); diff --git a/src/phpGPX/Parsers/Extensions/StyleExtensionParser.php b/src/phpGPX/Parsers/Extensions/StyleExtensionParser.php new file mode 100644 index 0000000..ca6d41f --- /dev/null +++ b/src/phpGPX/Parsers/Extensions/StyleExtensionParser.php @@ -0,0 +1,83 @@ + [ + 'name' => 'color', + 'type' => 'string' + ], + 'opacity' => [ + 'name' => 'opacity', + 'type' => 'float' + ], + 'width' => [ + 'name' => 'width', + 'type' => 'float' + ], + 'pattern' => [ + 'name' => 'pattern', + 'type' => 'string' + ], + 'linecap' => [ + 'name' => 'linecap', + 'type' => 'string' + ], + ]; + + /** + * @param \SimpleXMLElement $node + * @return StyleExtension + */ + public static function parse($node) + { + $extension = new StyleExtension(); + + foreach (self::$attributeMapper as $key => $attribute) { + $extension->{$attribute['name']} = isset($node->$key) ? $node->$key : null; + if (!is_null($extension->{$attribute['name']})) { + settype($extension->{$attribute['name']}, $attribute['type']); + } + } + + return $extension; + } + + /** + * @param StyleExtension $extension + * @param \DOMDocument $document + * @return \DOMElement + */ + public static function toXML(StyleExtension $extension, \DOMDocument &$document) + { + $node = $document->createElement("gpxstyle:line"); + + ExtensionParser::$usedNamespaces[StyleExtension::EXTENSION_NAME] = [ + 'namespace' => StyleExtension::EXTENSION_NAMESPACE, + 'xsd' => StyleExtension::EXTENSION_NAMESPACE_XSD, + 'name' => StyleExtension::EXTENSION_NAME, + 'prefix' => StyleExtension::EXTENSION_NAMESPACE_PREFIX + ]; + + foreach (self::$attributeMapper as $key => $attribute) { + if (!is_null($extension->{$attribute['name']})) { + $child = $document->createElement( + sprintf("%s:%s", StyleExtension::EXTENSION_NAMESPACE_PREFIX, $key), + $extension->{$attribute['name']} + ); + $node->appendChild($child); + } + } + + return $node; + } +} diff --git a/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.json b/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.json index 4cbd70b..874c77c 100644 --- a/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.json +++ b/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.json @@ -9,5 +9,11 @@ "course": null, "bearing": null }, + "line": { + "color": "FF0000", + "opacity": 0.5, + "width": 1, + "linecap": "square" + }, "unsupported": [] } diff --git a/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.php b/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.php index 352b0e6..587f2d2 100644 --- a/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.php +++ b/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.php @@ -3,6 +3,7 @@ namespace UnitTests\phpGPX\Parsers; use phpGPX\Models\Extensions; +use phpGPX\Models\Extensions\StyleExtension; use phpGPX\Models\Extensions\TrackPointExtension; use phpGPX\Parsers\ExtensionParser; @@ -27,8 +28,15 @@ public static function createTestInstance() $trackpoint->hr = (float) 152; $trackpoint->heartRate = (float) 152; + $style = new StyleExtension(); + $style->color = (string) "FF0000"; + $style->opacity = (float) 0.5; + $style->width = (float) 1; + $style->linecap = (string) "square"; + $extensions = new Extensions(); $extensions->trackPointExtension = $trackpoint; + $extensions->styleExtension = $style; return $extensions; } @@ -46,6 +54,7 @@ public function testParse() $this->assertEquals($this->testModelInstance->unsupported, $extensions->unsupported); $this->assertEquals($this->testModelInstance->trackPointExtension, $extensions->trackPointExtension); + $this->assertEquals($this->testModelInstance->styleExtension, $extensions->styleExtension); $this->assertEquals($this->testModelInstance->toArray(), $extensions->toArray()); } @@ -71,8 +80,9 @@ public function testToXML() $attributes = [ 'xmlns' => 'http://www.topografix.com/GPX/1/1', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', - 'xsi:schemaLocation' => '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 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 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 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 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 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', + 'xsi:schemaLocation' => '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 http://www.topografix.com/GPX/gpx_style/0/2 http://www.topografix.com/GPX/gpx_style/0/2.xsd', 'xmlns:gpxtpx' => 'http://www.garmin.com/xmlschemas/TrackPointExtension/v1', + 'xmlns:gpxstyle' => 'http://www.topografix.com/GPX/gpx_style/0/2', 'xmlns:gpxx' => 'http://www.garmin.com/xmlschemas/GpxExtensions/v3', ]; diff --git a/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.xml b/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.xml index 17f0b8b..cb08a2e 100644 --- a/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.xml +++ b/tests/UnitTests/phpGPX/Parsers/ExtensionParserTest.xml @@ -1,9 +1,15 @@ - + 14 152 + + FF0000 + 0.5 + 1 + square +