Skip to content

LeagueAPI: Callback functions

Daniel Dolejška edited this page Dec 13, 2018 · 2 revisions

Version v3.0.0-rc.1

Custom function callback before and after the call is made.

Settings key Data type Info / Possible values
LeagueAPI::SET_CALLBACKS_BEFORE callable|callable[] see example below
LeagueAPI::SET_CALLBACKS_AFTER callable|callable[] see example below

Before request callbacks

Every before request callback will receive these parameters:

Parameter name Data type Description
$api LeagueAPI Instance of LeagueAPI. If you wish to edit something in the instance, use &$api instead, in your callback function declaration.
$url string Complete URL to be called in request.
$requestHash string This hash is used when caching request. It is unique identificator of URL. Requests on same endpoints with same parameters will have same hash.

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.

In case rate limiting feature is enabled and limit should be exceeded by upcomming call, no before request callbacks will be called and Exceptions\ServerLimitException exception will be raised.

After request callback function parameters

Every after request callback will receive these parameters:

Parameter name Data type Description
$api LeagueAPI Instance of LeagueAPI. If you wish to edit something in the instance, use &$api instead, in your callback function declaration.
$url string Complete URL to be called in request.
$requestHash string This hash is used when caching request. It is unique identificator of URL. Requests on same endpoints with same parameters will have same hash.
$curlResource resource cUrl resource used in request, can be used to get usefull request information (e.g. with curl_getinfo function).

In case the call failed, exception will be raised based on HTTP code and no after request callbacks will be called.

Library initialization

use RiotAPI\LeagueAPI\LeagueAPI;

$api = new LeagueAPI([
	// ...
	LeagueAPI::SET_CALLBACKS_BEFORE => [
		function($api, $url, $requestHash) {
			// function logic
		},
		array($object, 'functionName'),
	],
	LeagueAPI::SET_CALLBACKS_AFTER => function($api, $url, $requestHash, $curlResource) {
		// function logic
	},
	// ...
]);