nellyt/free-to-game-api-wrapper

为 https://www.freetogame.com API提供的包装器

v1.0.2 2021-03-08 21:21 UTC

This package is auto-updated.

Last update: 2024-09-09 05:03:12 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

这是一个针对FreeToGame API的PHP包装器

基本安装

您可以通过Composer使用以下命令安装此包:

composer require nellyt/free-to-game-api-wrapper

使用方法

基本

require ('vendor/autoload.php');

$client = new \FreeToGame\Client();

$response = $client->fetchList();
$response = $client->fetchDetails($gameId);

$response->getResponse()->getStatusCode();

$response->getData();

过滤器

在获取游戏列表时使用过滤器。有三种类型的过滤器

  1. 平台
  2. 类别
  3. 标签

过滤器添加到FilterCollection实例中,并将其传递给客户端。

平台过滤器

$platformFilter = new \FreeToGame\Filters\PlatformFilter(new \FreeToGame\Filters\Platforms\Browser());

$filterCollection = new \FreeToGame\Filters\FilterCollection();
$filterCollection->setPlatformFilter($platformFilter);

$response = $client->fetchList($filterCollection);

类别/标签过滤器

游戏列表可以通过类别或标签进行筛选,但不能同时使用两者。标签过滤器需要一个SearchTerms数组,而类别过滤器只接受一个。

类别
$categoryFilter = new \FreeToGame\Filters\CategoryFilter(new \FreeToGame\Filters\SearchTerms\Shooter());

$filterCollection = new \FreeToGame\Filters\FilterCollection();
$filterCollection->setCategoryFilter($categoryFilter);

$response = $client->fetchList($filterCollection);
标签
$searchTerms = [
    new \FreeToGame\Filters\SearchTerms\Shooter(),
    new \FreeToGame\Filters\SearchTerms\Strategy(),
    new \FreeToGame\Filters\SearchTerms\Racing(),
];

$tagFilter = new \FreeToGame\Filters\TagFilter($searchTerms);
$filterCollection = new \FreeToGame\Filters\FilterCollection();
$filterCollection->setTagFilter($tagFilter);

$response = $client->fetchList($filterCollection);
标签辅助工具

有两个辅助函数可用于构建SearchTerms数组。

$shooter = \FreeToGame\Helpers\SearchTermFactory::getSearchTerm('shooter');
$searchTerms = \FreeToGame\Helpers\SearchTermFactory::getSearchTerms(['shooter', 'zombie', 'permadeath']);

排序

可以排序游戏列表。

$sort = new \FreeToGame\Sort\AlphabeticalSort();

$response = $client->fetchList(null, $sort);

示例:多个过滤器和排序

$platformFilter = new \FreeToGame\Filters\PlatformFilter(new \FreeToGame\Filters\Platforms\Browser());

$searchTerms = [
    new \FreeToGame\Filters\SearchTerms\Shooter(),
    new \FreeToGame\Filters\SearchTerms\Strategy(),
    new \FreeToGame\Filters\SearchTerms\Racing(),
];
$tagFilter = new \FreeToGame\Filters\TagFilter($searchTerms);

$filterCollection = new \FreeToGame\Filters\FilterCollection();
$filterCollection->setPlatformFilter($platformFilter);
$filterCollection->setTagFilter($tagFilter);

$sort = new \FreeToGame\Sort\AlphabeticalSort();

$response = $client->fetchList($filterCollection, $sort);

排序选项

排序选项列表如下

  1. 按字母顺序排序
  2. 按流行度排序
  3. 按发布日期排序
  4. 按相关性排序
  5. 排序

搜索词

搜索词列表如下

  1. 操作
  2. 动作角色扮演游戏
  3. 动漫
  4. 大逃杀
  5. 卡牌
  6. 幻想
  7. 格斗
  8. 第一人称
  9. 飞行
  10. 恐怖
  11. 低配置
  12. 武术
  13. 大型多人在线
  14. 大型多人在线第一人称射击游戏
  15. 大型多人在线即时战略游戏
  16. 大型多人在线角色扮演游戏
  17. 大型多人在线第三人称射击游戏
  18. 军事
  19. 多人在线战斗竞技场
  20. 开放世界
  21. 永久死亡
  22. 像素
  23. 玩家对抗环境
  24. 玩家对抗玩家
  25. 赛车
  26. 航海
  27. 沙盒
  28. 科幻
  29. 搜索词
  30. 射击
  31. 侧滚动
  32. 社交
  33. 太空
  34. 体育
  35. 策略
  36. 超级英雄
  37. 生存
  38. 坦克
  39. 第三人称
  40. 三维
  41. 俯视视角
  42. 塔防
  43. 回合制
  44. 二维
  45. 体素
  46. 僵尸