/** * Create a new match, or validate an existing one<br /><br /> * * <br /><br /> * Can be used 2 ways:<br /><br /> * <b>1)</b> Returns the open BBMatch object where the $team1 and $team2 meet,<br /> * it will try to return an unreported BBMatch from the open_matches array * * <br /> * <b>2)</b> Verifies that the provided BBMatch object is valid / part of this tournament * In which case, we return the valid most up-to-date object instance possible, even if the only thing that matches * from your BBMatch, is the id * * * @param int|BBTeam|BBMatch $team1 * <b>Possible values:</b> * - The <b>integer</b> ID the either team in the match * - The {@link BBTeam} object of either team in the match * - A {@link BBMatch} object - to verify that it exists and to fetch the latest and created instance, stored in our open matches array * * @param int|BBTeam $team2 * <b>Possible values:</b> * - The <b>integer</b> ID the either team in the match (can't be the same as <var>$team1</var>) * - The {@link BBTeam} object of either team in the match (can't be the same as <var>$team1</var>) * * @return BBMatch|null */ public function &match($team1 = null, $team2 = null) { //If given BBMatch, verify or return null if ($team1 instanceof BBMatch) { //if unreported - check it against our open_matches list if ($team1->is_new()) { return $this->get_child($team1, $this->open_matches()); } else { //Cast as a BBMatch $match = $this->bb->match($team1->id); $match->init($this); if ($match->tourney_id != $this->id) { return $this->bb->ref(null); } //success! return $match; } } //If team1 is a number, and team 2 is null, treat team1 as a tourney_match_id if (is_numeric($team1) && is_null($team2)) { $match = $this->bb->match($team1); $match->init($this); return $match->load(); } //Let open_match() take over return $this->open_match($team1, $team2); }