lmerotta / phpokeapi
一个用于PokéAPI的PHP7.1包装器,具有缓存和懒加载功能
1.1.5
2019-09-27 06:37 UTC
Requires
- php: ^7.1.3
- doctrine/common: ^2.8
- jms/serializer: ^1.11
- ocramius/proxy-manager: ^2.1
- psr/cache: ^1.0
- psr/simple-cache: ^1.0
- symfony/cache: ^4.0
- symfony/yaml: ^4.0
Requires (Dev)
- phpunit/phpunit: ^7.2
README
A PHP7.1+ wrapper for PokéAPI. This package offers the possibility to query the majority of the PokéAPI endpoints (see exceptions below). It supports caching of responses and lazy-loading relations.
安装
composer require lmerotta/phpokeapi
基本用法
使用PokeAPI\Client
通过命名方法直接查询端点。
<?php use PokeAPI\Client; $client = new Client(); // Returns a PokeAPI\Pokemon\Species instance $species = $client->species('bulbasaur'); // or $client->species(1);
然后您可以遍历返回的对象。所有关系都是代理,除非您显式调用它们的getter之一,否则不会向API发出新请求
<?php // ... $species->getName(); // 'bulbasaur' $growthRate = $species->getGrowthRate(); // A proxy of PokeAPI\Pokemon\GrowthRate $growthRate->getName(); // Here the real API call to the GrowthRate endpoint is made
所有请求都进行缓存,因此您不必为相同的数据集查询两次。
PokeAPI\Client
PokeAPI\Client
接受3个可选参数
$url
,一个指向PokéAPI基本URL的字符串。默认为pokeapi.co$cache
,一个Psr\SimpleCache\CacheInterface
。默认为Symfony\Component\Cache\Simple\FilesystemCache
实例$serializer
,一个JMS\Serializer\SerializerInterface
实现。
贡献
请随意打开拉取请求或提交问题!