jenkins-bot has submitted this change and it was merged.
Change subject: Take entity instantiator callbacks from
WikibaseRepo.entitytypes.php
......................................................................
Take entity instantiator callbacks from WikibaseRepo.entitytypes.php
Bug: T132964
Change-Id: I0c062fef694fa9c444238e09ecc6ec41f2d7e14b
---
M docs/entitytypes.wiki
M lib/includes/EntityTypeDefinitions.php
M lib/tests/phpunit/EntityTypeDefinitionsTest.php
M repo/WikibaseRepo.entitytypes.php
M repo/includes/WikibaseRepo.php
5 files changed, 37 insertions(+), 15 deletions(-)
Approvals:
Aude: Looks good to me, but someone else must approve
Adrian Heine: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/entitytypes.wiki b/docs/entitytypes.wiki
index 7e99793..6f7cee3 100644
--- a/docs/entitytypes.wiki
+++ b/docs/entitytypes.wiki
@@ -52,6 +52,8 @@
: a string representing the id of the content model
; content-handler-factory-callback (repo only)
: a callable that returns an EntityHandler instance supporting this entity type
+; entity-factory-callback (repo only)
+: a callback for creating an empty entity of this type
; js-deserializer-factory-function (repo only)
: a string representing a resource loader module that, when `require`d,
returns a function returning
a `wikibase.serialization.Deserializer` instance supporting this entity type
diff --git a/lib/includes/EntityTypeDefinitions.php
b/lib/includes/EntityTypeDefinitions.php
index d674200..aa4afe0 100644
--- a/lib/includes/EntityTypeDefinitions.php
+++ b/lib/includes/EntityTypeDefinitions.php
@@ -21,6 +21,7 @@
* - content-model-id: a string used as the content model identifier
* - content-handler-factory-callback: a callback for creating a content
handler dealing with
* entities of this type
+ * - entity-factory-callback: a callback for creating an empty entity of this
type
*
* @see docs/entitytypes.wiki
*
@@ -110,6 +111,13 @@
}
/**
+ * @return callable[]
+ */
+ public function getEntityFactoryCallbacks() {
+ return $this->getMapForDefinitionField(
'entity-factory-callback' );
+ }
+
+ /**
* @return string[]
*/
public function getJsDeserializerFactoryFunctions() {
diff --git a/lib/tests/phpunit/EntityTypeDefinitionsTest.php
b/lib/tests/phpunit/EntityTypeDefinitionsTest.php
index a5ab834..e6c18ce 100644
--- a/lib/tests/phpunit/EntityTypeDefinitionsTest.php
+++ b/lib/tests/phpunit/EntityTypeDefinitionsTest.php
@@ -20,14 +20,16 @@
'deserializer-factory-callback' =>
'foo-deserializer',
'view-factory-callback' => 'foo-view',
'content-model-id' => 'foo-model',
- 'content-handler-factory-callback' =>
'foo-handler'
+ 'content-handler-factory-callback' =>
'foo-handler',
+ 'entity-factory-callback' => 'new-foo',
),
'bar' => array(
'serializer-factory-callback' =>
'bar-serializer',
'deserializer-factory-callback' =>
'bar-deserializer',
'view-factory-callback' => 'bar-view',
'content-model-id' => 'bar-model',
- 'content-handler-factory-callback' =>
'bar-handler'
+ 'content-handler-factory-callback' =>
'bar-handler',
+ 'entity-factory-callback' => 'new-bar',
),
'baz' => array()
);
@@ -93,4 +95,16 @@
);
}
+ public function testGetEntityFactoryCallbacks() {
+ $definitions = new EntityTypeDefinitions(
$this->getDefinitions() );
+
+ $this->assertEquals(
+ array(
+ 'foo' => 'new-foo',
+ 'bar' => 'new-bar'
+ ),
+ $definitions->getEntityFactoryCallbacks()
+ );
+ }
+
}
diff --git a/repo/WikibaseRepo.entitytypes.php
b/repo/WikibaseRepo.entitytypes.php
index a309650..af53142 100644
--- a/repo/WikibaseRepo.entitytypes.php
+++ b/repo/WikibaseRepo.entitytypes.php
@@ -16,6 +16,8 @@
* @author Bene* < [email protected] >
*/
+use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\Property;
use Wikibase\DataModel\Services\Lookup\LabelDescriptionLookup;
use Wikibase\LanguageFallbackChain;
use Wikibase\Repo\WikibaseRepo;
@@ -41,7 +43,10 @@
'content-handler-factory-callback' => function() {
$wikibaseRepo = WikibaseRepo::getDefaultInstance();
return $wikibaseRepo->newItemHandler();
- }
+ },
+ 'entity-factory-callback' => function() {
+ return new Item();
+ },
),
'property' => array(
'view-factory-callback' => function(
@@ -62,6 +67,9 @@
'content-handler-factory-callback' => function() {
$wikibaseRepo = WikibaseRepo::getDefaultInstance();
return $wikibaseRepo->newPropertyHandler();
- }
+ },
+ 'entity-factory-callback' => function() {
+ return Property::newFromType( '' );
+ },
)
);
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 5e49aa4..bda7f84 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -1181,17 +1181,7 @@
* @return EntityFactory
*/
public function getEntityFactory() {
-
- //TODO: get this from EntityTypeDefinitions
-
- $instantiators = array(
- Item::ENTITY_TYPE => function() {
- return new Item();
- },
- Property::ENTITY_TYPE => function() {
- return Property::newFromType( '' );
- },
- );
+ $instantiators =
$this->entityTypeDefinitions->getEntityFactoryCallbacks();
return new EntityFactory( $instantiators );
}
--
To view, visit https://gerrit.wikimedia.org/r/285446
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0c062fef694fa9c444238e09ecc6ec41f2d7e14b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Adrian Heine <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits