/**
  * Store an error into $this->error, developers can refer to it
  * as $tournament|$match|etc->error()
  * 
  * In order to standardize error values, we send it first to the main library class,
  * which will either save as-is or convert to an array - either way it will return us the new value
  *      We locally store the value returned back from the main library
  * 
  * Lastly, we return false - this allows model methods simultaneously set an error, and return false
  * at the same time - allowing me to be lazy and type that all into a single line :)
  * 
  * @ignore
  * 
  * @param array|string $error
  * @return boolean<br />
  * Always returns <b>false</b>
  */
 protected function set_error($error)
 {
     //Send to the main BinaryBeast API Library, and locally save whatever is sent back (a standardized format)
     $this->last_error = $this->bb->set_error($error, $this->get_class_name());
     //Allows return this directly to return false, saves a line of code - don't have to set_error then return false
     return false;
 }
 /**
  */
 public function test_error_history()
 {
     $this->object->set_error('Custom Error');
     $key = sizeof($this->object->error_history) - 1;
     $this->assertTrue(is_object($this->object->error_history[$key]));
     $this->assertEquals('Custom Error', $this->object->error_history[$key]->error_message);
 }
 /**
  * Attempt to extract data sent from a BinaryBeast callback
  * 
  * <br />
  * This method will try to extract the data from $_POST and $_GET, and then
  * process the data further based on the event_id
  * 
  * <br /><br />
  * For example if a tourney_info array is provided, you'll get a full {@link BBTournament} instance
  * 
  * 
  * @return BBCallbackHandlerObject|boolean
  *	<b>FALSE</b> returned if unable to find any relevent data in $_POST and $_GET
  * 
  *	<br /><br />
  *	Refer to the properties documented in {@link BBCallbackObject} for values that you can expect
  * 
  *	<br /><br />
  *	In additon to the standard values in {@link BBCallbackObject}, each event may return data that this method will convert into <b>model objects</b><br/ >
  *	For example, if the callback sends a tourney_info array, you can expect <var>$tournament</var> to be a {@link BBTournament} model object
  * 
  *	<br /><br />
  *	Events that expect these values are documented in each event_id constant in this class
  */
 public function handle_callback()
 {
     //Prepare the object we'll be returning
     $data = new stdClass();
     //Figure out if we should use $_POST or $_GET, then save a refernece to $request
     $request = null;
     if (isset($_POST['callback_id'])) {
         $request =& $_POST;
     } else {
         if (isset($_GET['callback_id'])) {
             $request =& $_GET;
         } else {
             return $this->bb->set_error('Unable to locate a "callback_id" value in either $_POST or $_GET');
         }
     }
     //All standard callback values must be present
     $keys = array('callback_id', 'event_id', 'event_description', 'event_utc_date');
     foreach ($keys as $key) {
         if (!isset($request[$key])) {
             return $this->bb->set_error('Unable to locate a "' . $key . '" value, unable to process this as a valid callback', 'BBCallback');
         }
         $data->{$key} = $request[$key];
     }
     //Try to extract a tournament
     if (isset($request['tourney_info'])) {
         $data->tournament = $this->bb->tournament($request);
     } else {
         if (strpos($request['trigger_id'], 'x') === 0) {
             $data->tournament = $this->bb->tournament($request['trigger_id']);
         } else {
             if (isset($request['tourney_id'])) {
                 $data->tournament = $this->bb->tournament($request['tourney_id']);
             }
         }
     }
     //Try to extract a match
     if (isset($request['match_info'])) {
         if (isset($request['games'])) {
             $data->match = $this->bb->match($request);
         }
     } else {
         if (isset($request['tourney_match_id'])) {
             $data->match = $this->bb->match($request['tourney_match_id']);
         }
     }
     //Try to extract a team
     if (isset($request['team_info'])) {
         $data->team = $this->bb->team($request);
     } else {
         if (isset($request['tourney_team_id'])) {
             $data->team = $this->bb->team($request['tourney_team_id']);
         }
     }
     //Success!
     return $data;
 }
Beispiel #4
0
 /**
  * Constructor
  * Stores local references to the API library, and the database connection
  * 
  * @ignore
  * 
  * @param BinaryBeast       $bb
  * @param BBConfiguration   $config
  */
 function __construct(BinaryBeast &$bb, BBConfiguration &$config)
 {
     $this->bb =& $bb;
     $this->config =& $config;
     //If an error was returned while trying to connect, add it to BinaryBeast::$error_history
     if ($this->check_values()) {
         if (($error = $this->connect()) !== true) {
             $bb->set_error($error, 'BBCache');
         }
     }
 }
 /**
  * Allows BBCache to give us errors to keep track of
  */
 public function set_error($error, $class = null)
 {
     $this->bb->set_error($error, $class);
 }