Riot League of Legends & DataDragon API wrapper for PHP7
Clone or download
dolejska-daniel Merge pull request #23 from SpireGG/master
Add Response codes to Exceptions
Latest commit 37bdb0c Nov 18, 2018

RiotAPI PHP7 wrapper

Version v2.0.2

Build Status Test Coverage GitHub release GitHub pre release Packagist Packagist Packagist

Table of Contents

  1. Introduction
  2. Downloading
  3. League of Legends API
    1. Resource versions
    2. Initializing the library
    3. Usage example
    4. Cache providers
    5. Rate limiting
    6. Call caching
    7. StaticData linking
    8. Extensions
    9. Callback functions
    10. CLI support
  4. DataDragon API


Welcome to the RiotAPI PHP7 library repo! The goal of this library is to create easy-to-use library for anyone who might need one. This is fully object oriented API wrapper for League of Legends' API. A small DataDragon API is also included.

Here are some handy features:

  • Rate limit caching and limit exceeding prevention - fully automatic.
  • Call caching - this enables the library to re-use already fetched data within short timespan - saving time and API rate limit.
  • StaticData linking - library can automatically link Static Data related to your request right into the returned object.
  • Custom callbacks - you can set custom function which will be called before or after the request is processed.
  • Object extensions - you can implement own methods to the fetched API objects itself and enable yourself to use them later to ease of your work.
  • Interim mode support, you are going to be able to use the API the same way whether your key is in interim mode or not (meaning you won't need to change anything when you jump to production).
  • CLI supported! You can use the library easily even in PHP CLI mode.
  • Objects everywhere! API calls return data in special objects.

Please, refer mainly to the wiki pages.


The easiest way to get this library is to use Composer. While having Composer installed it takes only composer require dolejska-daniel/riot-api to get the library ready!

If you are not fan of Composer, you can download whole repository in .zip archive or clone the repository using Git - git clone But in this case, you will have to create your own autoload function.

League of Legends API

Resource versions

Below you can find table of implemented API resources and the version in which they are currently implemented. Please refer to wiki pages for more information about endpoints and resources.

Resource Status
Champion Champion resource implemented version
Champion Mastery Champion Mastery resource implemented version
League League resource implemented version
Masteries Masteries resource implemented version
Match Match resource implemented version
Runes Runes resource implemented version
Spectator Spectator resource implemented version
Static Data Static Data resource implemented version
Stats Stats endpoint implemented version
Status Status resource implemented version
Summoner Summoner resource implemented version
Third Party Code Third Party Code endpoint implemented version
Tournament Tournament resource implemented version
Tournament Stub Tournament Stub resource implemented version

Initializing the library

How to begin?

//  Include all required files
require_once __DIR__  . "/vendor/autoload.php";

use RiotAPI\RiotAPI;
use RiotAPI\Definitions\Region;

//  Initialize the library
$api = new RiotAPI([
	//  Your API key, you can get one at
	//  Target region (you can change it during lifetime of the library instance)

//  And now you are ready to rock!
$ch = $api->getStaticChampion(61); // Orianna <3

And there is a lot more what you can set when initializing the library - mainly to enable special features or to amend behaviour of the library. Please see the wiki pages for complete list of library's settings.

Usage example

Working with RiotAPI can not be easier, just watch how to fetch summoner information based on summoner's name:

//  ...initialization...

//  this fetches the summoner data and returns SummonerDto object
$summoner = $api->getSummonerByName('I am TheKronnY');

echo $summoner->id;             //  30904166
echo $summoner->name;           //  I am TheKronnY
echo $summoner->summonerLevel;  //  30

print_r($summoner->getData());  //  Or array of all the data
/* Array
 * (
 *    [id] => 30904166
 *    [name] => I am TheKronnY
 *    [profileIconId] => 540
 *    [summonerLevel] => 30
 *    [revisionDate] => 1484850969000
 * )

..or how to fetch a static champion data?

//  ...initialization...

//  this fetches the champion data and returns StaticChampionDto object
$champion = $api->getStaticChampion(61);

echo $champion->name;  //  Orianna
echo $champion->title; //  the Lady of Clockwork

print_r($champion->getData());  //  Or array of all the data
/* Array
 * (
 *    [id] => 61
 *    [name] => "Orianna"
 *    [key] => "Orianna"
 *    [title] => "the Lady of Clockwork"
 * )

Cache providers

Cache providers are responsible for keeping data of rate limiting and call caching within instances of the library. This feature is automatically enabled, when any of previously mentioned features is used.

When using this feature, you can set RiotAPI::SET_CACHE_PROVIDER to any class, thought it has to implement Objects\ICacheProvider interface. By using RiotAPI::SET_CACHE_PROVIDER_PARAMS option, you can pass any variables to the cache provider.

For more, please see the wiki pages.

Rate limiting

This clever feature will easily prevent exceeding your per key call limits & method limits. In order to enable this feature, you have to set RiotAPI::SET_CACHE_RATELIMIT to true. Everything is completly automatic, so all you need to do is to enable this feature.

For more, please see the wiki pages.

Call caching

This feature can prevent unnecessary calls to API within short timespan by temporarily saving fetched data from API and using them as the result data. In order to enable this feature, you have to set RiotAPI::SET_CACHE_CALLS to true. You should also provide RiotAPI::SET_CACHE_CALLS_LENGTH option or else default time interval of 60 seconds will be used.

For more, please see the wiki pages.

StaticData linking

This feature allows you to automatically link static data related to your request. This action is time consuming (works well when caching call data for StaticData resource), but calls to StaticData resource are not counted to your rate limit so there is no problem in using it.

For more, please see the wiki pages.


Using extensions for ApiObjects is useful tool, allowing implementation of your own methods into the ApiObjects itself. Extensions are enabled by using settings option RiotAPI::SET_EXTENSIONS when initializing the library.

Any extending class must implement Objects\IApiObjectExtension. Only class names are provided, no instances required. Extension will be initialized (instantiated) when object is being initialized.

For more, please see the wiki pages.

Callback functions

Custom function callback before and after the call is made.

Before request callbacks have ability to cancel upcomming request - when false is returned by any callback function, exception Exceptions\RequestException is raised and request is cancelled.

For more, please see the wiki pages.

CLI support.

You can easily get API results even in CLI:

root@localhost:~/src/RiotAPI# php7.0 RiotAPICLI.php getChampions --config ~/RiotAPI_Config.json

For more information about CLI support, please see the wiki pages.

DataDragon API

How easy is it to work with static images? For instance, to get loading screen art of Orianna?


echo DataDragonAPI::getChampionLoading('Orianna');
echo DataDragonAPI::getChampionLoading('Orianna', 7);


<img src="" class="dd-icon dd-loading" alt="Orianna">
<img src="" class="dd-icon dd-loading" alt="Orianna">


Orianna Dark Star Orianna

...a bit of nostalgia?


echo DataDragonAPI::getItemIcon(3132);
echo DataDragonAPI::getItemIcon(3126);
echo DataDragonAPI::getItemIcon(3138);


<img src="" class="dd-icon dd-item" alt="3132">
<img src="" class="dd-icon dd-item" alt="3126">
<img src="" class="dd-icon dd-item" alt="3138">


Heart of Gold Madred's Bloodrazor Leviathan

For more, please see the wiki pages.