m1so/leaguewrap 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

m1so/leaguewrap

Composer 安装命令:

composer require m1so/leaguewrap

包简介

Riot Games API client

README 文档

README

Simple yet powerful PHP wrapper for Riot Games API (formerly LeaguePHP/LeagueWrap and paquettg/leaguewrap).

The library has been fully rewritten to support v3 of the League of Legends API and adapted to use modern PHP standards such as PSR-4, PSR-6 and PSR-7. Guzzle has been removed in favor of PHP-HTTP, while the caching and rate-limiting backends now fully support PSR-6 through PHP Cache.

Note that the HTTP client is pluggable and must be chosen when installing the library. For example using Guzzle along with LeagueWrap would look like:

composer require \
    php-http/guzzle6-adapter \
    php-http/message \
    guzzlehttp/psr7 \
    m1so/leaguewrap

See the library users section for more information.

Features

  • Simple API design
    • leverages PHP's magic methods and provides phpdoc annotations
    • implements ArrayAccess and "dot notation" to quickly grab data
  • Rate limiting supports app and method limits
  • PSR-6 compatible caching with multiple backend adapters and framework integrations
  • Batch calls - every method can accept an array of identifiers to generate multiple asynchronous requests

Example

use LeagueWrap\Client as RiotApi;

$api = new RiotApi('RGAPI-xxx', 'euw');

// The following calls produce the same results
$api->match()->getById($id);
$api->match()->byId($id);

// Support for batch calls (requires multiple async requests)
$api->match()->getById([$gameId, $anotherGameId]); // using array as an argument
$api->match()->byIds([$gameId, $anotherGameId]); // dedicated method on the Match API Class

// Simple data access
$myGame = $api->match()->byId($id);
$myGame['gameId'] === $id;
$myGame['teams.0.teamId'] === 100; // "dot" notation support for nested elements

Rate limiting

Any PSR-6 compatible cache pool can be used for rate limiting backend. If no pool is supplied, the filesystem is used. For list of available pools see php-cache docs.

// Redis backend with Predis client
// @see https://github.com/php-cache/predis-adapter
$client = new \Predis\Client('tcp:/127.0.0.1:6379');
$pool = new \Cache\Adapter\Predis\PredisCachePool($client);

$api->setAppLimits([
    '10' => 100, // 100 requests per 10 seconds
], $pool);

// When using Laravel
$store = app(\Illuminate\Cache\Repository::class)->getStore();
$pool = new \Cache\Adapter\Illuminate\IlluminateCachePool($store);

$api->setLimits([
    '10' => 100, // 100 requests per 10 seconds
], $pool);

/*
 * Caching is very similar, infact the same pool can be shared with the rate-limiter.
 */
$api->addCache($pool);
$api->removeCache();

Extras

Additional headers

The underlying PSR response contains additional headers such as:

  • X-Region - region string, can be used with Region::create($value)
  • X-Endpoint - endpoint name, can be used with BaseApi::$endpointDefinitions[$endpointName]

Gotchas

Batch request calls / caching

Consider the following example:

$api->addCache($cachePool)->match()->byIds([$id1, $id2, ..., $idN, $id1]);

it is possible that N+1 requests will be made instead of N (where the second call with $id1 would be cached) because Guzzle can start multiple requests "concurrently", therefore the second call would be fired before the first response could be received and cached.

This scenario is not that significant in most cases as requesting multiple same resources should be avoided in the application logic.

Todo

  • Finish writing annotations for phpdoc
  • Custom cache TTL for individual endpoints
  • Sync rate limits and usage from responses
  • Clean up batch responses sorting
  • Dto support?
  • Should the filesystem cache be used by default or use void?

PHP LeagueWrap API isn't endorsed by Riot Games and doesn't reflect the views or opinions of Riot Games or anyone officially involved in producing or managing League of Legends. League of Legends and Riot Games are trademarks or registered trademarks of Riot Games, Inc. League of Legends © Riot Games, Inc.

统计信息

  • 总下载量: 334
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 3
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固