-
Notifications
You must be signed in to change notification settings - Fork 7
/
default_bootstrap.php
56 lines (44 loc) · 2.26 KB
/
default_bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
include_once __DIR__ . '/vendor/autoload.php';
if (!defined('THESPORTSDB_API_KEY')) {
define('THESPORTSDB_API_KEY', '1');
}
if (
class_exists('\Symfony\Component\DependencyInjection\ContainerBuilder')
&& class_exists('\Symfony\Component\Config\Resource\FileResource')
&& class_exists('Symfony\Component\DependencyInjection\Loader\YamlFileLoader')
&& class_exists('\HendrichA\TagPassLibrary\TagPass')
) {
// Use the dependency injection container if available.
include_once __DIR__ . '/default_bootstrap_dic.php';
return;
}
// Http client.
$httpClient = new GuzzleHttp\Client();
// Factory container.
$factoryContainer = new TheSportsDb\Entity\Factory\FactoryContainer();
// Repository container.
$repositoryContainer = new TheSportsDb\Entity\Repository\RepositoryContainer();
// Property mapper.
$propertyMapper = new FastNorth\PropertyMapper\Mapper();
// Entity manager.
$entityManager = new TheSportsDb\Entity\EntityManager($propertyMapper, $factoryContainer, $repositoryContainer);
$entityManager->registerClass('league');
$entityManager->registerClass('sport');
$entityManager->registerClass('team');
$entityManager->registerClass('event');
$entityManager->registerClass('player');
$entityManager->registerClass('season');
// The sports db client.
$sportsDbClient = new TheSportsDb\Http\TheSportsDbClient(THESPORTSDB_API_KEY, $httpClient);
// Repositories.
$repositoryContainer->addRepository(new TheSportsDb\Entity\Repository\SportRepository($sportsDbClient, $entityManager));
$repositoryContainer->addRepository(new TheSportsDb\Entity\Repository\LeagueRepository($sportsDbClient, $entityManager));
$repositoryContainer->addRepository(new TheSportsDb\Entity\Repository\SeasonRepository($sportsDbClient, $entityManager));
$repositoryContainer->addRepository(new TheSportsDb\Entity\Repository\EventRepository($sportsDbClient, $entityManager));
$repositoryContainer->addRepository(new TheSportsDb\Entity\Repository\PlayerRepository($sportsDbClient, $entityManager));
$repositoryContainer->addRepository(new TheSportsDb\Entity\Repository\TeamRepository($sportsDbClient, $entityManager));
// Factory.
$factory = new \TheSportsDb\Entity\Factory\Factory($sportsDbClient, $entityManager);
$factoryContainer->setDefaultFactory($factory);
$db = new TheSportsDb\TheSportsDb($entityManager);