Library for processing open data published by FIDE for PHP
- Download all player rating XML files published by FIDE
- Read and parse player rating XML files
Use Composer to install the library for your project:
composer require tegenterter/fide-data
<?php
require __DIR__ . '/vendor/autoload.php';
// Download particular rating file from https://ratings.fide.com/download_lists.phtml
$client = new \FideData\Http\RatingXmlDownloader(__DIR__);
$path = $client->download(\FideData\Enum\RatingType::STANDARD, 2020, 12);
// Read and parse the rating file
$rating = new \FideData\PlayerRating($path);
/** @var \FideData\Structure\Player $player */
foreach ($rating->process() as $player) {
// Get array representation of the player object
$array = $player->toArray();
echo json_encode($array, JSON_PRETTY_PRINT) . PHP_EOL;
/**
{
"fideId": 1503014,
"name": "Carlsen, Magnus",
"federation": "NOR",
"birthYear": 1990,
"sex": "M",
"title": "GM",
"standardRating": {
"type": "standard",
"rating": 2862,
"k": 10
},
"rapidRating": null,
"blitzRating": null,
"active": true
}
*/
}
The library is covered by unit tests using PHPUnit. You can use the following Composer script to run them:
composer run test