SportsDb
in package
FinalYes
The TheSportsDB client.
$db = new SportsDb(); // free key 123: v1 only
$arsenal = $db->v1->lookup->team(133604);
$db = new SportsDb(apiKey: getenv('THESPORTSDB_API_KEY'), cache: new InMemoryResponseCache());
$tv = $db->v2->tv->country('Canada');
Reuse one client per key: its rate limiter and cache cover every call made through it.
Table of Contents
Properties
- $config : Config
- $helpers : Helpers
- Common tasks in one call, using v2 or v1 depending on the key.
- $v1 : V1Api
- The v1 API (free and premium keys).
- $v2 : V2Api
- The v2 API (premium keys only).
Methods
- __construct() : mixed
- Named arguments are the Config settings, plus an optional Transport and Clock.
- isPremiumKey() : bool
- Whether v2 accepts the key. One call (v2 lookup/league/4328) unless it's a free key.
Properties
$config read-only
public
Config
$config
$helpers read-only
Common tasks in one call, using v2 or v1 depending on the key.
public
Helpers
$helpers
$v1 read-only
The v1 API (free and premium keys).
public
V1Api
$v1
$v2 read-only
The v2 API (premium keys only).
public
V2Api
$v2
Methods
__construct()
Named arguments are the Config settings, plus an optional Transport and Clock.
public
__construct([string $apiKey = Config::FREE_API_KEY ][, int|null $requestsPerMinute = null ][, int $maxRetries = 2 ][, float $retryBackoff = 0.5 ][, bool $retryOnRateLimit = true ][, float $rateLimitWait = 60.0 ][, ResponseCache|null $cache = null ][, CachePolicy|null $cachePolicy = null ][, float $timeout = 30.0 ][, callable(RequestEvent): void|null $requestListener = null ][, string $baseUrl = 'https://www.thesportsdb.com' ][, string $userAgent = 'thesportsdb-client-php' ][, Transport|null $transport = null ][, Clock|null $clock = null ]) : mixed
Parameters
- $apiKey : string = Config::FREE_API_KEY
- $requestsPerMinute : int|null = null
- $maxRetries : int = 2
- $retryBackoff : float = 0.5
- $retryOnRateLimit : bool = true
- $rateLimitWait : float = 60.0
- $cache : ResponseCache|null = null
- $cachePolicy : CachePolicy|null = null
- $timeout : float = 30.0
- $requestListener : callable(RequestEvent): void|null = null
- $baseUrl : string = 'https://www.thesportsdb.com'
- $userAgent : string = 'thesportsdb-client-php'
- $transport : Transport|null = null
- $clock : Clock|null = null
isPremiumKey()
Whether v2 accepts the key. One call (v2 lookup/league/4328) unless it's a free key.
public
isPremiumKey() : bool