brieucthomas/ergast-client

Ergast 开发者 API 的 PHP 客户端

v1.0.1 2020-09-09 14:09 UTC

This package is not auto-updated.

Last update: 2024-09-19 08:57:31 UTC


README

Build Status Software License Latest Version Total Downloads

Ergast 开发者 API 的 PHP 客户端。

要求

PHP 至少需要 7.0 版本。

安装

此库可以通过 Composer 轻松安装

composer require brieucthomas/ergast-client

或者直接将其添加到您的 composer.json 文件中,然后运行 composer install。

用法

use BrieucThomas\ErgastClient\ErgastClientBuilder;
use BrieucThomas\ErgastClient\Request\RequestBuilder;

$ergastClient = ErgastClientBuilder::createErgastClient();

$requestBuilder = new RequestBuilder();
$requestBuilder
    ->findCircuits()
    ->byId('monza')
;

$response = $ergastClient->execute($requestBuilder->build());
$circuit = $response->getCircuits()->first();

echo $circuit->getId();                       // "monza"
echo $circuit->getName();                     // "Autodromo Nazionale di Monza"
echo $circuit->getUrl();                      // "http://en.wikipedia.org/wiki/Autodromo_Nazionale_Monza"
echo $circuit->getLocation()->getLocality();  // "Monza"
echo $circuit->getLocation()->getCountry();   // "Italy"
echo $circuit->getLocation()->getLatitude();  // 45.6156
echo $circuit->getLocation()->getLongitude(); // 9.28111

限制和偏移量

$uriBuilder
    ->setFirstResult(2)
    ->setMaxResults(5)
;