-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.github/ export-ignore | ||
/tests/ export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Endroid\SoccerData\Sofascore\Loader; | ||
|
||
use Endroid\SoccerData\Loader\TeamLoaderInterface; | ||
use Endroid\SoccerData\Model\Game; | ||
use Endroid\SoccerData\Model\Team; | ||
|
||
final class TeamLoader implements TeamLoaderInterface | ||
{ | ||
/** @var array<Team> */ | ||
private array $teams = []; | ||
|
||
public function load(string $identifier): Team | ||
{ | ||
if (isset($this->teams[$identifier])) { | ||
return $this->teams[$identifier]; | ||
} | ||
|
||
$searchUrl = 'https://www.sofascore.com/api/v1/search/all?q='.urlencode($identifier).'&sport=soccer'; | ||
$contents = file_get_contents($searchUrl); | ||
$searchData = json_decode($contents, true); | ||
Check failure on line 24 in src/Sofascore/Loader/TeamLoader.php
|
||
|
||
$team = new Team( | ||
$searchData['results'][0]['entity']['id'], | ||
$searchData['results'][0]['entity']['shortName'] | ||
); | ||
|
||
$gamesUrl = 'https://www.sofascore.com/api/v1/team/'.$team->id.'/events/next/0'; | ||
$contents = file_get_contents($gamesUrl); | ||
$gamesData = json_decode($contents, true); | ||
Check failure on line 33 in src/Sofascore/Loader/TeamLoader.php
|
||
|
||
foreach ($gamesData['events'] as $event) { | ||
$game = new Game( | ||
$event['id'], | ||
\DateTimeImmutable::createFromFormat('U', (string) $event['startTimestamp']), | ||
Check failure on line 38 in src/Sofascore/Loader/TeamLoader.php
|
||
new Team($event['homeTeam']['id'], $event['homeTeam']['shortName']), | ||
new Team($event['awayTeam']['id'], $event['awayTeam']['shortName']), | ||
null | ||
); | ||
$team->addGame($game); | ||
} | ||
|
||
return $team; | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.