-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add links to sub endpoints and wd/pd to item and property get endpoints
- Loading branch information
1 parent
41b9549
commit 82ee42d
Showing
23 changed files
with
421 additions
and
164 deletions.
There are no files selected for viewing
This file contains 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 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,61 @@ | ||
<?php | ||
|
||
namespace Queryr\WebApi\ResponseModel; | ||
|
||
/** | ||
* @licence GNU GPL v2+ | ||
* @author Jeroen De Dauw < jeroendedauw@gmail.com > | ||
*/ | ||
trait SimpleEntityTrait { | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
public $ids = []; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $label = ''; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $description = ''; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
public $aliases = []; | ||
|
||
/** | ||
* @var SimpleStatement[] | ||
*/ | ||
public $statements = []; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $dataUrl = ''; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $labelUrl = ''; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $descriptionUrl = ''; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $aliasesUrl = ''; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $wikidataUrl = ''; | ||
|
||
} |
This file contains 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 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 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 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,85 @@ | ||
<?php | ||
|
||
namespace Queryr\WebApi\Serializers; | ||
|
||
use Queryr\WebApi\ResponseModel\SimpleEntityTrait; | ||
use Serializers\Exceptions\UnsupportedObjectException; | ||
use Serializers\Serializer; | ||
|
||
/** | ||
* @access private | ||
* @licence GNU GPL v2+ | ||
* @author Jeroen De Dauw < jeroendedauw@gmail.com > | ||
*/ | ||
class SimpleEntitySerializer implements Serializer { | ||
|
||
/** | ||
* @var SimpleEntityTrait | ||
*/ | ||
private $entity; | ||
|
||
private $statementSerializer; | ||
|
||
public function __construct( Serializer $statementSerializer ) { | ||
$this->statementSerializer = $statementSerializer; | ||
} | ||
|
||
public function serialize( $object ) { | ||
if ( !in_array( SimpleEntityTrait::class, class_uses( $object ) ) ) { | ||
throw new UnsupportedObjectException( $object, 'Can only serialize instances of SimpleEntityTrait' ); | ||
} | ||
|
||
$this->entity = $object; | ||
|
||
return $this->serializeEntity(); | ||
} | ||
|
||
private function serializeEntity(): array { | ||
$serialization = [ 'id' => $this->entity->ids ]; | ||
|
||
if ( $this->entity->label !== '' ) { | ||
$serialization['label'] = $this->entity->label; | ||
} | ||
|
||
if ( $this->entity->description !== '' ) { | ||
$serialization['description'] = $this->entity->description; | ||
} | ||
|
||
if ( !empty( $this->entity->aliases ) ) { | ||
$serialization['aliases'] = $this->entity->aliases; | ||
} | ||
|
||
if ( $this->entity->labelUrl !== '' ) { | ||
$serialization['label_url'] = $this->entity->labelUrl; | ||
} | ||
|
||
if ( $this->entity->description !== '' ) { | ||
$serialization['description_url'] = $this->entity->descriptionUrl; | ||
} | ||
|
||
if ( $this->entity->aliasesUrl !== '' ) { | ||
$serialization['aliases_url'] = $this->entity->aliasesUrl; | ||
} | ||
|
||
if ( $this->entity->wikidataUrl !== '' ) { | ||
$serialization['wikidata_url'] = $this->entity->wikidataUrl; | ||
} | ||
|
||
$serialization['data_url'] = $this->entity->dataUrl; | ||
|
||
$serialization['data'] = $this->getDataSection(); | ||
|
||
return $serialization; | ||
} | ||
|
||
private function getDataSection(): array { | ||
$data = []; | ||
|
||
foreach ( $this->entity->statements as $simpleStatement ) { | ||
$data[$simpleStatement->propertyName] = $this->statementSerializer->serialize( $simpleStatement ); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 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.