jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/336818 )
Change subject: Always use SerializerFactory from top level factory
......................................................................
Always use SerializerFactory from top level factory
This is a prerequisit for following patches where we want to add
support for more entity types.
Change-Id: I385e9d26b02a72b216a78043ba0908ab150e97da
---
M repo/includes/Api/ApiHelperFactory.php
M repo/includes/Specials/SpecialEntityData.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/Api/ApiHelperFactoryTest.php
4 files changed, 31 insertions(+), 27 deletions(-)
Approvals:
WMDE-leszek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/includes/Api/ApiHelperFactory.php
b/repo/includes/Api/ApiHelperFactory.php
index 0982064..1711bdc 100644
--- a/repo/includes/Api/ApiHelperFactory.php
+++ b/repo/includes/Api/ApiHelperFactory.php
@@ -3,7 +3,6 @@
namespace Wikibase\Repo\Api;
use ApiBase;
-use DataValues\Serializers\DataValueSerializer;
use Serializers\Serializer;
use SiteLookup;
use Wikibase\DataModel\Entity\EntityIdParser;
@@ -65,6 +64,11 @@
private $siteLookup;
/**
+ * @var SerializerFactory
+ */
+ private $serializerFactory;
+
+ /**
* @var Serializer
*/
private $entitySerializer;
@@ -99,6 +103,7 @@
* @param SummaryFormatter $summaryFormatter
* @param EntityRevisionLookup $entityRevisionLookup
* @param EditEntityFactory $editEntityFactory
+ * @param SerializerFactory $serializerFactory
* @param Serializer $entitySerializer
* @param EntityIdParser $idParser
* @param SiteLinkLookup|null $siteLinkLookup
@@ -113,6 +118,7 @@
SummaryFormatter $summaryFormatter,
EntityRevisionLookup $entityRevisionLookup,
EditEntityFactory $editEntityFactory,
+ SerializerFactory $serializerFactory,
Serializer $entitySerializer,
EntityIdParser $idParser,
SiteLinkLookup $siteLinkLookup = null,
@@ -126,6 +132,7 @@
$this->summaryFormatter = $summaryFormatter;
$this->entityRevisionLookup = $entityRevisionLookup;
$this->editEntityFactory = $editEntityFactory;
+ $this->serializerFactory = $serializerFactory;
$this->entitySerializer = $entitySerializer;
$this->idParser = $idParser;
$this->siteLinkLookup = $siteLinkLookup;
@@ -144,7 +151,7 @@
return new ResultBuilder(
$api->getResult(),
$this->titleLookup,
- $this->newSerializerFactory(),
+ $this->serializerFactory,
$this->entitySerializer,
$this->siteLookup,
$this->dataTypeLookup,
@@ -164,19 +171,6 @@
$api,
$this->exceptionLocalizer,
$api->getLanguage()
- );
- }
-
- /**
- * Returns a serializer factory to be used when constructing API
results.
- *
- * @return SerializerFactory
- */
- public function newSerializerFactory() {
- return new SerializerFactory(
- new DataValueSerializer(),
-
SerializerFactory::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH +
-
SerializerFactory::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH
);
}
diff --git a/repo/includes/Specials/SpecialEntityData.php
b/repo/includes/Specials/SpecialEntityData.php
index dc666dc..f326c79 100644
--- a/repo/includes/Specials/SpecialEntityData.php
+++ b/repo/includes/Specials/SpecialEntityData.php
@@ -2,7 +2,6 @@
namespace Wikibase\Repo\Specials;
-use DataValues\Serializers\DataValueSerializer;
use HttpError;
use Wikibase\DataModel\SerializerFactory;
use Wikibase\Repo\LinkedData\EntityDataFormatProvider;
@@ -77,8 +76,7 @@
$entityIdParser = $wikibaseRepo->getEntityIdParser();
$entityDataFormatProvider = new EntityDataFormatProvider();
- $serializerFactory = new SerializerFactory(
- new DataValueSerializer(),
+ $serializerFactory = $wikibaseRepo->getSerializerFactory(
SerializerFactory::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH +
SerializerFactory::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH
);
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 8234b1f..e934d56 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -1309,10 +1309,12 @@
}
/**
+ * @param int $options bitwise combination of the
SerializerFactory::OPTION_ flags
+ *
* @return SerializerFactory
*/
- public function getSerializerFactory() {
- return new SerializerFactory( new DataValueSerializer() );
+ public function getSerializerFactory( $options = 0 ) {
+ return new SerializerFactory( new DataValueSerializer(),
$options );
}
/**
@@ -1353,7 +1355,7 @@
public function getEntitySerializer( $options = 0 ) {
if ( !isset( $this->entitySerializers[$options] ) ) {
$serializerFactoryCallbacks =
$this->entityTypeDefinitions->getSerializerFactoryCallbacks();
- $serializerFactory = new SerializerFactory( new
DataValueSerializer(), $options );
+ $serializerFactory = $this->getSerializerFactory(
$options );
$serializers = array();
foreach ( $serializerFactoryCallbacks as $callback ) {
@@ -1519,6 +1521,9 @@
* @return ApiHelperFactory
*/
public function getApiHelperFactory( IContextSource $context ) {
+ $serializerOptions =
SerializerFactory::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH
+ +
SerializerFactory::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH;
+
return new ApiHelperFactory(
$this->getEntityTitleLookup(),
$this->getExceptionLocalizer(),
@@ -1527,10 +1532,8 @@
$this->getSummaryFormatter(),
$this->getEntityRevisionLookup( 'uncached' ),
$this->newEditEntityFactory( $context ),
- $this->getEntitySerializer(
-
SerializerFactory::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH +
-
SerializerFactory::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH
- ),
+ $this->getSerializerFactory( $serializerOptions ),
+ $this->getEntitySerializer( $serializerOptions ),
$this->getEntityIdParser(),
$this->getStore()->newSiteLinkStore(),
$this->getEntityFactory(),
diff --git a/repo/tests/phpunit/includes/Api/ApiHelperFactoryTest.php
b/repo/tests/phpunit/includes/Api/ApiHelperFactoryTest.php
index 42daac9..5dd2a2e 100644
--- a/repo/tests/phpunit/includes/Api/ApiHelperFactoryTest.php
+++ b/repo/tests/phpunit/includes/Api/ApiHelperFactoryTest.php
@@ -8,6 +8,7 @@
use Language;
use Serializers\Serializer;
use Wikibase\DataModel\Entity\ItemIdParser;
+use Wikibase\DataModel\SerializerFactory;
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
use Wikibase\EditEntityFactory;
use Wikibase\Lib\Store\EntityRevisionLookup;
@@ -33,9 +34,16 @@
private function newApiHelperFactory() {
$summaryFormatter = $this->getMockBuilder(
SummaryFormatter::class )
- ->disableOriginalConstructor()->getMock();
+ ->disableOriginalConstructor()
+ ->getMock();
+
$editEntityFactory = $this->getMockBuilder(
EditEntityFactory::class )
- ->disableOriginalConstructor()->getMock();
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $serializerFactory = $this->getMockBuilder(
SerializerFactory::class )
+ ->disableOriginalConstructor()
+ ->getMock();
return new ApiHelperFactory(
$this->getMock( EntityTitleLookup::class ),
@@ -45,6 +53,7 @@
$summaryFormatter,
$this->getMock( EntityRevisionLookup::class ),
$editEntityFactory,
+ $serializerFactory,
$this->getMock( Serializer::class ),
new ItemIdParser(),
null
--
To view, visit https://gerrit.wikimedia.org/r/336818
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I385e9d26b02a72b216a78043ba0908ab150e97da
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits