Browse Source

* Make PDO->stringColumn use back ticks on the name
* Don't add normal app handlers if JUJU_DISABLE_APP is defined
* CLean up Request::get_url

Nathaniel van Diepen 6 years ago
parent
commit
8554ac24d8
3 changed files with 22 additions and 24 deletions
  1. 2 6
      Http/request.class.php
  2. 19 17
      app.class.php
  3. 1 1
      pdo.class.php

+ 2 - 6
Http/request.class.php

@@ -60,18 +60,14 @@
 			return msgpack_unpack($this->body);
 		}
 		public static function get_url(){
-			if(isset($_SERVER['REDIRECT_URL'])){
-				$url = 'REDIRECT_URL';
-			}else{
-				$url = 'REQUEST_URI';
-			}
+			$url = $_SERVER['REDIRECT_URL'] ?? $_SERVER['REQUEST_URI'];
 			if(!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])){
 				$root = $_SERVER['HTTP_X_FORWARDED_PROTO'].'://';
 			}else{
 				$root = !empty($_SERVER['HTTPS']) ? "https://" : "http://";
 			}
 			// @todo - determine if http or http and also check cloudflare
-			return parse_url($root.$_SERVER['HTTP_HOST'].$_SERVER[$url]);
+			return parse_url($root.$_SERVER['HTTP_HOST'].$url);
 		}
 		public static function get_headers(){
 			return getallheaders();

+ 19 - 17
app.class.php

@@ -1,10 +1,10 @@
 <?php
 	namespace Juju;
+	use \Juju\{App\Controller, App\Exception, App\Router, Http\Response, Http\Request};
 	require_once('base.abstract.class.php');
 	require_once('App/router.class.php');
 	require_once('App/exception.class.php');
 	require_once('App/controller.abstract.class.php');
-	use \Juju\{App\Controller, App\Exception, App\Router, Http\Response, Http\Request};
 
 	class App extends Base {
 		use Events;
@@ -231,22 +231,24 @@
 			return $this;
 		}
 	}
-	set_exception_handler(function($error){
-		App::shutdown_error($error);
-	});
-	set_error_handler(function($errno, $errstr, $errfile, $errline){
-		// ignore warnings
-		if($errno &~ E_WARNING){
-			App::shutdown_error(new Exception($errstr, $errno, null, $errfile, $errline, debug_backtrace()));
-			die();
-		}
-	}, E_ALL);
-	register_shutdown_function(function(){
+	if(!defined('JUJU_DISABLE_APP')){
+		set_exception_handler(function($error){
+			App::shutdown_error($error);
+		});
+		set_error_handler(function($errno, $errstr, $errfile, $errline){
+			// ignore warnings
+			if($errno &~ E_WARNING){
+				App::shutdown_error(new Exception($errstr, $errno, null, $errfile, $errline, debug_backtrace()));
+				die();
+			}
+		}, E_ALL);
+		register_shutdown_function(function(){
+			error_reporting(E_ALL &~ E_WARNING);
+			ini_set('display_errors', 'Off');
+			App::shutdown();
+		});
 		error_reporting(E_ALL &~ E_WARNING);
 		ini_set('display_errors', 'Off');
-		App::shutdown();
-	});
-	error_reporting(E_ALL &~ E_WARNING);
-	ini_set('display_errors', 'Off');
-	gc_enable();
+		gc_enable();
+	}
 ?>

+ 1 - 1
pdo.class.php

@@ -198,7 +198,7 @@
 			}
 			$null = $column['null'] ? ' NULL' : ' NOT NULL';
 			$ai = $column['increment'] ? ' AUTO_INCREMENT' : '';
-			return "{$name} {$column['type']}{$null}{$default}{$ai}";
+			return "`{$name}` {$column['type']}{$null}{$default}{$ai}";
 		}
 		public function stringIndex(string $name, array $idx){
 			if($idx['unique']){