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');
$events  = $client->match()->scheduledEventsByDate('football', '2026-06-28');

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()
}

use Nietonchique\SofascoreApiBundle\SofascoreClient;
use Nietonchique\SofascoreApiBundle\Transport\RouteTransportFactory;
use Nietonchique\SofascoreApiBundle\Transport\TransportRoute;
use Symfony\Component\HttpClient\HttpClient;

$factory = new RouteTransportFactory(HttpClient::create());
$route = new TransportRoute(
    id: 'bg-primary',
    provider: 'provider-a',
    proxy: 'socks5h://127.0.0.1:10841',
    chromeProxy: 'socks5://127.0.0.1:10841',
);

$client = SofascoreClient::create($factory->create($route, 'chain'));