-
-
Notifications
You must be signed in to change notification settings - Fork 54
Add the line part of the style extension #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
peternewman
wants to merge
9
commits into
Sibyx:master
Choose a base branch
from
peternewman:style
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f95ad54
chore: Whitespace tidy
peternewman 020645f
chore: Further whitespace tidying
peternewman 3553d3a
chore: Final whitespace tidy
peternewman 5f4009a
chore: Missed whitespace tidy
peternewman 717f1dc
Remove phpdoc-md until dependencies resolved
peternewman 5ed1e17
First attempt at the line part of the style extension
peternewman eb6e8bf
Merge branch 'Sibyx:master' into style
peternewman 7a8e240
Merge branch 'Sibyx:master' into style
peternewman 6060b52
Merge branch 'Sibyx:master' into style
peternewman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| <?php | ||
| /** | ||
| * Created 27/02/26 23:09 | ||
| * @author Peter Newman | ||
| */ | ||
|
|
||
| namespace phpGPX\Models\Extensions; | ||
|
|
||
| use phpGPX\Helpers\SerializationHelper; | ||
|
|
||
| /** | ||
| * Class StyleExtension | ||
| * Extension version: v2 | ||
| * Based on namespace: http://www.topografix.com/GPX/gpx_style/0/2/gpx_style.xsd | ||
| * @package phpGPX\Models\Extensions | ||
| */ | ||
| class StyleExtension extends AbstractExtension | ||
| { | ||
| const EXTENSION_NAMESPACE = 'http://www.topografix.com/GPX/gpx_style/0/2'; | ||
| const EXTENSION_NAMESPACE_XSD = 'http://www.topografix.com/GPX/gpx_style/0/2/gpx_style.xsd'; | ||
|
|
||
| const EXTENSION_NAME = 'line'; | ||
| const EXTENSION_NAMESPACE_PREFIX = 'gpxstyle'; | ||
|
|
||
| /** | ||
| * @var string | ||
| */ | ||
| public $color; | ||
|
|
||
| /** | ||
| * @var float | ||
| */ | ||
| public $opacity; | ||
|
|
||
| /** | ||
| * @var float | ||
| */ | ||
| public $width; | ||
|
|
||
| /** | ||
| * @var string | ||
| */ | ||
| public $pattern; | ||
|
|
||
| /** | ||
| * @var string | ||
| */ | ||
| public $linecap; | ||
|
|
||
| /** | ||
| * StyleExtension constructor. | ||
| */ | ||
| public function __construct() | ||
| { | ||
| parent::__construct(self::EXTENSION_NAMESPACE, self::EXTENSION_NAME); | ||
| } | ||
|
|
||
| /** | ||
| * Serialize object to array | ||
| * @return array | ||
| */ | ||
| public function toArray() | ||
| { | ||
| return [ | ||
| 'color' => 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), | ||
|
Comment on lines
+68
to
+71
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess these more complicated types want implementing at some point? |
||
| ]; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <?php | ||
| /** | ||
| * Created 27/02/26 23:09 | ||
| * @author Peter Newman | ||
| */ | ||
|
|
||
| namespace phpGPX\Parsers\Extensions; | ||
|
|
||
| use phpGPX\Models\Extensions\StyleExtension; | ||
| use phpGPX\Parsers\ExtensionParser; | ||
|
|
||
| class StyleExtensionParser | ||
| { | ||
| private static $attributeMapper = [ | ||
| 'color' => [ | ||
| '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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure there's an official defined prefix for this, should it be gpx_style to match the namespace they use in the URL?