iarcadia/php-magic-pokeapi
Composer 安装命令:
composer require iarcadia/php-magic-pokeapi
包简介
An awesome PokéAPI PHP wrapper.
README 文档
README
This package is a POO-oriented PHP wrapper for using the version 2 of the RESTful API PokéAPI. With MagicPokeAPI, you can obtain tons of data from PokéAPI server, thanks to some lines. The package includes an useful mini caching system.
What's PokéAPI?
This is a full RESTful API linked to an extensive database detailing everything about the Pokémon main game series.
Installation
Require this package with composer:
composer require iarcadia/php-magic-pokeapi
Configuration
First of all, you need to check files into the config folder.
cache.php is cache systems related.
request.php is request systems related.
lang.php is language systems related.
Please, respect the comments written in these files.
Usage
First step
Yep, you probably guess right: you have to create an instance of your favorite PokéAPI wrapper in order to continue.
$api = new PokeAPI();
Don't forget to include files or to use classes. (e.g. use iArcadia\MagicPokeAPI\PokeAPI)
Second step
You must specify the resource that you want to look for! Use the resource() method.
$api->resource('pokemon'); // or (and the recommended one) $api->resource(PokeAPI::RESOURCE_POKEMON);
The PokeAPI class provides constants for all resources. It could be a good idea to use them instead of direct string.
A constant list is available in src/PokeAPI.php file.
Endpoints
Setting the number of results (or "limit")
Use the limit() method.
$api->limit(20);
Setting the search starting point (or "offset")
Use the offset() or the skip() method.
$api->offset(5); // or $api->skip(5);
The skip() method is an alias for the offset() one.
Executing the request
Use the get() method.
$data = $api->get();
Resource details
Very simple, just use the find() method.
// by name $item = $api->find('arcanine'); // or by id $item = $api->find(25);
Other
Requesting raw URLs
You want to directly write your URL? Use the raw() method.
// endpoint $api->raw('/ability/'); // with parameters $api->raw('/pokemon-species/?limit=30&offset=60'); // resource details $api->raw('/pokemon/bulbasaur/'); // with full URL $api->raw('https://www.pokeapi.co/api/v2/item/203');
You can specify many URLs with an array, or with many arguments.
// array way $api->raw(['/ability/', 'https://www.pokeapi.co/api/v2/item/203']); // many args way $api->raw('/ability/', 'https://www.pokeapi.co/api/v2/item/203');
Note that after using it, your PokeAPI object properties (url, resource, limit and offset) will be updated from your raw URL (or the last one if you specifies many URLs).
Forcing the cache update
If a reason, you want to force the update of a cached file, use the cacheForcing() method.
$api->cacheForcing(true);
It will update the cache for the next request ONLY.
Tips
Chaining methods
Thanks to the power of the POO, you can quickly set up options between two different requests.
// for endpoint $api->limit(20)->offset(60)->resource(PokeAPI::RESOURCE_ITEM)->get(); // for resource details $api->resource(PokeAPI::RESOURCE_ITEM)->find('potion');
Constructor options
If you prefer, you can also set up options at the instance creation (if you know that they won't change for example).
$api = new PokeApi( [ 'limit' => 20, 'offset' => 0, // works with "skip" too 'resource' => PokeAPI::RESOURCE_CONTEST_EFFECT ]);
Using automatic resource name translation
/!\ CURRENTLY ONLY WORK WITH POKEMON NAME /!\
If you decide to activate the automatic resource name translation (in the config/lang.php file), you will be able to use your language name for requesting data!
// Charizard in french will be translated to: // $api->resource(PokeAPI::RESOURCE_POKEMON)->find('charizard'); $api->resource(PokeAPI::RESOURCE_POKEMON)->find('dracaufeu'); // Nidoqueen in korean will be translated to: // $api->resource(PokeAPI::RESOURCE_POKEMON)->find('nidoqueen'); $api->resource(PokeAPI::RESOURCE_POKEMON)->find('니드퀸');
Bonus: even if you use this feature, all english will continue to work!
CHANGELOGS
See CHANGELOGS.md
iarcadia/php-magic-pokeapi 适用场景与选型建议
iarcadia/php-magic-pokeapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 12 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「pokemon」 「pokeapi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 iarcadia/php-magic-pokeapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iarcadia/php-magic-pokeapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 iarcadia/php-magic-pokeapi 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Pokeapi PHP Wrapper
The Pokemon Go API library.
Alfabank REST API integration
Endroid Pokemon
The most accurate PHP lib to calculate Pokemon Go IV
This is an update to the Pokémon TCG SDK PHP implementation. It is a wrapper around the Pokémon TCG API of pokemontcg.io.
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-14