예제 #1
0
파일: helper.php 프로젝트: kennho/router
 public function __construct($route)
 {
     $function = array('class_name' => __NAMESPACE__, 'method_name' => __METHOD__);
     //ensure that route is valid else send error
     if (is_ready($route)) {
         $this->route = $route;
     } else {
         $error = Tool::prepare('Route is invalid, unable to process routing request.', 'Route is null, verify that index router has parsed the information correctly.', __LINE__, $this->route->get_return_type(), Constants::get('default_error_code'));
         Tool::error($function, $error, false);
     }
     try {
         $this->connection = new PDO('mysql:host=' . DatabaseConfig::get('host') . ';dbname=' . DatabaseConfig::get('database'), DatabaseConfig::get('username'), DatabaseConfig::get('password'));
         $exception_mode = Config::get('enable_debugging') == true ? PDO::ERRMODE_EXCEPTION : PDO::ERRMODE_SILENT;
         $this->connection->setAttribute(PDO::ATTR_ERRMODE, $exception_mode);
     } catch (\PDOException $exception) {
         $error = Tool::prepare('Unable to connect to database.', $exception->getMessage(), __LINE__, $this->route->get_return_type(), Constants::get('default_error_code'));
         Tool::error($function, $error, false);
     }
 }
예제 #2
0
파일: tool.php 프로젝트: kennho/router
 public static function error($info, $error, $loggable = false)
 {
     //preset $info('class_name', 'method_name', 'return_type')
     $class_name = set_default($info['class_name'], '');
     $method_name = set_default($info['method_name'], '');
     $return_type = set_default($error['return_type'], Constants::get('default_return_type'));
     //preset $error('message', 'details', 'line', 'error_code')
     $message = set_default($error['message'], 'Unknown Error Occurred.');
     $details = set_default($error['details'], '');
     $line = set_default($error['line'], '');
     $http_status_code = set_default($error['http_status_code'], Constants::get('default_error_code'));
     $error['function'] = str_replace($class_name . '/', '', $method_name);
     Writer::write($http_status_code, $error, Constants::get('error_tag'), $return_type);
     $debuggable = Config::get('enable_debugging');
     if ($debuggable == true) {
     }
     if ($loggable == true) {
     }
     //write to log
     exit;
 }
예제 #3
0
파일: enforcer.php 프로젝트: kennho/router
function enforce_https($return_type = 'json')
{
    $enable_https = Config::get('enable_https');
    if ($enable_https == true) {
        if (validate_https() == false) {
            Writer::write(412, 'Request is not sent securely with https.', Constants::get('error_tag'), $return_type);
        } else {
            return true;
        }
    }
}