-
Notifications
You must be signed in to change notification settings - Fork 11
Created StatementListSerializer and StatementListDeserializer #120
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
482e26e
Created StatementListSerializer and StatementListDeserializer
Benestar 5dd40b3
Create tests for StatementListSerializer
Benestar db67076
Fix tests
Benestar 5b108a4
Merge pull request #122 from wmde/fingerprintdeserializer
JeroenDeDauw 2bd9baa
Use StatementListSerializer where appropriate
Benestar bc6203b
Merge pull request #121 from wmde/usestatementlistserializer
JeroenDeDauw 9e4389d
Update README.md
JeroenDeDauw 1fba7f5
Created StatementListSerializer and StatementListDeserializer
Benestar 3826818
Create tests for StatementListSerializer
Benestar 2663375
Fix tests
Benestar bc4df2f
Merge branch 'statementlistserializer' of https://github.com/wmde/Wik…
Benestar 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
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,67 @@ | ||
| <?php | ||
|
|
||
| namespace Wikibase\DataModel\Deserializers; | ||
|
|
||
| use Deserializers\Deserializer; | ||
| use Deserializers\Exceptions\DeserializationException; | ||
| use Wikibase\DataModel\Statement\StatementList; | ||
|
|
||
| /** | ||
| * Package private | ||
| * | ||
| * @licence GNU GPL v2+ | ||
| * @author Bene* < benestar.wikimedia@gmail.com > | ||
| */ | ||
| class StatementListDeserializer implements Deserializer { | ||
|
|
||
| /** | ||
| * @var Deserializer | ||
| */ | ||
| private $statementDeserializer; | ||
|
|
||
| /** | ||
| * @param Deserializer $statementDeserializer | ||
| */ | ||
| public function __construct( Deserializer $statementDeserializer ) { | ||
| $this->statementDeserializer = $statementDeserializer; | ||
| } | ||
|
|
||
| /** | ||
| * @see Deserializer::deserialize | ||
| * | ||
| * @param mixed $serialization | ||
| * | ||
| * @return object | ||
| * @throws DeserializationException | ||
| */ | ||
| public function deserialize( $serialization ) { | ||
| $this->assertHasGoodFormat( $serialization ); | ||
|
|
||
| return $this->getDeserialized( $serialization ); | ||
| } | ||
|
|
||
| private function getDeserialized( array $serialization ) { | ||
| $statementList = new StatementList(); | ||
|
|
||
| foreach( $serialization as $statementArray ) { | ||
| foreach( $statementArray as $statementSerialization ) { | ||
| $statementList->addStatement( $this->statementDeserializer->deserialize( $statementSerialization ) ); | ||
| } | ||
| } | ||
|
|
||
| return $statementList; | ||
| } | ||
|
|
||
| private function assertHasGoodFormat( $serialization ) { | ||
| if( !is_array( $serialization ) ) { | ||
| throw new DeserializationException( 'The StatementList serialization should be an array' ); | ||
| } | ||
|
|
||
| foreach( $serialization as $statementArray ) { | ||
| if( !is_array( $statementArray ) ) { | ||
| throw new DeserializationException( 'The statements per property should be an array' ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
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 spend some time wondering why we have a list of lists here. Having some kind of hint that these are grouped by property id would be nice. Which also makes me wonder if we should just accept statements with a property id different than that of the list they are in. Though that is not something to change here if this just re-implements the current code.
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.
It indeed just reflects the current serialization format. I'm not sure if we should enforce statements grouped by property id in the serializatoin though if it is not done in the DataModel. This is a more general question but we should stay consistent and either do this grouping in Items/Properties as well or don't force it in the serialization.