Download the PHP package einar-hansen/php-football-data without Composer
On this page you can find all versions of the php package einar-hansen/php-football-data. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download einar-hansen/php-football-data
More information about einar-hansen/php-football-data
Files in einar-hansen/php-football-data
Package php-football-data
Short Description A PHP service for using the football-data.org API.
License MIT
Homepage https://github.com/einar-hansen/php-football-data
Informations about the package php-football-data
PHP Football Data
This package gets you quickly up and going with FootballData's API using PHP. This implementation uses the V4 (latest) of the API, as of the time of writing. Read more about the API in the quickstart guide.
- Installation
- Getting Started
- Initialization
- Collections
- RateLimit
- About the resources
- Area Resource
- Competition Resource
- Match Resource
- Team Resource
- Person Resource
- Laravel
- Credits
- Testing
- About
- License
Installation
You can install the package via composer:
Getting Started
You should register for an account at https://www.football-data.org.
To use the service you will need create a new instance of EinarHansen\FootballData\FootballDataService::class
. The service requires a client that implements Psr\Http\Client\ClientInterface::class
, like for example GuzzleHttp\Client::class
('not included in the package').
Initialization
To initialize an API service you don't need to pass in any parameters. But you should provide the API Token that you recieved when registering, to avoid limited access and heavy ratelimiting.
Because of PHP PSR support and Psr17FactoryDiscovery|Psr18ClientDiscovery we do not need to pass in the implementations of the PSR
contracts.
Collections
If you want to use the returned data collections as generators, then you can pass an instance of the EinarHansen\Http\Collection\LazyCollectionFactory::class
class, or yor own implementation of the EinarHansen\Http\Contracts\Collection\CollectionFactory::class
if you would like.
RateLimit
If you want to keep track of you rate limiting, then you should also provide an instance of \EinarHansen\Http\Contracts\RateLimit\RateLimiterState::class
. By default the service will remember the attempts and remaining requests in memory, for the duration of the objects lifecycle. Below is an example using the Psr16RateLimitState
that comes with the package, configured for the Free Tier
.
Take a look at football-data pricing page to find the ratelimits for your Tier.
The ratelimiter will update the state with ratelimiting details from the response headers. If you have used up all the attempts, then your requests will return false
.
About the resources
Initialize a service like this.
The service consists of 5 resources:
- Area Resource
- Competition Resource
- Match Resource
- Team Resource
- Person Resource
Every resource contains at least the methods all
and find
. all
will return a collection of items, while find
will grab an item by its id.
If the item you are trying to find is not found/doesn't exists, then the resource methods will return null
.
If you are beeing rate limited, then the methods will return false
.
Area Resource
Read more about the Area Resource at the offical documentation.
Competition Resource
Read more about the Competition Resource at the offical documentation.
Match Resource
Read more about the Match Resource at the offical documentation.
Person Resource
Read more about the Person Resource at the offical documentation.
Team Resource
Read more about the Team Resource at the offical documentation.
Paginator
The Team Resource has a paginate method that returns an instance of the contract EinarHansen\Http\Contracts\Pagination\Paginator::class
that keeps track of the pages and items. The Team Resource uses EinarHansen\FootballData\Pagination\TeamPaginator::class
. The paginator allows you to jump between pages with the nextPage
and previousPage
methods.
Laravel
If you are using Laravel, then you might want to add your API Token
to your .env
file and reference it from you config file. You might also want to register it as a singleton in one of your service providers, for example App\Providers\AppServiceProvider::class
.
Credits
This package uses code from and is greatly inspired by
Testing
This package requires PHP8.1. If you don't have this version locally or as default PHP version, then you can use the bin/develop
helper script. The script is inspired by Laravel Sail, but is much simpler. To use the script you should have Docker installed. It will pull down PHP8.1 for you and allow you to run the testing commands below.
To use the script
The testing environment uses guzzlehttp/guzzle. I experienced some issues with the stream interface of the nyholm/psr7 package when loading the fixture-responses into a ResponseInterface in the testing environment, as the body stream that was created from a local file would not play nice with halaxa/json-machine package. The Nyholm package works well in production and with real responses.
About
Einar Hansen is a webdeveloper in Oslo, Norway. You'll find more information about me on my website.
License
The MIT License (MIT).
All versions of php-football-data with dependencies
einar-hansen/http-sdk Version ^0.5.0
halaxa/json-machine Version ^1.1
psr/http-client-implementation Version ^1.0