Skip to content

Latest commit

 

History

History
152 lines (109 loc) · 4.51 KB

02-configuration.md

File metadata and controls

152 lines (109 loc) · 4.51 KB

Configuration

Default Configuration

SportMonksFootball(string $apiKey, array $options => []);
use ProgrammatorDev\SportMonksFootball\SportMonksFootball;

$api = new SportMonksFootball('yourapikey', [
    'timezone' => 'UTC',
    'language' => 'en'
]);

Options

timezone

Timezone used when retrieving data. Check the official documentation for more information.

Example:

use ProgrammatorDev\SportMonksFootball\SportMonksFootball;

$api = new SportMonksFootball('yourapikey', [
    'timezone' => 'Europe/Lisbon'
]);

language

Language used when retrieving data. List of all available languages can be found here (still in beta).

Example:

use ProgrammatorDev\SportMonksFootball\Language\Language;
use ProgrammatorDev\SportMonksFootball\SportMonksFootball;

$api = new SportMonksFootball('yourapikey', [
    'language' => Language::JAPANESE
]);

Methods

Important

The PHP API SDK library was used to create the SportMonksFootball PHP API. To get to know about all the available methods, make sure to check the documentation here.

The following sections have examples of some of the most important methods, particularly related with the configuration of the client, cache and logger.

setClientBuilder

By default, this library makes use of the HTTPlug's Discovery library. This means that it will automatically find and install a well-known PSR-18 client and PSR-17 factory implementation for you (if they were not found on your project):

If you don't want to rely on the discovery of implementations, you can set the ones you want:

use Nyholm\Psr7\Factory\Psr17Factory;
use ProgrammatorDev\SportMonksFootball\SportMonksFootball;
use Symfony\Component\HttpClient\Psr18Client;

$api = new SportMonksFootball('yourapikey');

$client = new Psr18Client();
$requestFactory = $streamFactory = new Psr17Factory();

$api->setClientBuilder(
    new ClientBuilder(
        client: $client, 
        requestFactory: $requestFactory, 
        streamFactory: $streamFactory
    )
);

Check the full documentation here.

setCacheBuilder

This library allows configuring the cache layer of the client for making API requests. It uses a standard PSR-6 implementation and provides methods to fine-tune how HTTP caching behaves:

Example:

use ProgrammatorDev\SportMonksFootball\SportMonksFootball;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$api = new SportMonksFootball('yourapikey');

$pool = new FilesystemAdapter();

// set a file-based cache adapter with a 1-hour default cache lifetime
$api->setCacheBuilder(
    new CacheBuilder(
        pool: $pool, 
        ttl: 3600
    )
);

Check the full documentation here.

setLoggerBuilder

This library allows configuring a logger to save data for making API requests. It uses a standard PSR-3 implementation and provides methods to fine-tune how logging behaves:

Example:

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use ProgrammatorDev\SportMonksFootball\SportMonksFootball;

$api = new SportMonksFootball('yourapikey');

$logger = new Logger('api');
$logger->pushHandler(new StreamHandler('/logs/api.log'));

$api->setLoggerBuilder(
    new LoggerBuilder(
        logger: $logger
    )
);

Check the full documentation here.