samwilson/simple-wikidata

A very simplistic library for interacting with Wikidata in PHP.

0.6.1 2019-07-21 01:47 UTC

This package is auto-updated.

Last update: 2024-11-21 21:05:19 UTC


README

This is a simple (and limited, by design) package for interacting with Wikidata from PHP.

Packagist License GitHub issues Scrutinizer Code Quality Code Coverage Build Status

Example

// The Sparql must return an ?item column.
$sparql = "SELECT ?item WHERE { ?item wdt:P31 wd:Q54050 } LIMIT 5";
$cache = new \Stash\Pool(new \Stash\Driver\FileSystem());
$people = new \Samwilson\SimpleWikidata\Query($sparql, 'en', $cache);
foreach ($people->getItems() as $person) {
    // Each $person is an Item object.
    $person->getLabel();
    $person->getPropertyOfTypeItem();
    $person->getPropertyOfTypeQuantity();
    $person->getPropertyOfTypeIdentifier(); // External identifier
    $person->getPropertyOfTypeUrl();
    $person->getPropertyOfTypeTime();
    $person->getPropertyOfTypeString(); // No language
    $person->getPropertyOfTypeText(); // Has language
    $person->getPropertyOfTypeCoord();
    $person->getPropertyOfTypeFile(); // Commons media
}

Licence

GPL3.0+