Beispiel #1
0
 function test()
 {
     global $argv;
     $url = $argv[3];
     $testcase = $argv[4];
     $testcase = str_replace("application/", "", $testcase);
     $testcase = str_replace("/", "\\", $testcase);
     $testcase = str_replace(".php", "", $testcase);
     $test = new $testcase();
     $test->setServer($url);
     $exitcode = 0;
     $refl = new ReflectionClass($test);
     foreach ($refl->getMethods() as $method) {
         if (strpos($method->name, "test_") === 0) {
             try {
                 $test->setTestNamePrefix($method->name . " - ");
                 $test->init();
                 $test->{$method->name}();
                 $test->cleanup();
             } catch (\Exception $e) {
                 echo "not ok - uncaught exception in {$testcase}->{$method->name}\n";
                 \libraries\ExceptionHandler::exception_handler($e);
                 $exitcode = 255;
             }
         }
     }
     if ($exitcode == 0) {
         $test->done_testing();
     } else {
         exit($exitcode);
     }
 }
Beispiel #2
0
 public function route()
 {
     try {
         $requested_version = $this->uri->segment(2);
         $controller = $this->uri->segment(3);
         $function = $this->uri->segment(4);
         if (!preg_match("/^v([0-9]+)(.[0-9]+){0,2}\$/", $requested_version)) {
             throw new \exceptions\PublicApiException("api/invalid-version", "Invalid API version requested");
         }
         $requested_version = substr($requested_version, 1);
         $major = intval(explode(".", $requested_version)[0]);
         if (!preg_match("/^[a-zA-Z-_]+\$/", $controller)) {
             throw new \exceptions\PublicApiException("api/invalid-endpoint", "Invalid endpoint requested");
         }
         if (!preg_match("/^[a-zA-Z-_]+\$/", $function)) {
             throw new \exceptions\PublicApiException("api/invalid-endpoint", "Invalid endpoint requested");
         }
         $namespace = "controllers\\api\\v" . $major;
         $class = $namespace . "\\" . $controller;
         $class_info = $namespace . "\\api_info";
         if (!class_exists($class_info) || version_compare($class_info::get_version(), $requested_version, "<")) {
             throw new \exceptions\PublicApiException("api/version-not-supported", "Requested API version is not supported");
         }
         if (!class_exists($class)) {
             throw new \exceptions\PublicApiException("api/unknown-endpoint", "Unknown endpoint requested");
         }
         $c = new $class();
         if (!method_exists($c, $function)) {
             throw new \exceptions\PublicApiException("api/unknown-endpoint", "Unknown endpoint requested");
         }
         return send_json_reply($c->{$function}());
     } catch (\exceptions\PublicApiException $e) {
         return send_json_error_reply($e->get_error_id(), $e->getMessage(), $e->get_data());
     } catch (\Exception $e) {
         \libraries\ExceptionHandler::log_exception($e);
         return send_json_error_reply("internal-error", "An unhandled internal server error occured");
     }
 }
Beispiel #3
0
function _exception_handler($severity, $message, $filepath, $line)
{
    return \libraries\ExceptionHandler::error_handler($severity, $message, $filepath, $line);
}