本文整理汇总了PHP中Wikibase\DataModel\Entity\Item::getStatements方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::getStatements方法的具体用法?PHP Item::getStatements怎么用?PHP Item::getStatements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Wikibase\DataModel\Entity\Item
的用法示例。
在下文中一共展示了Item::getStatements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addStatements
private function addStatements(Item $item)
{
$statement = new Statement(new PropertyValueSnak(42, new StringValue('kittens')));
$statement->setGuid('first guid');
$item->getStatements()->addStatement($statement);
$statement = new Statement(new PropertyNoValueSnak(23));
$statement->setGuid('second guid');
$item->getStatements()->addStatement($statement);
}
示例2: testDataIsOrderedByStatementId
/**
* @depends testGivenKnownItemId_itemIsReturned
*/
public function testDataIsOrderedByStatementId()
{
$item = new Item(new ItemId('Q1'));
$item->getStatements()->addNewStatement(new PropertyValueSnak(new PropertyId('P1337'), new StringValue('kittens')));
$item->getStatements()->addNewStatement(new PropertyValueSnak(new PropertyId('P23'), new StringValue('cats')));
$item->getStatements()->addNewStatement(new PropertyValueSnak(new PropertyId('P42'), new StringValue('bunnies')));
$this->testEnvironment->insertItem($item);
$client = $this->createClient();
$client->request('GET', '/items/Q1');
$this->assertSame(['P23', 'P42', 'P1337'], array_keys(json_decode($client->getResponse()->getContent(), true)['data']));
}
示例3: patchItem
private function patchItem(Item $item, EntityDiff $patch)
{
$this->fingerprintPatcher->patchFingerprint($item->getFingerprint(), $patch);
if ($patch instanceof ItemDiff) {
$item->setSiteLinkList($this->siteLinkListPatcher->getPatchedSiteLinkList($item->getSiteLinkList(), $patch->getSiteLinkDiff()));
}
$item->setStatements($this->statementListPatcher->getPatchedStatementList($item->getStatements(), $patch->getClaimsDiff()));
}
示例4: testClaimsAreDiffed
public function testClaimsAreDiffed()
{
$firstItem = new Item();
$secondItem = new Item();
$secondItem->getStatements()->addNewStatement(new PropertySomeValueSnak(42), null, null, 'guid');
$differ = new ItemDiffer();
$diff = $differ->diffItems($firstItem, $secondItem);
$this->assertCount(1, $diff->getClaimsDiff()->getAdditions());
}
示例5: findSnaksProvider
public function findSnaksProvider()
{
$propertyId = new PropertyId('P1337');
$statement1 = new Statement(new PropertyValueSnak($propertyId, new StringValue('a kitten!')));
$statement1->setGuid('Q42$1');
$statement2 = new Statement(new PropertyValueSnak($propertyId, new StringValue('two kittens!!')));
$statement2->setGuid('Q42$2');
// A Statement with a lower rank which should not affect the output
$statement3 = new Statement(new PropertyValueSnak($propertyId, new StringValue('three kittens!!!')));
$statement3->setGuid('Q42$3');
$statement3->setRank(Statement::RANK_DEPRECATED);
$item = new Item(new ItemId('Q42'));
$item->getStatements()->addStatement($statement1);
$item->getStatements()->addStatement($statement2);
$item->getStatements()->addStatement($statement3);
$snaksNormal = array(new PropertyValueSnak($propertyId, new StringValue('a kitten!')), new PropertyValueSnak($propertyId, new StringValue('two kittens!!')));
$snakDeprecated = array(new PropertyValueSnak($propertyId, new StringValue('three kittens!!!')));
return array(array($snaksNormal, $item, new PropertyId('P1337')), array(array(), $item, new PropertyId('P90001')), array($snakDeprecated, $item, new PropertyId('P1337'), array(Statement::RANK_DEPRECATED)));
}
示例6: testSuggestByItem
public function testSuggestByItem()
{
$item = new Item(new ItemId('Q42'));
$snak = new PropertySomeValueSnak(new PropertyId('P1'));
$guid = 'claim0';
$item->getStatements()->addNewStatement($snak, null, null, $guid);
$res = $this->suggester->suggestByItem($item, 100, 0.0, 'item');
$this->assertEquals(new PropertyId('p2'), $res[0]->getPropertyId());
$this->assertEquals(new PropertyId('p3'), $res[1]->getPropertyId());
}
示例7: findEquivalentStatement
/**
* Finds a statement in the target entity with the same main snak and qualifiers as $fromStatement
*
* @param Statement $fromStatement
*
* @return Statement|false Statement to merge reference into or false
*/
private function findEquivalentStatement($fromStatement)
{
$fromHash = $this->getStatementHash($fromStatement);
/** @var Statement $statement */
foreach ($this->toItem->getStatements() as $statement) {
$toHash = $this->getStatementHash($statement);
if ($toHash === $fromHash) {
return $statement;
}
}
return false;
}
示例8: testGetStatementFromEntity
public function testGetStatementFromEntity()
{
$helper = $this->getNewInstance();
$item = new Item(new ItemId('Q42'));
$snak = new PropertyValueSnak(2754236, new StringValue('test'));
$statement = new Statement($snak);
$statement->setGuid('q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0F');
$item->getStatements()->addStatement($statement);
$guid = $statement->getGuid();
$this->assertEquals($statement, $helper->getStatementFromEntity($guid, $item));
$this->setExpectedException('\\UsageException');
$helper->getStatementFromEntity('q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0N', $item);
}
示例9: testSerialize
public function testSerialize()
{
$item = new Item();
$item->setLabel('de', 'German');
$item->setDescription('de', 'German');
$item->setAliases('de', array('German'));
$item->setAliases('en', array('English'));
$item->getStatements()->addNewStatement(new PropertyNoValueSnak(1));
$instance = $this->newInstance();
$serialization = $instance->serialize($item);
$expected = array('type' => 'item', 'labels' => array('en' => array('source-language' => '<SOURCE>')), 'descriptions' => array('en' => array('source-language' => '<SOURCE>')), 'aliases' => array('en' => array(array('language' => 'en', 'value' => 'English'))), 'claims' => array('P1' => array(array('mainsnak' => array('snaktype' => 'novalue', 'property' => 'P1', 'datatype' => '<DATATYPE>'), 'type' => 'statement', 'rank' => 'normal'))));
$this->assertSame($expected, $serialization);
}
示例10: testAttemptSave
public function testAttemptSave()
{
$mockApiBase = $this->getMockApiBase();
$mockApiBase->expects($this->once())->method('isWriteMode')->will($this->returnValue(true));
$mockApiBase->expects($this->atLeastOnce())->method('getContext')->will($this->returnValue($this->newContext()));
$mockApiBase->expects($this->atLeastOnce())->method('extractRequestParams')->will($this->returnValue(array()));
$helper = new EntitySavingHelper($mockApiBase, $this->getMockErrorReporter(), $this->getMockSummaryFormatter(), $this->getMockEditEntityFactory(1));
$entity = new Item();
$entity->setId(new ItemId('Q444'));
$entity->getFingerprint()->setLabel('en', 'Foo');
$entity->getSiteLinkList()->addNewSiteLink('enwiki', 'APage');
$entity->getStatements()->addNewStatement(new PropertyNoValueSnak(new PropertyId('P8')));
$summary = 'A String Summary';
$flags = 0;
$status = $helper->attemptSaveEntity($entity, $summary, $flags);
$this->assertTrue($status->isGood());
}
示例11: getMockRepository
/**
* Returns a MockRepository. The following entities are defined:
*
* - Items Q23
* - Item Q42
* - Redirect Q2233 -> Q23
* - Redirect Q222333 -> Q23
* - Property P5 (item reference)
*
* @return MockRepository
*/
private function getMockRepository()
{
$mockRepo = new MockRepository();
$p5 = new Property(new PropertyId('P5'), null, 'wikibase-item');
$p5->getFingerprint()->setLabel('en', 'Label5');
$mockRepo->putEntity($p5);
$q23 = new Item(new ItemId('Q23'));
$q23->getFingerprint()->setLabel('en', 'Label23');
$mockRepo->putEntity($q23);
$q2233 = new EntityRedirect(new ItemId('Q2233'), new ItemId('Q23'));
$mockRepo->putRedirect($q2233);
$q222333 = new EntityRedirect(new ItemId('Q222333'), new ItemId('Q23'));
$mockRepo->putRedirect($q222333);
$q42 = new Item(new ItemId('Q42'));
$q42->getFingerprint()->setLabel('en', 'Label42');
$snak = new PropertyValueSnak($p5->getId(), new EntityIdValue($q2233->getEntityId()));
$q42->getStatements()->addNewStatement($snak, null, null, 'Q42$DEADBEEF');
$mockRepo->putEntity($q42);
return $mockRepo;
}
开发者ID:Benestar,项目名称:mediawiki-extensions-Wikibase,代码行数:31,代码来源:EntityDataSerializationServiceTest.php
示例12: deserializationProvider
public function deserializationProvider()
{
$provider = array(array(new Item(), array('type' => 'item')));
$item = new Item(new ItemId('Q42'));
$provider[] = array($item, array('type' => 'item', 'id' => 'Q42'));
$item = new Item();
$item->getFingerprint()->setLabel('en', 'foo');
$provider[] = array($item, array('type' => 'item', 'labels' => array('en' => array('lang' => 'en', 'value' => 'foo'))));
$item = new Item();
$item->getFingerprint()->setDescription('en', 'foo');
$provider[] = array($item, array('type' => 'item', 'descriptions' => array('en' => array('lang' => 'en', 'value' => 'foo'))));
$item = new Item();
$item->getFingerprint()->setAliasGroup('en', array('foo', 'bar'));
$provider[] = array($item, array('type' => 'item', 'aliases' => array('en' => array('lang' => 'en', 'values' => array('foo', 'bar')))));
$item = new Item();
$item->getStatements()->addNewStatement(new PropertyNoValueSnak(42), null, null, 'test');
$provider[] = array($item, array('type' => 'item', 'claims' => array('P42' => array(array('mainsnak' => array('snaktype' => 'novalue', 'property' => 'P42'), 'type' => 'statement', 'rank' => 'normal')))));
$item = new Item();
$item->addSiteLink(new SiteLink('enwiki', 'Nyan Cat'));
$provider[] = array($item, array('type' => 'item', 'sitelinks' => array('enwiki' => array('site' => 'enwiki', 'title' => 'Nyan Cat', 'badges' => array()))));
return $provider;
}
示例13: entityProvider
public function entityProvider()
{
$entities = array();
$entity = new Item(new ItemId('Q42'));
$entities[] = array($entity);
$entity = new Item();
$entity->setLabels(array('en' => 'Nyan Cat', 'fr' => 'Nyan Cat'));
$entities[] = array($entity);
$entity = new Item();
$entity->setDescriptions(array('en' => 'A Nyan Cat', 'fr' => 'A Nyan Cat'));
$entities[] = array($entity);
$entity = new Item();
$entity->setAliases('en', array('Cat', 'My cat'));
$entity->setAliases('fr', array('Cat'));
$entities[] = array($entity);
$entity = new Item();
$entity->getStatements()->addNewStatement(new PropertyNoValueSnak(42), null, null, 'guid');
$entities[] = array($entity);
$item = new Item();
$item->addSiteLink(new SiteLink('enwiki', 'Nyan Cat'));
$entities[] = array($item);
$entities[] = array(Property::newFromType('string'));
return $entities;
}
示例14: provideValidate
public function provideValidate()
{
$p11 = new PropertyId('P11');
$q17 = new ItemId('Q17');
$item = new Item($q17);
$claimGuid = $this->mockProvider->getGuidGenerator()->newGuid($q17);
$oldSnak = new PropertyValueSnak($p11, new StringValue("old reference"));
$oldReference = new Reference(new SnakList(array($oldSnak)));
$snak = new PropertyNoValueSnak($p11);
$qualifiers = new SnakList(array($oldSnak));
$item->getStatements()->addNewStatement($snak, $qualifiers, null, $claimGuid);
//NOTE: the mock validator will consider the string "INVALID" to be invalid.
$badSnak = new PropertyValueSnak($p11, new StringValue('INVALID'));
$brokenSnak = new PropertyValueSnak($p11, new NumberValue(23));
$badReference = new Reference(new SnakList(array($badSnak)));
$brokenReference = new Reference(new SnakList(array($brokenSnak)));
$refHash = $oldReference->getHash();
$cases = array();
$cases['invalid snak value'] = array($item, $claimGuid, $badReference, '');
$cases['invalid snak value type'] = array($item, $claimGuid, $brokenReference, $refHash);
return $cases;
}
示例15: newItem
private function newItem()
{
$item = new Item(new ItemId('Q7799929'));
$item->setLabel('en', 'kitten item');
$statements = $item->getStatements();
$statements->addNewStatement(new PropertyValueSnak(42, new StringValue('http://an.url.com')));
$statements->addNewStatement(new PropertyValueSnak(42, new StringValue('https://another.url.org')));
$statements->addNewStatement(new PropertyValueSnak(10, new StringValue('File:This is a file.pdf')));
$statements->addNewStatement(new PropertyValueSnak(10, new StringValue('File:Selfie.jpg')));
return $item;
}