Beispiel #1
0
 /**
  * Makes an HTTP request to the provided URL
  *
  * @param   Boolean - should this throw an exception? (Default = TRUE)
  *
  * @return  **Object** - 
  * Example response object
  * <code>
  * {
  *  status: "http_response_header",
  *  route: "STRING",
  *  errors: "ARRAY/OBJECT/STRING",
  *  data: "ARRAY/OBJECT/STRING"
  * }
  * </code>
  *
  * @since   2015-11-05
  * @author  Deac Karns <*****@*****.**>
  * @author  Wesley Dekkers <*****@*****.**>
  */
 public function run($throw_exception = TRUE)
 {
     $contents = json_decode(file_get_contents($this->url, false, $this->context));
     $result = new \stdClass();
     $result->status = $http_response_header[0];
     $result->route = $this->url;
     $result->errors = "";
     $result->success = TRUE;
     if (!strpos($http_response_header[0], '200')) {
         if (is_object($contents) && !empty($contents->errors)) {
             foreach ($contents->errors as $error) {
                 \Rhonda\Error::add_summary_item($error);
             }
         } else {
             \Rhonda\Error::add_summary_item(implode(" - ", $http_response_header));
         }
         $result->errors = \Rhonda\Error::summary();
         $result->success = FALSE;
         // When hard error End call here
         if ($throw_exception) {
             throw new \Exception("Rhonda API Gateway detected an error");
         }
     }
     $result->data = $contents->data;
     return $result;
 }
Beispiel #2
0
try {
    throw new Exception("Demo Error Exception 2");
} catch (\Exception $e) {
    $error = new \Rhonda\Error();
    echo $error->handle($e);
}
echo "</br>";
try {
    throw new Exception("Demo Error Exception 3", 404);
} catch (\Exception $e) {
    $error = new \Rhonda\Error();
    echo $error->handle($e);
}
echo "</br>";
try {
    throw new Exception("Demo Error Exception 4");
} catch (\Exception $e) {
    $error = new \Rhonda\Error();
    echo $error->handle($e, 402);
}
\Rhonda\Error::deprecation_warning("message", "http://alternate/route");
echo "</br>";
$error = new \stdClass();
$error->code = 444;
$error->message = "test message";
\Rhonda\Error::add_summary_item($error);
\Rhonda\Error::add_summary_item($error);
echo "<pre>";
print_r(\Rhonda\Error::summary());
echo "</pre>";
echo "</br>";
Beispiel #3
0
<h3>\Rhonda\Response</h3>

<?php 
$data = "Will we have success";
\Rhonda\Error::add_summary_item("We show an error");
echo "<pre>";
print_r(\Rhonda\Response::package($data));
echo "</pre>";