| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * The main sportsdb class. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | namespace TheSportsDb; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use TheSportsDb\Entity\EntityManagerConsumerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use TheSportsDb\Entity\EntityManagerConsumerTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use TheSportsDb\Entity\EntityManagerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * Main API class for TheSportsDb. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @author Jelle Sebreghts | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | class TheSportsDb implements EntityManagerConsumerInterface { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |   use EntityManagerConsumerTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |    * Creates a new TheSportsDb instance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |   public function __construct(EntityManagerInterface $entityManager = NULL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     if ($entityManager instanceof EntityManagerInterface) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |       $this->entityManager = $entityManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |   public function getSports() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     return $this->entityManager->repository('sport')->all(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |    * Get a sport by name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |    * @param string $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |    *   The sport name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |    * @return \TheSportsDb\Entity\SportInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |   public function getSport($name) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     return $this->entityManager->repository('sport')->byId($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |   public function getLeagues() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     return $this->entityManager->repository('league')->all(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |    * Get a league by id. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |    * @param int $leagueId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |    *   The league id. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |    * @return \TheSportsDb\Entity\LeagueInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |   public function getLeague($leagueId) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     return $this->entityManager->repository('league')->byId($leagueId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |   public function getLeaguesByCountry($country) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     return $this->entityManager->repository('league')->byCountry($country); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |   public function getLeaguesBySport($sport) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     return $this->entityManager->repository('league')->bySport($sport); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |   } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |   public function getLeaguesByCountryAndSport($country, $sport) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     return $this->entityManager->repository('league')->byCountryAndSport($country, $sport); | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |   public function getTeam($teamId) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     return $this->entityManager->repository('team')->byId($teamId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     public function getTeamByName($teamName) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     return $this->entityManager->repository('team')->byName($teamName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |   public function getTeamsByLeague($leagueId) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     return $this->entityManager->repository('team')->byLeague($leagueId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |   public function getTeamsByLeagueName($leagueName) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     return $this->entityManager->repository('team')->byLeagueName($leagueName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |   public function getTeamsBySportAndCountry($sport, $country) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     return $this->entityManager->repository('team')->bySportAndCountry($sport, $country); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |   public function getPlayer($playerId) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     return $this->entityManager->repository('player')->byId($playerId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |   public function getPlayersByTeamName($teamName) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     return $this->entityManager->repository('player')->byTeamName($teamName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |   public function getPlayersByName($teamName) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     return $this->entityManager->repository('player')->byName($teamName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |   public function getPlayersByTeamNameAndName($teamName, $name) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     return $this->entityManager->repository('player')->byTeamNameAndName($teamName, $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |   public function getEvent($eventId) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     return $this->entityManager->repository('event')->byId($eventId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |   public function getEventsByName($name) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     return $this->entityManager->repository('event')->byName($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |   public function getEventsByFileName($name) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     return $this->entityManager->repository('event')->byFileName($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |   public function getEventsByNameAndSeason($name, $season) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     return $this->entityManager->repository('event')->byNameAndSeason($name, $season); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |   public function getSeasonsByLeague($leagueId) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     return $this->entityManager->repository('season')->byLeague($leagueId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |   } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 129 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 130 |  |  |  | 
            
                        
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.