bluepsyduck/factorio-mod-portal-client 问题修复 & 功能扩展

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

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

bluepsyduck/factorio-mod-portal-client

Composer 安装命令:

composer require bluepsyduck/factorio-mod-portal-client

包简介

A client to access the Factorio mod portal.

README 文档

README

GitHub release (latest SemVer) GitHub build Codecov

This library implements a PHP client to access the API of the Factorio Mod Portal.

Usage

The client is shipped with a ConfigProvider to directly integrate it into a Zend Expressive project. Using it in other contexts will require additional configuration not covered by this README file.

To use the client in a Zend Expressive context, add the BluePsyduck\FactorioModPortalClient\ConfigProvider to your config aggregator, and fetch the actual client or the facade from the container.

Configuration

The client provides a zero-config setup. Yet, to use the full feature set, few values are required to be configured:

<?php

use BluePsyduck\FactorioModPortalClient\Constant\ConfigKey;

return [
    ConfigKey::MAIN => [
        ConfigKey::OPTIONS => [
            // Your Factorio username. This username is used to build a full download link, avoiding getting redirected
            // to the login page. 
            // See https://wiki.factorio.com/Mod_portal_API#Downloading_Mods for further details.
            ConfigKey::OPTION_USERNAME => 'your-username',
            // The token to your username.
            ConfigKey::OPTION_TOKEN => 'your-token',

            // The timeout in seconds to use for the request. Defaults to 10 seconds.
            ConfigKey::OPTION_TIMEOUT => 10,
        ],
    ],
];

Example

There are basically two approaches to requesting data from the mod portal API: Using the facade for simple access, and using the client directly for the full set of features.

Using the facade is straight forward: Request the facade instance from the container, pass the requests in and get the responses back:

<?php
/* @var \Psr\Container\ContainerInterface $container */

use BluePsyduck\FactorioModPortalClient\Client\Facade;
use BluePsyduck\FactorioModPortalClient\Request\ModRequest; 

/* @var Facade $facade */
$facade = $container->get(Facade::class);

$mod = $facade->getMod((new ModRequest())->setName('FARL'));

// Do something with the received mod.
var_dump($mod->getDownloadsCount());

Using the client itself allows you to make parallel requests using the Promises returned by the client for the requests.

<?php
/* @var \Psr\Container\ContainerInterface $container */

use BluePsyduck\FactorioModPortalClient\Client\ClientInterface;
use BluePsyduck\FactorioModPortalClient\Request\ModRequest; 
use BluePsyduck\FactorioModPortalClient\Response\ModResponse;
use function GuzzleHttp\Promise\all;

/* @var ClientInterface $client */
$client = $container->get(ClientInterface::class);

$request1 = (new ModRequest())->setName('FARL');
$request2 = (new ModRequest())->setName('FNEI');

/* @var ModResponse[] $responses*/
$responses = all([
    'FARL' => $client->sendRequest($request1),
    'FNEI' => $client->sendRequest($request2)
])->wait();

// Do something with the responses
var_dump($responses['FARL']->getSummary());
var_dump($responses['FNEI']->getSummary());

Additionally, both the facade and the client provide methods to transform download and asset paths to their full URL:

<?php 
/* @var BluePsyduck\FactorioModPortalClient\Client\Facade $facade */
/* @var BluePsyduck\FactorioModPortalClient\Response\ModResponse $response */

$downloadUrl = $facade->getDownloadUrl($response->getReleases()[0]->getDownloadUrl());
$thumbnail = $facade->getAssetUrl($response->getThumbnail());

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2019-09-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固