This is a small library to integrate Handball4All results and tables into a PHP website, that has some kind of persistence to it.
Calling H4A on every of your clients request has two major downsides:
- the nested request massively slows down the original request
- the effect amplificates, if it is desired to deliver content, that itself cannot be requested from H4A in a single request
Therefore, this library is meant to scrape all needed information into a local database (or any kind of persistence), such that this can feed the resulting page with a maximum of performance and flexibility.
The important components to understand are the Updater
, the
PersistenceInterface
, and the Models.
You will need to provide a PersistenceInterface
yourself, to actually fit your
persistence solution. You can take a look at
SqliteAdapter
to see a sample
implementation, or just use it if it fits your needs.
The Updater
is the central component. It proviedes the update function, which
gathers all information for all teams and stores it.
For it to work, it needs an object, that implements the PersistenceInterface
.
It's responsibilities are to
- tell the
Updater
, which teams need to be updated, via thegetTeams
method - save the data gahtered by the
Updater
using thereplaceLeagueData
method
The Models are how those components communicate with each other and also how you
would probably want to access the gathered data afterwards.
Those models might seem confusing at first glance, but they try to resemble the
H4A API-Response as close as possible. Therefore, you can look at the H4A page
to actually see, what all those fields refere to.
There are:
Game
: One single GameGameSchedule
: A set of games for the associated team, as well as the league's metadataLeagueData
: An triplet joiningLeagueMetadata
, aTable
and aGameSchedule
LeagueMetadata
: Metadata, that belongs to a leagueTabScore
: A line in the league's tableTable
: A Table, no more than a collection ofTabScore
sTeam
: A Team. In contrast to all previous models theTeam
has no relation to any API response. It is only used to communicate between thePersistenceInterface
and theUpdater
.
This library is not on Packagist intentionally. However, you can install it
via this GitHub-Repo directly using Composer anyways:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/tobb10001/h4a-integration"
}
],
"require": {
"tobb10001/h4a-integration": "<choose a revision>"
}
}
use H4aIntegration\Tobb10001\Updater;
/**
* Updating Function.
* You would probably want to hook this function into some kind of cron mechanism.
*/
function updateH4a() {
persistence = new MyPersistence(...); // must implement PersistenceInterface
updater = new Updater(persistence);
result = updater->update();
// do logging or whatever with result
}