Browse Source

Use [] for arrays

Nathaniel van Diepen 7 years ago
parent
commit
f372a3ff05
9 changed files with 40 additions and 50 deletions
  1. 11 11
      app.class.php
  2. 3 5
      base.class.php
  3. 3 3
      dypath.class.php
  4. 5 15
      path.class.php
  5. 2 2
      request.class.php
  6. 4 4
      response.class.php
  7. 5 5
      router.class.php
  8. 5 5
      sql.class.php
  9. 2 0
      uri.class.php

+ 11 - 11
app.class.php

@@ -6,7 +6,7 @@
 	require_once('uri.class.php');
 	require_once('events.interface.php');
 	class App extends Base implements Events {
-		private static $apps = array();
+		private static $apps = [];
 		private $domains;
 		private $routers;
 		private $router;
@@ -14,16 +14,16 @@
 		public function __construct($name, Callable $fn = null){
 			$this->name = $name;
 			$this->router = new Router();
-			$this->routers = array();
-			$this->domains = array();
+			$this->routers = [];
+			$this->domains = [];
 			$this->_onerror = function($req, $res, $error){
-				$o = json_encode(array(
+				$o = json_encode([
 					'message'=>$error->getMessage(),
 					'code'=>$error->getCode(),
 					'file'=>$error->getFile(),
 					'line'=>$error->getLine(),
 					'traceback'=>$error->getTrace()
-				));
+				]);
 				if($res){
 					$res->code(404);
 					$res->header('Content-Type', 'application/json');
@@ -40,7 +40,7 @@
 			}
 		}
 		public function __destruct(){
-			$this->routers = array();
+			$this->routers = [];
 			$index = array_search(static::$apps, $this);
 			if($index !== false){
 				array_splice(static::$apps, $index, 1);
@@ -146,26 +146,26 @@
 		App::shutdown();
 	});
 	set_error_handler(function($errno, $errstr, $errfile, $errline){
-		App::shutdown_error(array(
+		App::shutdown_error([
 			'number'=> $errno,
 			'msg'=> $errstr,
 			'file'=> $errfile,
 			'line'=> $errline,
 			'backtrace'=> debug_backtrace(),
 			'included'=> get_included_files()
-		));
+		]);
 	},E_ALL);
 	register_shutdown_function(function(){
 		$error = error_get_last();
 		if($error['type'] == 1){
-			App::shutdown_error(array(
+			App::shutdown_error([
 				'number'=> $error['type'],
 				'msg'=> $error['message'],
 				'file'=> $error['file'],
 				'line'=> $error['line'],
-				'backtrace'=> array(),
+				'backtrace'=> [],
 				'included'=> get_included_files()
-			));
+			]);
 		}
 	});
 ?>

+ 3 - 5
base.class.php

@@ -2,7 +2,7 @@
 	abstract class Base{
 		private $data;
 		public function __construct(){
-			$this->data = array();
+			$this->data = [];
 			// Constructor
 		}
 		public function __clone(){
@@ -10,7 +10,7 @@
 		}
 		public function __destruct(){
 			// Destroy handler
-			$this->data = array();
+			$this->data = [];
 		}
 		public function __toString(){
 			$name = get_class($this);
@@ -26,9 +26,7 @@
 			return $this;
 		}
 		public function __get($name){
-			if(isset($this->data[$name])){
-				return $this->data[$name];
-			}
+			return $this->data??null;
 		}
 		public function __set($name,$value){
 			if(isset($this->data[$name])){

+ 3 - 3
dypath.class.php

@@ -6,11 +6,11 @@
 			$this->path = $path;
 		}
 		public function jsonSerialize(){
-			return array(
+			return [
 				'path'=>$this->path,
 				'regex'=>$this->regex,
 				'arguments'=>$this->arguments
-			);
+			];
 		}
 		public function __toString(){
 			return $this->path;
@@ -30,7 +30,7 @@
 			return preg_match($this->regex,$url);
 		}
 		public function args($url){
-			$ret = array();
+			$ret = [];
 			preg_match_all($this->regex,$url,$m,PREG_SET_ORDER);
 			foreach($this->arguments as $k => $arg){
 				$ret[$arg[1]] = $m[0][$k+1];

+ 5 - 15
path.class.php

@@ -1,16 +1,16 @@
 <?php
 	require_once('dypath.class.php');
 	class Path implements JsonSerializable{
-		private $handles = array();
+		private $handles = [];
 		public $path;
 		public function __construct($path){
 			$this->path = new DyPath($path);
 		}
-		public function __invoke($res,$args){
+		public function __invoke($req, $res,$args){
 			$err = null;
 			foreach($this->handles as $k => $fn){
 				try{
-					call_user_func($fn, $res, $args, $err);
+					$fn($req, $res, $args, $err);
 				}catch(Exception $e){
 					$err = $e;
 				}
@@ -23,23 +23,13 @@
 			// Nothing to do here
 		}
 		public function jsonSerialize(){
-			return array(
+			return [
 				'dypath'=>$this->path
-			);
+			];
 		}
 		public function __toString(){
 			return "[Path {$this->path}]";
 		}
-		public function __get($name){
-			switch($name){
-				
-			}
-		}
-		public function __set($name,$value){
-			switch($name){
-				
-			}
-		}
 		public function handle(Callable $fn){
 			array_push($this->handles,$fn);
 			return $this;

+ 2 - 2
request.class.php

@@ -3,7 +3,7 @@
 		private $url;
 		private $headers;
 		private $body;
-		public function __construct($url, $headers = array(), $body = ''){
+		public function __construct($url, $headers = [], $body = ''){
 			if(is_string($url) || is_array($url)){
 				$this->url = new Uri($url);
 			}elseif($url instanceof Uri){
@@ -14,7 +14,7 @@
 			if(is_array($headers)){
 				$this->headers = $headers;
 			}else{
-				$this->headers = array();
+				$this->headers = [];
 			}
 			$this->body = $body;
 		}

+ 4 - 4
response.class.php

@@ -3,7 +3,7 @@
 		public $output = '';
 		public $body = '';
 		private $code = 200;
-		public $headers = array();
+		public $headers = [];
 		protected $open = true;
 		public function __construct(){}
 		public function __toString(){
@@ -17,7 +17,7 @@
 		}
 		public function clear_headers(){
 			if($this->open){
-				$this->headers = array();
+				$this->headers = [];
 			}
 			return $this;
 		}
@@ -53,10 +53,10 @@
 			if($this->open){
 				array_push(
 					$this->headers,
-					array(
+					[
 						$name,
 						$value
-					)
+					]
 				);
 			}
 			return $this;

+ 5 - 5
router.class.php

@@ -3,10 +3,10 @@
 	require_once('response.class.php');
 	require_once('request.class.php');
 	class Router {
-		private $_paths = array();
-		private $_routers = array();
+		private $_paths = [];
+		private $_routers = [];
 		private $_base = '/';
-		private $responses = array();
+		private $responses = [];
 		private $_handled = false;
 		public function __construct($base = null, $paths = null){
 			if($paths != null){
@@ -30,7 +30,7 @@
 			// No cloning
 		}
 		public function __destruct(){
-			$this->_paths = array();
+			$this->_paths = [];
 		}
 		public function __toString(){
 			return "[Router]";
@@ -76,7 +76,7 @@
 			}
 		}
 		public function clear(){
-			$this->_paths = array();
+			$this->_paths = [];
 		}
 		public function handle($path, $req = null,$res = null,Callable $fn = null, Callable $onerror = null){
 			if(strpos($path, $this->base) !== false){

+ 5 - 5
sql.class.php

@@ -40,7 +40,7 @@
 		*/
 		public function query(){
 			$reflect = new ReflectionClass('Query');
-			$args = array_merge(array($this),func_get_args());
+			$args = array_merge([$this],func_get_args());
 			return $reflect->newInstanceArgs($args);
 		}
 		public function escape($s){
@@ -65,7 +65,7 @@
 			$this->sql = $sql();
 			$this->query = $sql()->prepare($source);
 			if(!is_null($types)){
-				call_user_func_array(array($this->query, 'bind_param'),make_referenced($args)) or die($sql()->error);
+				call_user_func_array([$this->query, 'bind_param'], make_referenced($args)) or die($sql()->error);
 			}
 		}
 		public function __invoke(){
@@ -116,7 +116,7 @@
 				*/
 				case 'assoc_results':case 'results_assoc':
 					if($this->query){
-						$a = array();
+						$a = [];
 						$r = $this->results;
 						while($row = $r->fetch_assoc()){
 							array_push($a,$row);
@@ -142,7 +142,7 @@
 				*/
 				case 'num_results':case 'results_num':
 					if($this->query){
-						$a = array();
+						$a = [];
 						$r = $this->results;
 						while($row = $r->fetch_num()){
 							array_push($a,$row);
@@ -175,7 +175,7 @@
 		}
 	}
 	function make_referenced(&$arr){
-		$refs = array();
+		$refs = [];
 		foreach($arr as $key => $value){
 			$refs[$key] = &$arr[$key];
 		}

+ 2 - 0
uri.class.php

@@ -35,6 +35,7 @@
 				}elseif($this->scheme = 'https'){
 					$port = $port == 443 ? "" : ":{$port}";
 				}
+				// @todo - add other default port types
 			}
 			$auth = $this->user;
 			if($auth){
@@ -48,6 +49,7 @@
 			if($fragmanet){
 				$fragmanet = "#{$fragmanet}";
 			}
+			// @todo - handle when scheme requires other formats
 			return "{$this->scheme}://{$auth}{$this->host}{$port}{$this->path}{$query}{$fragmanet}";
 		}
 	}