PHP code example of nietonchique / sofascore-api-bundle

1. Go to this page and download the library: Download nietonchique/sofascore-api-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nietonchique / sofascore-api-bundle example snippets


return [
    // ...
    Nietonchique\SofascoreApiBundle\SofascoreApiBundle::class => ['all' => true],
];

use Nietonchique\SofascoreApiBundle\SofascoreClient;

$client = SofascoreClient::create(); // default HTTP transport

$results = $client->search('arsenal')->searchAll();
$event   = $client->match(12436870)->getMatch();   // Dto\Event
$h2h     = $client->match(12436870)->h2h();         // array
$team    = $client->team(42)->getTeam();            // Dto\Team
$games   = $client->basketball()->gamesByDate('basketball', '2026-01-15');

use Nietonchique\SofascoreApiBundle\SofascoreClient;

final class ScoresController
{
    public function __construct(private readonly SofascoreClient $sofascore)
    {
    }

    public function live(): array
    {
        return $this->sofascore->match()->liveGames();
    }
}

$event = $client->match(12436870)->getMatch();
$team  = $event->homeTeam;

// Full translation maps
$team?->fieldTranslations?->name;       // ['ru' => 'Интер', 'sr' => 'Интер', ...]
$team?->fieldTranslations?->shortName;  // ['ru' => 'Инт', ...]

// Convenience accessor
$team?->fieldTranslations?->nameIn(LanguageCode::RU);        // 'Интер'
$team?->fieldTranslations?->nameIn(LanguageCode::SR);        // 'Интер'
$team?->fieldTranslations?->nameIn('xx', 'fallback');        // 'fallback'

use Nietonchique\SofascoreApiBundle\Exception\ApiBlockedException;
use Nietonchique\SofascoreApiBundle\Exception\NotFoundException;
use Nietonchique\SofascoreApiBundle\Exception\SofascoreExceptionInterface;

try {
    $event = $client->match(12436870)->getMatch();
} catch (NotFoundException) {
    // no such match
} catch (ApiBlockedException $e) {
    // Cloudflare blocked this IP — configure a proxy (see below)
} catch (SofascoreExceptionInterface $e) {
    // any other error from the bundle: $e->getMessage()
}