-
-
Notifications
You must be signed in to change notification settings - Fork 25
LeagueAPI: Extensions
Version v3.0.0-rc.1
Using extensions for ApiObjects is useful tool, allowing implementation of your own methods into the ApiObjects itself.
Extensions are enabled by using settings option LeagueAPI::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.
This specific example no longer works, but Extensions feature still works the same way...
use RiotAPI\LeagueAPI\LeagueAPI;
use RiotAPI\LeagueAPI\Objects;
use RiotAPI\LeagueAPI\Extensions;
$api = new LeagueAPI([
// ...
LeagueAPI::SET_EXTENSIONS => [
Objects\MasteryPagesDto::class => Extensions\MasteryPagesDtoExtension::class,
// API_OBJECT_TO_BE_EXTENDED => EXTENDING_CLASS,
],
// ...
]);
And from now on, on any MasteryPagesDto
object returned to you by the API, you can
use methods declared in your extension class. Just like this:
$masteryPages = $api->getMasteriesBySummoner(30904166);
if ($masteryPages->pageExists('MasterPageName'))
echo "Mastery page exists.";
if ($page = $masteryPages->getPageByName('MasterPageName'))
{
echo $page->id;
echo $page->name;
}
On initialization the extension class is provided with Objects\IApiObject
reference (in example case above it would be Objects\MasteryPagesDto
) and LeagueAPI
instance reference.