PHPackages                             elogank/lol-php-api-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. elogank/lol-php-api-client

ActiveLibrary[API Development](/categories/api)

elogank/lol-php-api-client
==========================

League of Legends PHP API Client

71251PHP

Since Nov 27Pushed 11y ago1 watchersCompare

[ Source](https://github.com/EloGank/lol-php-api-client)[ Packagist](https://packagist.org/packages/elogank/lol-php-api-client)[ RSS](/packages/elogank-lol-php-api-client/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Since the October 1st 2014, a custom API is not fully allowed by the League of Legend's Terms of Use, only some API calls are allowed. More information :
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#since-the-october-1st-2014-a-custom-api-is-not-fully-allowed-by-the-league-of-legends-terms-of-use-only-some-api-calls-are-allowed-more-information---httpsdeveloperriotgamescom)

---

League of Legends PHP API Client
================================

[](#league-of-legends-php-api-client)

**This client use the API server provided by : **

Installation
------------

[](#installation)

### From Composer

[](#from-composer)

In the `require` key :

```
{
    "require": {
        "elogank/lol-php-api-client": "1.0.*@dev"
    }
}
```

Then, in a CLI window :

```
php composer.phar update "elogank/php-lol-api"

```

#### Composer what ?

[](#composer-what-)

Ok, here a fast lesson about Composer.
Composer is a PHP CLI dependency manager. Download Composer in your project root directory, here :

Then, you'll have a new file : `composer.phar`.
Now create a `composer.json`, and read this brief documentation :
Finally, install this repository !

How to use
----------

[](#how-to-use)

The `Client` object need three parameters, and two as optionals :

- `$host` the server host IP address
- `$port` the server port
- `$format` the default output format
- `$throwException` (optional, default: true) if true, an `ApiException` will be throw on error and the response won't contain the first array level which contain "success" &amp; "result"/"error" keys.
- `$timeout` (optional, default: your php.ini "default\_socket\_timeout" configuration) the connection timeout, in second.

In short :

```
// Declare your client and the configuration
$client = new \EloGank\ApiClient\Client('127.0.0.1', 8080, 'json');

// Do your API request
try {
    $response = $client->send('EUW', 'summoner.summoner_existence', ['Foobar']);
} catch (\EloGank\ApiClient\Exception\ApiException $e) {
    // error
    var_dump($e->getCause(), $e->getMessage());
}
```

The `send()` method have three parameters and one optional :

- `region` it's the client region short name (EUW, NA, ...). Make sure there is a registered client for the selected region in your API !
- `route` the API route, in short it's the "`controller_name`.`method_name`"
- `parameters` it's the route parameters, it's an array
- `format` (optional) if you need a specific format for a specific route (see the [API configuration documentation](https://github.com/EloGank/lol-php-api/blob/master/doc/configuration.md) for available formats)

#### Example

[](#example)

This example is available in the file `examples/index.php`.

**Note 1:** use `192.168.100.10` instead of `127.0.0.1` if you using Virtual Machine for the API server.
**Note 2:** a `ConnectionException` can be thrown if there is a problem with the server (timeout or connection refused, for example). Be sure to handle this case by surrounding with a try/catch and set the timeout in the `Client::__construct()` when an API client timeout.

```
// examples/index.php
