Completed
Push — master ( 9ad54b...895d73 )
by Federico
03:21
created
dist/jate/modules/Query/Query.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -7,42 +7,42 @@
 block discarded – undo
7 7
 			$this->connection = [];
8 8
 			$this->currentConnection = null;
9 9
 		}
10
-		public function addConnection( $_name, $_connection ) {
10
+		public function addConnection($_name, $_connection) {
11 11
 			$this->connection["$_name"] = $_connection;
12 12
 			$this->currentConnection = $_connection;
13 13
 
14 14
 			foreach ($this->modules as &$module)
15
-				if(isset($module->currentConnection))
15
+				if (isset($module->currentConnection))
16 16
 					$module->addConnection($_name, $_connection);
17 17
 		}
18
-		public function setConnection( $_name ) {
18
+		public function setConnection($_name) {
19 19
 			$this->currentConnection = $this->connection["$_name"];
20 20
 		}
21
-		public function query( $_query ) {
21
+		public function query($_query) {
22 22
 			$this->stdQuery($_query);
23 23
 			return true;
24 24
 		}
25
-		public function queryInsert( $_query ) {
25
+		public function queryInsert($_query) {
26 26
 			$temp = $this->stdQuery($_query);
27 27
 			return $this->currentConnection->database->lastInsertId();
28 28
 		}
29 29
 
30
-		public function queryFetch( $_query ) {
30
+		public function queryFetch($_query) {
31 31
 			$temp = $this->stdQuery($_query);
32 32
 			return $temp->fetchAll(PDO::FETCH_ASSOC);
33 33
 		}
34 34
 
35
-		public function queryArray( $_query ) {
35
+		public function queryArray($_query) {
36 36
 			$temp = $this->stdQuery($_query);
37 37
 			return $temp->fetchAll(PDO::FETCH_COLUMN, 0);
38 38
 		}
39 39
 
40
-		protected function stdQuery( $_query ) {
40
+		protected function stdQuery($_query) {
41 41
 			$database = $this->currentConnection->database;
42 42
 			$error = "Error query [$_query]";
43 43
 			$query = $database->prepare($_query);
44 44
 			$_result = $query->execute();
45
-			if(!$_result) {
45
+			if (!$_result) {
46 46
 				echo "$_query<br>";
47 47
 				echo "Something wrong: $error";
48 48
 				var_dump($query->errorInfo());
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,9 +11,10 @@
 block discarded – undo
11 11
 			$this->connection["$_name"] = $_connection;
12 12
 			$this->currentConnection = $_connection;
13 13
 
14
-			foreach ($this->modules as &$module)
15
-				if(isset($module->currentConnection))
14
+			foreach ($this->modules as &$module) {
15
+							if(isset($module->currentConnection))
16 16
 					$module->addConnection($_name, $_connection);
17
+			}
17 18
 		}
18 19
 		public function setConnection( $_name ) {
19 20
 			$this->currentConnection = $this->connection["$_name"];
Please login to merge, or discard this patch.
dist/jate/modules/JConfig/JConfig.php 2 patches
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,10 +17,11 @@  discard block
 block discarded – undo
17 17
 		public function import( $_path, $_type = "misc" ) {
18 18
 			$data = file_get_contents($_path);
19 19
 			$data = json_decode($data);
20
-			if( $_type == "connection" )
21
-				$this->overlayConnection($data);
22
-			else
23
-				$this->overlayMisc($data);
20
+			if( $_type == "connection" ) {
21
+							$this->overlayConnection($data);
22
+			} else {
23
+							$this->overlayMisc($data);
24
+			}
24 25
 		}
25 26
 		protected function overlayConnection( $_data ) {
26 27
 			$this->connection = $this->obj2array($_data);
@@ -40,8 +41,9 @@  discard block
 block discarded – undo
40 41
 			return $return;
41 42
 		}
42 43
 		protected function importObject( $_object ) {
43
-			foreach (get_object_vars($_object) as $key => $value)
44
-				$this->$key = $value;
44
+			foreach (get_object_vars($_object) as $key => $value) {
45
+							$this->$key = $value;
46
+			}
45 47
 		}
46 48
 	}
47 49
 ?>
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -6,45 +6,45 @@
 block discarded – undo
6 6
 		public $pages;
7 7
 		public $server;
8 8
 		public function __construct() {
9
-			$this->connection["enable"]		= false;
10
-			$this->connection["user"]			= "";
9
+			$this->connection["enable"] = false;
10
+			$this->connection["user"] = "";
11 11
 			$this->connection["password"] = "";
12 12
 			$this->connection["database"] = "";
13
-			$this->connection["server"]		= "";
14
-			$this->all		= "";
13
+			$this->connection["server"] = "";
14
+			$this->all = "";
15 15
 			$this->DEBUG	= 0;
16 16
 			$this->pages	= [];
17
-			$this->server	= [];
17
+			$this->server = [];
18 18
 			$this->server["HTTP_HOST"]		= $_SERVER["HTTP_HOST"];
19
-			$this->server["REQUEST_URI"]	= $_SERVER["REQUEST_URI"];
19
+			$this->server["REQUEST_URI"] = $_SERVER["REQUEST_URI"];
20 20
 			$this->server["PHP_SELF"]			= $_SERVER["PHP_SELF"];
21 21
 		}
22
-		public function import( $_path, $_type = "misc" ) {
22
+		public function import($_path, $_type = "misc") {
23 23
 			$data = file_get_contents($_path);
24 24
 			$data = json_decode($data);
25
-			if( $_type == "connection" )
25
+			if ($_type == "connection")
26 26
 				$this->overlayConnection($data);
27 27
 			else
28 28
 				$this->overlayMisc($data);
29 29
 		}
30
-		protected function overlayConnection( $_data ) {
30
+		protected function overlayConnection($_data) {
31 31
 			$this->connection = $this->obj2array($_data);
32 32
 		}
33
-		protected function overlayMisc( $_data ) {
33
+		protected function overlayMisc($_data) {
34 34
 			$this->importObject($_data);
35 35
 		}
36
-		protected function obj2array ( &$_instance ) {
37
-			$clone	= (array) $_instance;
36
+		protected function obj2array(&$_instance) {
37
+			$clone = (array) $_instance;
38 38
 			$return	= [];
39 39
 			$return['___SOURCE_KEYS_'] = $clone;
40
-			while ( list ($key, $value) = each ($clone) ) {
41
-				$temp		= explode ("\0", $key);
42
-				$newkey	= $temp[count($temp)-1];
40
+			while (list ($key, $value) = each($clone)) {
41
+				$temp		= explode("\0", $key);
42
+				$newkey = $temp[count($temp) - 1];
43 43
 				$return[$newkey] = &$return['___SOURCE_KEYS_'][$key];
44 44
 			}
45 45
 			return $return;
46 46
 		}
47
-		protected function importObject( $_object ) {
47
+		protected function importObject($_object) {
48 48
 			foreach (get_object_vars($_object) as $key => $value)
49 49
 				$this->$key = $value;
50 50
 		}
Please login to merge, or discard this patch.
dist/jate/functions/git.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@
 block discarded – undo
1 1
 <?php
2
-	function getGitLog( $_dir = "./" ) {
3
-		if(!file_exists($_dir))
2
+	function getGitLog($_dir = "./") {
3
+		if (!file_exists($_dir))
4 4
 			return [];
5 5
 		$currentDir = getcwd();
6 6
 		chdir($_dir);
7 7
 		$gitHistory	= [];
8 8
 		$gitLogs		= [];
9 9
 		$gitPath		= str_replace('\\', '/', exec("git rev-parse --show-toplevel"));
10
-		$rootPath		= str_replace('\\', '/', getcwd ());
10
+		$rootPath		= str_replace('\\', '/', getcwd());
11 11
 		$lastHash		= null;
12
-		if( $gitPath != $rootPath ) {
12
+		if ($gitPath != $rootPath) {
13 13
 			chdir($currentDir);
14 14
 			return [];
15 15
 		}
Please login to merge, or discard this patch.
Braces   +7 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,7 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 	function getGitLog( $_dir = "./" ) {
3
-		if(!file_exists($_dir))
4
-			return [];
3
+		if(!file_exists($_dir)) {
4
+					return [];
5
+		}
5 6
 		$currentDir = getcwd();
6 7
 		chdir($_dir);
7 8
 		$gitHistory	= [];
@@ -35,19 +36,17 @@  discard block
 block discarded – undo
35 36
 						$tag = trim($tag[0]);
36 37
 						$gitHistory[$lastHash]['tag'] = $tag;
37 38
 					}
38
-				}
39
-				else if (strpos($line, 'Author') === 0) {
39
+				} else if (strpos($line, 'Author') === 0) {
40 40
 					$author = explode(':', $line);
41 41
 					$author = trim(end($author));
42 42
 					$gitHistory[$lastHash]['author'] = $author;
43
-				}
44
-				else if (strpos($line, 'Date') === 0) {
43
+				} else if (strpos($line, 'Date') === 0) {
45 44
 					$date = explode(':', $line, 2);
46 45
 					$date = trim(end($date));
47 46
 					$gitHistory[$lastHash]['date'] = date('d/m/Y H:i:s A', strtotime($date));
47
+				} else {
48
+									$gitHistory[$lastHash]['message'] .= "$line<br>";
48 49
 				}
49
-				else
50
-					$gitHistory[$lastHash]['message'] .= "$line<br>";
51 50
 			}
52 51
 		}
53 52
 		chdir($currentDir);
Please login to merge, or discard this patch.
dist/jate/modules/Html/Html.php 2 patches
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,17 +26,20 @@
 block discarded – undo
26 26
 			$this->tags["js"]				= array_unique($this->tags["js"]);
27 27
 			$this->tags["pagePath"]	= json_encode($this->tags["pagePath"]);
28 28
 			$tempStr = "";
29
-			foreach ($this->tags["css"] as $i)
30
-				$tempStr .= "<link rel='stylesheet' href='$i'>";
29
+			foreach ($this->tags["css"] as $i) {
30
+							$tempStr .= "<link rel='stylesheet' href='$i'>";
31
+			}
31 32
 			$this->tags["css"] = $tempStr;
32 33
 			$tempStr = "";
33
-			foreach ($this->tags["js"] as $i)
34
-				$tempStr .= "<script src='$i'></script>";
34
+			foreach ($this->tags["js"] as $i) {
35
+							$tempStr .= "<script src='$i'></script>";
36
+			}
35 37
 			$this->tags["js"] = $tempStr;
36 38
 			$tempStr = "";
37 39
 			$tempStr .= "<script type='text/javascript'>";
38
-			foreach ($this->tags["jsVariables"] as $i)
39
-				$tempStr .= " $i[0] = $i[1];\n";
40
+			foreach ($this->tags["jsVariables"] as $i) {
41
+							$tempStr .= " $i[0] = $i[1];\n";
42
+			}
40 43
 			$tempStr .= "</script>";
41 44
 			$this->tags["jsVariables"] = $tempStr;
42 45
 		}
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,32 +1,32 @@
 block discarded – undo
1 1
 <?php
2 2
 	requireComponent("../Query/Query.php");
3 3
 	class Html extends Query {
4
-		public function __construct( $_parameters = [ "app" => null, "page" => null] ) {
4
+		public function __construct($_parameters = ["app" => null, "page" => null]) {
5 5
 			parent::__construct();
6 6
 			$this->data["template"]					= "";
7 7
 			$this->tags["brand"]						= "";
8 8
 			$this->tags["brandImg"]					= "";
9 9
 			$this->tags["menu"]							= "";
10 10
 			$this->tags["title"]						= "";
11
-			$this->tags["subtitle"]		 			= "";
11
+			$this->tags["subtitle"] = "";
12 12
 			$this->tags["content"]				 	= "";
13
-			$this->tags["outContent"]		 		= "";
13
+			$this->tags["outContent"] = "";
14 14
 			$this->tags["footer"]		 				= "";
15 15
 			$this->tags["pagePath"]				 	= [];
16
-			$this->tags["css"]							= [];
17
-			$this->tags["js"]					 			= [];
16
+			$this->tags["css"] = [];
17
+			$this->tags["js"] = [];
18 18
 			$this->tags["jsVariables"]			= [];
19
-			$this->tags["metaDescription"]	= [];
20
-			$this->tags["metaKeywords"]			= [];
19
+			$this->tags["metaDescription"] = [];
20
+			$this->tags["metaKeywords"] = [];
21 21
 			$this->tags["metaAuthor"]				= [];
22
-			$this->parameters								= $_parameters;
23
-			$this->tags["base"]							= $_parameters["app"]->server["RELATIVE"]."/";
22
+			$this->parameters = $_parameters;
23
+			$this->tags["base"] = $_parameters["app"]->server["RELATIVE"]."/";
24 24
 		}
25 25
 		public function uniforma() {
26 26
 			$this->addDipendences();
27 27
 			$this->tags["css"]			= array_unique($this->tags["css"]);
28 28
 			$this->tags["js"]				= array_unique($this->tags["js"]);
29
-			$this->tags["pagePath"]	= json_encode($this->tags["pagePath"]);
29
+			$this->tags["pagePath"] = json_encode($this->tags["pagePath"]);
30 30
 			$tempStr = "";
31 31
 			foreach ($this->tags["css"] as $i)
32 32
 				$tempStr .= "<link rel='stylesheet' href='$i'>";
Please login to merge, or discard this patch.
dist/jate/modules/WebApp/WebApp.php 2 patches
Braces   +20 added lines, -14 removed lines patch added patch discarded remove patch
@@ -18,8 +18,9 @@  discard block
 block discarded – undo
18 18
 			if(is_array($_page)) {
19 19
 				$path		= $_page[0];
20 20
 				$class	= $_page[1];
21
-				if(isset($_page[2]))
22
-					$param = $_page[2];
21
+				if(isset($_page[2])) {
22
+									$param = $_page[2];
23
+				}
23 24
 			} else {
24 25
 				$path		= $_page;
25 26
 				$class	= $_page;
@@ -27,8 +28,9 @@  discard block
 block discarded – undo
27 28
 			$this->pages[$path] = [$class,$param];
28 29
 		}
29 30
 		public function addPages( $_pages ) {
30
-			foreach ($_pages as $i)
31
-				$this->addPage($i);
31
+			foreach ($_pages as $i) {
32
+							$this->addPage($i);
33
+			}
32 34
 		}
33 35
 		public function fetchPage( $_stack ) {
34 36
 			$parameters = [];
@@ -42,10 +44,11 @@  discard block
 block discarded – undo
42 44
 					break;
43 45
 				}
44 46
 			}
45
-			if( isset($temp[1]) && is_array($temp[1]) )
46
-				$temp[1] = array_merge($temp[1], $parameters);
47
-			else
48
-				$temp[1] = $parameters;
47
+			if( isset($temp[1]) && is_array($temp[1]) ) {
48
+							$temp[1] = array_merge($temp[1], $parameters);
49
+			} else {
50
+							$temp[1] = $parameters;
51
+			}
49 52
 			$this->currentPage = new $temp[0](["app" => $this->jConfig, "page" => $temp[1]]);
50 53
 			return $this->currentPage;
51 54
 		}
@@ -65,15 +68,18 @@  discard block
 block discarded – undo
65 68
 			$pathLength = count($_path);
66 69
 			if($urlLength == $pathLength) {
67 70
 				while($cont < $urlLength) {
68
-					if( $_path[$cont] == $_url[$cont] )
69
-						$cont++;
70
-					else if( strpos($_path[$cont], "\$") !== false ) {
71
+					if( $_path[$cont] == $_url[$cont] ) {
72
+											$cont++;
73
+					} else if( strpos($_path[$cont], "\$") !== false ) {
71 74
 						$variables[str_replace('$', "", $_path[$cont])] = $_url[$cont];
72 75
 						$cont++;
73
-					} else break;
76
+					} else {
77
+						break;
78
+					}
79
+				}
80
+				if($cont == $urlLength) {
81
+									return $variables;
74 82
 				}
75
-				if($cont == $urlLength)
76
-					return $variables;
77 83
 			}
78 84
 			return null;
79 85
 		}
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -7,48 +7,48 @@  discard block
 block discarded – undo
7 7
 		public function __construct() {
8 8
 			parent::__construct();
9 9
 			$this->pages = [];
10
-			$this->defaultPage	= ["Page404",[]];
10
+			$this->defaultPage	= ["Page404", []];
11 11
 			$this->currentPage	= null;
12
-			$this->jConfig			= null;
12
+			$this->jConfig = null;
13 13
 		}
14
-		public function addPage( $_page ) {
14
+		public function addPage($_page) {
15 15
 			$param	= [];
16 16
 			$path		= $_page;
17 17
 			$class	= $_page;
18
-			if(is_array($_page)) {
18
+			if (is_array($_page)) {
19 19
 				$path		= $_page[0];
20 20
 				$class	= $_page[1];
21
-				if(isset($_page[2]))
21
+				if (isset($_page[2]))
22 22
 					$param = $_page[2];
23 23
 			}
24 24
 			$this->pages[$path] = [$class, $param];
25 25
 		}
26
-		public function addPages( $_pages ) {
26
+		public function addPages($_pages) {
27 27
 			foreach ($_pages as $i)
28 28
 				$this->addPage($i);
29 29
 		}
30 30
 		public function fetchPage(  ) {
31 31
 			$router = new Router();
32
-			$router->parameters = [ "app" => &$this->jConfig, "page" => null];
32
+			$router->parameters = ["app" => &$this->jConfig, "page" => null];
33 33
 			$stack = $router->getPage();
34 34
 			$parameters = [];
35
-			$temp				= $this->defaultPage;
35
+			$temp = $this->defaultPage;
36 36
 			foreach ($this->pages as $key => $value) {
37 37
 				$variables = $this->pathSeeker(explode("/", $key), $stack);
38
-				if(is_array($variables)) {
38
+				if (is_array($variables)) {
39 39
 					$temp = $value;
40 40
 					$parameters = $variables;
41 41
 					break;
42 42
 				}
43 43
 			}
44
-			if( isset($temp[1]) && is_array($temp[1]) )
44
+			if (isset($temp[1]) && is_array($temp[1]))
45 45
 				$temp[1] = array_merge($temp[1], $parameters);
46 46
 			else
47 47
 				$temp[1] = $parameters;
48 48
 			$this->currentPage = new $temp[0](["app" => $this->jConfig, "page" => $temp[1]]);
49 49
 			return $this->currentPage;
50 50
 		}
51
-		public function setDefaultPage( $_page ) {
51
+		public function setDefaultPage($_page) {
52 52
 			$this->defaultPage = $_page;
53 53
 		}
54 54
 		public function draw() {
@@ -57,28 +57,28 @@  discard block
 block discarded – undo
57 57
 			$gui->init($this->currentPage);
58 58
 			$gui->draw($this->currentPage->data["template"]);
59 59
 		}
60
-		public function pathSeeker( $_path, $_url ) {
60
+		public function pathSeeker($_path, $_url) {
61 61
 			$urlLength = count($_url);
62 62
 			$cont = 0;
63 63
 			$variables = [];
64 64
 			$pathLength = count($_path);
65
-			if($urlLength == $pathLength) {
66
-				while($cont < $urlLength) {
67
-					if( $_path[$cont] == $_url[$cont] )
65
+			if ($urlLength == $pathLength) {
66
+				while ($cont < $urlLength) {
67
+					if ($_path[$cont] == $_url[$cont])
68 68
 						$cont++;
69
-					else if( strpos($_path[$cont], "\$") !== false ) {
69
+					else if (strpos($_path[$cont], "\$") !== false) {
70 70
 						$variables[str_replace('$', "", $_path[$cont])] = $_url[$cont];
71 71
 						$cont++;
72 72
 					} else break;
73 73
 				}
74
-				if($cont == $urlLength)
74
+				if ($cont == $urlLength)
75 75
 					return $variables;
76 76
 			}
77 77
 			return null;
78 78
 		}
79
-		public function newConfig( $_path = "config/") {
79
+		public function newConfig($_path = "config/") {
80 80
 			$this->jConfig = new JConfig();
81
-			$this->jConfig->import("${_path}connection.json","connection");
81
+			$this->jConfig->import("${_path}connection.json", "connection");
82 82
 			$this->jConfig->import("${_path}misc.json");
83 83
 			$this->jConfig->import("${_path}router.json");
84 84
 		}
Please login to merge, or discard this patch.
dist/jate/modules/Router/Router.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 			parent::__construct();
5 5
 		}
6 6
 		public function getPage() {
7
-			$request	= $this->parameters["app"]->server["REQUEST_URI"];
8
-			$base			= $this->parameters["app"]->server["RELATIVE"];
7
+			$request = $this->parameters["app"]->server["REQUEST_URI"];
8
+			$base = $this->parameters["app"]->server["RELATIVE"];
9 9
 			$url			= str_replace($base, "", $request);
10 10
 			$url			= explode("/", $url);
11 11
 			return $url;
Please login to merge, or discard this patch.
dist/jate/modules/Menu/Menu.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -8,13 +8,13 @@  discard block
 block discarded – undo
8 8
 			$menu = $this->queryFetch("SELECT * FROM menu WHERE flag_active = 1 ORDER BY `order`");
9 9
 			$temp = [];
10 10
 			foreach ($menu as $i) {
11
-				if($i["fk_menu"] == 0) {
11
+				if ($i["fk_menu"] == 0) {
12 12
 					$pk_menu = $i["pk_menu"];
13 13
 					array_push($temp, array("label" => $i["label"], "link" => $i["link"], "submenu" => [], "relative" => false));
14 14
 					$submenu = $this->queryFetch("SELECT * FROM menu WHERE fk_menu = $pk_menu ORDER BY `order`");
15
-					if($submenu)
15
+					if ($submenu)
16 16
 					foreach ($submenu as $j)
17
-						array_push( $temp[count($temp)-1]["submenu"], array("label" => $j["label"], "link" => $j["link"], "submenu" => [], "relative" => false) );
17
+						array_push($temp[count($temp) - 1]["submenu"], array("label" => $j["label"], "link" => $j["link"], "submenu" => [], "relative" => false));
18 18
 				}
19 19
 			}
20 20
 			$this->tags["menu"] = $temp;
@@ -23,15 +23,15 @@  discard block
 block discarded – undo
23 23
 		public function draw() {
24 24
 			$temp = "";
25 25
 			$host = $this->parameters["app"]->server["HTTP_HOST"];
26
-			$uri	= $this->parameters["app"]->server["REQUEST_URI"];
27
-			$actualLink	= "http://$host$uri";
28
-			$relative		= $this->parameters["app"]->server["RELATIVE"];
26
+			$uri = $this->parameters["app"]->server["REQUEST_URI"];
27
+			$actualLink = "http://$host$uri";
28
+			$relative = $this->parameters["app"]->server["RELATIVE"];
29 29
 			foreach ($this->tags["menu"] as $i) {
30 30
 				$prePath = "";
31
-				if($i["relative"])
31
+				if ($i["relative"])
32 32
 					$prePath = $relative;
33 33
 				$active = $this->isSubString($actualLink, array_merge(array_column($i["submenu"], 'link'), array($i["link"]))) ? "active" : "";
34
-				if( is_array($i["submenu"]) && count($i["submenu"])<1)
34
+				if (is_array($i["submenu"]) && count($i["submenu"]) < 1)
35 35
 						$temp .= "<li class='$active'><a href='$prePath$i[link]'>$i[label]</a></li>";
36 36
 				else {
37 37
 					$temp .= "<li class='dropdown $active'>";
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 						'<ul class="dropdown-menu">';
44 44
 					foreach ($i["submenu"] as $j) {
45 45
 						$prePath = "";
46
-						if($j["relative"])
46
+						if ($j["relative"])
47 47
 							$prePath = $relative;
48 48
 						$temp .= "<li><a href='$prePath$j[link]'>$j[label]</a></li>";
49 49
 					}
@@ -52,18 +52,18 @@  discard block
 block discarded – undo
52 52
 			}
53 53
 			return $temp;
54 54
 		}
55
-		protected function isSubString( $_string, $_list) {
55
+		protected function isSubString($_string, $_list) {
56 56
 			$success = false;
57 57
 			foreach ($_list as $i)
58
-				if(strpos($_string,$i) !== false)
58
+				if (strpos($_string, $i) !== false)
59 59
 					$success = true;
60 60
 			return $success;
61 61
 		}
62 62
 		public function loginWithUser() {
63 63
 			$this->init();
64 64
 			$temp = [];
65
-			if(!isset($_SESSION["username"]))
66
-				$_SESSION["username"] ="guest";
65
+			if (!isset($_SESSION["username"]))
66
+				$_SESSION["username"] = "guest";
67 67
 			$user = $_SESSION["username"];
68 68
 			$blackList = $this->queryFetch(
69 69
 				"SELECT user.*,user_section.*
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
 				$success = true;
79 79
 				$k = $i["label"];
80 80
 				foreach ($blackList as $j)
81
-					if( $j["section"] == $k)
81
+					if ($j["section"] == $k)
82 82
 						$success = false;
83
-				if($success)
84
-					array_push($temp,$i);
83
+				if ($success)
84
+					array_push($temp, $i);
85 85
 			}
86 86
 			$this->tags["menu"] = $temp;
87 87
 		}
Please login to merge, or discard this patch.
Braces   +24 added lines, -17 removed lines patch added patch discarded remove patch
@@ -12,9 +12,10 @@  discard block
 block discarded – undo
12 12
 					$pk_menu = $i["pk_menu"];
13 13
 					array_push($temp, array("label" => $i["label"], "link" => $i["link"], "submenu" => [], "relative" => false));
14 14
 					$submenu = $this->queryFetch("SELECT * FROM menu WHERE fk_menu = $pk_menu ORDER BY `order`");
15
-					if($submenu)
16
-					foreach ($submenu as $j)
15
+					if($submenu) {
16
+										foreach ($submenu as $j)
17 17
 						array_push( $temp[count($temp)-1]["submenu"], array("label" => $j["label"], "link" => $j["link"], "submenu" => [], "relative" => false) );
18
+					}
18 19
 				}
19 20
 			}
20 21
 			$this->tags["menu"] = $temp;
@@ -28,12 +29,13 @@  discard block
 block discarded – undo
28 29
 			$relative		= $this->parameters["app"]->server["RELATIVE"];
29 30
 			foreach ($this->tags["menu"] as $i) {
30 31
 				$prePath = "";
31
-				if($i["relative"])
32
-					$prePath = $relative;
32
+				if($i["relative"]) {
33
+									$prePath = $relative;
34
+				}
33 35
 				$active = $this->isSubString($actualLink, array_merge(array_column($i["submenu"], 'link'), array($i["link"]))) ? "active" : "";
34
-				if( is_array($i["submenu"]) && count($i["submenu"])<1)
35
-						$temp .= "<li class='$active'><a href='$prePath$i[link]'>$i[label]</a></li>";
36
-				else {
36
+				if( is_array($i["submenu"]) && count($i["submenu"])<1) {
37
+										$temp .= "<li class='$active'><a href='$prePath$i[link]'>$i[label]</a></li>";
38
+				} else {
37 39
 					$temp .= "<li class='dropdown $active'>";
38 40
 					$temp .=
39 41
 						'<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">'.
@@ -43,8 +45,9 @@  discard block
 block discarded – undo
43 45
 						'<ul class="dropdown-menu">';
44 46
 					foreach ($i["submenu"] as $j) {
45 47
 						$prePath = "";
46
-						if($j["relative"])
47
-							$prePath = $relative;
48
+						if($j["relative"]) {
49
+													$prePath = $relative;
50
+						}
48 51
 						$temp .= "<li><a href='$prePath$j[link]'>$j[label]</a></li>";
49 52
 					}
50 53
 					$temp .= "</ul></li>";
@@ -54,16 +57,18 @@  discard block
 block discarded – undo
54 57
 		}
55 58
 		protected function isSubString( $_string, $_list) {
56 59
 			$success = false;
57
-			foreach ($_list as $i)
58
-				if(strpos($_string,$i) !== false)
60
+			foreach ($_list as $i) {
61
+							if(strpos($_string,$i) !== false)
59 62
 					$success = true;
63
+			}
60 64
 			return $success;
61 65
 		}
62 66
 		public function loginWithUser() {
63 67
 			$this->init();
64 68
 			$temp = [];
65
-			if(!isset($_SESSION["username"]))
66
-				$_SESSION["username"] ="guest";
69
+			if(!isset($_SESSION["username"])) {
70
+							$_SESSION["username"] ="guest";
71
+			}
67 72
 			$user = $_SESSION["username"];
68 73
 			$blackList = $this->queryFetch(
69 74
 				"SELECT user.*,user_section.*
@@ -77,11 +82,13 @@  discard block
 block discarded – undo
77 82
 			foreach ($this->tags["menu"] as $i) {
78 83
 				$success = true;
79 84
 				$k = $i["label"];
80
-				foreach ($blackList as $j)
81
-					if( $j["section"] == $k)
85
+				foreach ($blackList as $j) {
86
+									if( $j["section"] == $k)
82 87
 						$success = false;
83
-				if($success)
84
-					array_push($temp,$i);
88
+				}
89
+				if($success) {
90
+									array_push($temp,$i);
91
+				}
85 92
 			}
86 93
 			$this->tags["menu"] = $temp;
87 94
 		}
Please login to merge, or discard this patch.
dist/jate/modules/GUI/GUI.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -4,14 +4,14 @@  discard block
 block discarded – undo
4 4
 		public function __construct() {
5 5
 			parent::__construct();
6 6
 		}
7
-		public function init( $_page ) {
7
+		public function init($_page) {
8 8
 			$this->tags = $_page->tags;
9 9
 		}
10
-		public function draw( $_template ) {
10
+		public function draw($_template) {
11 11
 			$page = "";
12
-			$extension = explode(".",$_template);
13
-			$extension = $extension[count($extension)-1];
14
-			if($extension == "pug" || $extension == "jade") {
12
+			$extension = explode(".", $_template);
13
+			$extension = $extension[count($extension) - 1];
14
+			if ($extension == "pug" || $extension == "jade") {
15 15
 				$pug = new Pug\Pug();
16 16
 				$page = $pug->render($_template);
17 17
 			} else
@@ -19,9 +19,9 @@  discard block
 block discarded – undo
19 19
 			$render = $this->overlayTag($page);
20 20
 			echo minifyOutput($render);
21 21
 		}
22
-		protected function overlayTag( $_page ) {
23
-			foreach($this->tags as $key => $value)
24
-				if(!is_array($value))
22
+		protected function overlayTag($_page) {
23
+			foreach ($this->tags as $key => $value)
24
+				if (!is_array($value))
25 25
 					$_page = str_replace("<_${key}_>", "$value", $_page);
26 26
 			return $_page;
27 27
 		}
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -14,15 +14,17 @@
 block discarded – undo
14 14
 			if($extension == "pug" || $extension == "jade") {
15 15
 				$pug = new Pug\Pug();
16 16
 				$page = $pug->render($_template);
17
-			} else
18
-				$page = file_get_contents($_template);
17
+			} else {
18
+							$page = file_get_contents($_template);
19
+			}
19 20
 			$render = $this->overlayTag($page);
20 21
 			echo minifyOutput($render);
21 22
 		}
22 23
 		protected function overlayTag( $_page ) {
23
-			foreach($this->tags as $key => $value)
24
-				if(!is_array($value))
24
+			foreach($this->tags as $key => $value) {
25
+							if(!is_array($value))
25 26
 					$_page = str_replace("<_${key}_>", "$value", $_page);
27
+			}
26 28
 			return $_page;
27 29
 		}
28 30
 	}
Please login to merge, or discard this patch.
dist/jate/modules/ExternalModules/composer/ClassLoader.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -341,6 +341,10 @@
 block discarded – undo
341 341
         return $file;
342 342
     }
343 343
 
344
+    /**
345
+     * @param string $class
346
+     * @param string $ext
347
+     */
344 348
     private function findFileWithExtension($class, $ext)
345 349
     {
346 350
         // PSR-4 lookup
Please login to merge, or discard this patch.
Indentation   +359 added lines, -359 removed lines patch added patch discarded remove patch
@@ -42,364 +42,364 @@  discard block
 block discarded – undo
42 42
  */
43 43
 class ClassLoader
44 44
 {
45
-    // PSR-4
46
-    private $prefixLengthsPsr4 = array();
47
-    private $prefixDirsPsr4 = array();
48
-    private $fallbackDirsPsr4 = array();
49
-
50
-    // PSR-0
51
-    private $prefixesPsr0 = array();
52
-    private $fallbackDirsPsr0 = array();
53
-
54
-    private $useIncludePath = false;
55
-    private $classMap = array();
56
-
57
-    private $classMapAuthoritative = false;
58
-
59
-    public function getPrefixes()
60
-    {
61
-        if (!empty($this->prefixesPsr0)) {
62
-            return call_user_func_array('array_merge', $this->prefixesPsr0);
63
-        }
64
-
65
-        return array();
66
-    }
67
-
68
-    public function getPrefixesPsr4()
69
-    {
70
-        return $this->prefixDirsPsr4;
71
-    }
72
-
73
-    public function getFallbackDirs()
74
-    {
75
-        return $this->fallbackDirsPsr0;
76
-    }
77
-
78
-    public function getFallbackDirsPsr4()
79
-    {
80
-        return $this->fallbackDirsPsr4;
81
-    }
82
-
83
-    public function getClassMap()
84
-    {
85
-        return $this->classMap;
86
-    }
87
-
88
-    /**
89
-     * @param array $classMap Class to filename map
90
-     */
91
-    public function addClassMap(array $classMap)
92
-    {
93
-        if ($this->classMap) {
94
-            $this->classMap = array_merge($this->classMap, $classMap);
95
-        } else {
96
-            $this->classMap = $classMap;
97
-        }
98
-    }
99
-
100
-    /**
101
-     * Registers a set of PSR-0 directories for a given prefix, either
102
-     * appending or prepending to the ones previously set for this prefix.
103
-     *
104
-     * @param string       $prefix  The prefix
105
-     * @param array|string $paths   The PSR-0 root directories
106
-     * @param bool         $prepend Whether to prepend the directories
107
-     */
108
-    public function add($prefix, $paths, $prepend = false)
109
-    {
110
-        if (!$prefix) {
111
-            if ($prepend) {
112
-                $this->fallbackDirsPsr0 = array_merge(
113
-                    (array) $paths,
114
-                    $this->fallbackDirsPsr0
115
-                );
116
-            } else {
117
-                $this->fallbackDirsPsr0 = array_merge(
118
-                    $this->fallbackDirsPsr0,
119
-                    (array) $paths
120
-                );
121
-            }
122
-
123
-            return;
124
-        }
125
-
126
-        $first = $prefix[0];
127
-        if (!isset($this->prefixesPsr0[$first][$prefix])) {
128
-            $this->prefixesPsr0[$first][$prefix] = (array) $paths;
129
-
130
-            return;
131
-        }
132
-        if ($prepend) {
133
-            $this->prefixesPsr0[$first][$prefix] = array_merge(
134
-                (array) $paths,
135
-                $this->prefixesPsr0[$first][$prefix]
136
-            );
137
-        } else {
138
-            $this->prefixesPsr0[$first][$prefix] = array_merge(
139
-                $this->prefixesPsr0[$first][$prefix],
140
-                (array) $paths
141
-            );
142
-        }
143
-    }
144
-
145
-    /**
146
-     * Registers a set of PSR-4 directories for a given namespace, either
147
-     * appending or prepending to the ones previously set for this namespace.
148
-     *
149
-     * @param string       $prefix  The prefix/namespace, with trailing '\\'
150
-     * @param array|string $paths   The PSR-4 base directories
151
-     * @param bool         $prepend Whether to prepend the directories
152
-     *
153
-     * @throws \InvalidArgumentException
154
-     */
155
-    public function addPsr4($prefix, $paths, $prepend = false)
156
-    {
157
-        if (!$prefix) {
158
-            // Register directories for the root namespace.
159
-            if ($prepend) {
160
-                $this->fallbackDirsPsr4 = array_merge(
161
-                    (array) $paths,
162
-                    $this->fallbackDirsPsr4
163
-                );
164
-            } else {
165
-                $this->fallbackDirsPsr4 = array_merge(
166
-                    $this->fallbackDirsPsr4,
167
-                    (array) $paths
168
-                );
169
-            }
170
-        } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
171
-            // Register directories for a new namespace.
172
-            $length = strlen($prefix);
173
-            if ('\\' !== $prefix[$length - 1]) {
174
-                throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
175
-            }
176
-            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
177
-            $this->prefixDirsPsr4[$prefix] = (array) $paths;
178
-        } elseif ($prepend) {
179
-            // Prepend directories for an already registered namespace.
180
-            $this->prefixDirsPsr4[$prefix] = array_merge(
181
-                (array) $paths,
182
-                $this->prefixDirsPsr4[$prefix]
183
-            );
184
-        } else {
185
-            // Append directories for an already registered namespace.
186
-            $this->prefixDirsPsr4[$prefix] = array_merge(
187
-                $this->prefixDirsPsr4[$prefix],
188
-                (array) $paths
189
-            );
190
-        }
191
-    }
192
-
193
-    /**
194
-     * Registers a set of PSR-0 directories for a given prefix,
195
-     * replacing any others previously set for this prefix.
196
-     *
197
-     * @param string       $prefix The prefix
198
-     * @param array|string $paths  The PSR-0 base directories
199
-     */
200
-    public function set($prefix, $paths)
201
-    {
202
-        if (!$prefix) {
203
-            $this->fallbackDirsPsr0 = (array) $paths;
204
-        } else {
205
-            $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
206
-        }
207
-    }
208
-
209
-    /**
210
-     * Registers a set of PSR-4 directories for a given namespace,
211
-     * replacing any others previously set for this namespace.
212
-     *
213
-     * @param string       $prefix The prefix/namespace, with trailing '\\'
214
-     * @param array|string $paths  The PSR-4 base directories
215
-     *
216
-     * @throws \InvalidArgumentException
217
-     */
218
-    public function setPsr4($prefix, $paths)
219
-    {
220
-        if (!$prefix) {
221
-            $this->fallbackDirsPsr4 = (array) $paths;
222
-        } else {
223
-            $length = strlen($prefix);
224
-            if ('\\' !== $prefix[$length - 1]) {
225
-                throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
226
-            }
227
-            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
228
-            $this->prefixDirsPsr4[$prefix] = (array) $paths;
229
-        }
230
-    }
231
-
232
-    /**
233
-     * Turns on searching the include path for class files.
234
-     *
235
-     * @param bool $useIncludePath
236
-     */
237
-    public function setUseIncludePath($useIncludePath)
238
-    {
239
-        $this->useIncludePath = $useIncludePath;
240
-    }
241
-
242
-    /**
243
-     * Can be used to check if the autoloader uses the include path to check
244
-     * for classes.
245
-     *
246
-     * @return bool
247
-     */
248
-    public function getUseIncludePath()
249
-    {
250
-        return $this->useIncludePath;
251
-    }
252
-
253
-    /**
254
-     * Turns off searching the prefix and fallback directories for classes
255
-     * that have not been registered with the class map.
256
-     *
257
-     * @param bool $classMapAuthoritative
258
-     */
259
-    public function setClassMapAuthoritative($classMapAuthoritative)
260
-    {
261
-        $this->classMapAuthoritative = $classMapAuthoritative;
262
-    }
263
-
264
-    /**
265
-     * Should class lookup fail if not found in the current class map?
266
-     *
267
-     * @return bool
268
-     */
269
-    public function isClassMapAuthoritative()
270
-    {
271
-        return $this->classMapAuthoritative;
272
-    }
273
-
274
-    /**
275
-     * Registers this instance as an autoloader.
276
-     *
277
-     * @param bool $prepend Whether to prepend the autoloader or not
278
-     */
279
-    public function register($prepend = false)
280
-    {
281
-        spl_autoload_register(array($this, 'loadClass'), true, $prepend);
282
-    }
283
-
284
-    /**
285
-     * Unregisters this instance as an autoloader.
286
-     */
287
-    public function unregister()
288
-    {
289
-        spl_autoload_unregister(array($this, 'loadClass'));
290
-    }
291
-
292
-    /**
293
-     * Loads the given class or interface.
294
-     *
295
-     * @param  string    $class The name of the class
296
-     * @return bool|null True if loaded, null otherwise
297
-     */
298
-    public function loadClass($class)
299
-    {
300
-        if ($file = $this->findFile($class)) {
301
-            includeFile($file);
302
-
303
-            return true;
304
-        }
305
-    }
306
-
307
-    /**
308
-     * Finds the path to the file where the class is defined.
309
-     *
310
-     * @param string $class The name of the class
311
-     *
312
-     * @return string|false The path if found, false otherwise
313
-     */
314
-    public function findFile($class)
315
-    {
316
-        // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
317
-        if ('\\' == $class[0]) {
318
-            $class = substr($class, 1);
319
-        }
320
-
321
-        // class map lookup
322
-        if (isset($this->classMap[$class])) {
323
-            return $this->classMap[$class];
324
-        }
325
-        if ($this->classMapAuthoritative) {
326
-            return false;
327
-        }
328
-
329
-        $file = $this->findFileWithExtension($class, '.php');
330
-
331
-        // Search for Hack files if we are running on HHVM
332
-        if ($file === null && defined('HHVM_VERSION')) {
333
-            $file = $this->findFileWithExtension($class, '.hh');
334
-        }
335
-
336
-        if ($file === null) {
337
-            // Remember that this class does not exist.
338
-            return $this->classMap[$class] = false;
339
-        }
340
-
341
-        return $file;
342
-    }
343
-
344
-    private function findFileWithExtension($class, $ext)
345
-    {
346
-        // PSR-4 lookup
347
-        $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
348
-
349
-        $first = $class[0];
350
-        if (isset($this->prefixLengthsPsr4[$first])) {
351
-            foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
352
-                if (0 === strpos($class, $prefix)) {
353
-                    foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
354
-                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
355
-                            return $file;
356
-                        }
357
-                    }
358
-                }
359
-            }
360
-        }
361
-
362
-        // PSR-4 fallback dirs
363
-        foreach ($this->fallbackDirsPsr4 as $dir) {
364
-            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
365
-                return $file;
366
-            }
367
-        }
368
-
369
-        // PSR-0 lookup
370
-        if (false !== $pos = strrpos($class, '\\')) {
371
-            // namespaced class name
372
-            $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
373
-                . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
374
-        } else {
375
-            // PEAR-like class name
376
-            $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
377
-        }
378
-
379
-        if (isset($this->prefixesPsr0[$first])) {
380
-            foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
381
-                if (0 === strpos($class, $prefix)) {
382
-                    foreach ($dirs as $dir) {
383
-                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
384
-                            return $file;
385
-                        }
386
-                    }
387
-                }
388
-            }
389
-        }
390
-
391
-        // PSR-0 fallback dirs
392
-        foreach ($this->fallbackDirsPsr0 as $dir) {
393
-            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
394
-                return $file;
395
-            }
396
-        }
397
-
398
-        // PSR-0 include paths.
399
-        if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
400
-            return $file;
401
-        }
402
-    }
45
+	// PSR-4
46
+	private $prefixLengthsPsr4 = array();
47
+	private $prefixDirsPsr4 = array();
48
+	private $fallbackDirsPsr4 = array();
49
+
50
+	// PSR-0
51
+	private $prefixesPsr0 = array();
52
+	private $fallbackDirsPsr0 = array();
53
+
54
+	private $useIncludePath = false;
55
+	private $classMap = array();
56
+
57
+	private $classMapAuthoritative = false;
58
+
59
+	public function getPrefixes()
60
+	{
61
+		if (!empty($this->prefixesPsr0)) {
62
+			return call_user_func_array('array_merge', $this->prefixesPsr0);
63
+		}
64
+
65
+		return array();
66
+	}
67
+
68
+	public function getPrefixesPsr4()
69
+	{
70
+		return $this->prefixDirsPsr4;
71
+	}
72
+
73
+	public function getFallbackDirs()
74
+	{
75
+		return $this->fallbackDirsPsr0;
76
+	}
77
+
78
+	public function getFallbackDirsPsr4()
79
+	{
80
+		return $this->fallbackDirsPsr4;
81
+	}
82
+
83
+	public function getClassMap()
84
+	{
85
+		return $this->classMap;
86
+	}
87
+
88
+	/**
89
+	 * @param array $classMap Class to filename map
90
+	 */
91
+	public function addClassMap(array $classMap)
92
+	{
93
+		if ($this->classMap) {
94
+			$this->classMap = array_merge($this->classMap, $classMap);
95
+		} else {
96
+			$this->classMap = $classMap;
97
+		}
98
+	}
99
+
100
+	/**
101
+	 * Registers a set of PSR-0 directories for a given prefix, either
102
+	 * appending or prepending to the ones previously set for this prefix.
103
+	 *
104
+	 * @param string       $prefix  The prefix
105
+	 * @param array|string $paths   The PSR-0 root directories
106
+	 * @param bool         $prepend Whether to prepend the directories
107
+	 */
108
+	public function add($prefix, $paths, $prepend = false)
109
+	{
110
+		if (!$prefix) {
111
+			if ($prepend) {
112
+				$this->fallbackDirsPsr0 = array_merge(
113
+					(array) $paths,
114
+					$this->fallbackDirsPsr0
115
+				);
116
+			} else {
117
+				$this->fallbackDirsPsr0 = array_merge(
118
+					$this->fallbackDirsPsr0,
119
+					(array) $paths
120
+				);
121
+			}
122
+
123
+			return;
124
+		}
125
+
126
+		$first = $prefix[0];
127
+		if (!isset($this->prefixesPsr0[$first][$prefix])) {
128
+			$this->prefixesPsr0[$first][$prefix] = (array) $paths;
129
+
130
+			return;
131
+		}
132
+		if ($prepend) {
133
+			$this->prefixesPsr0[$first][$prefix] = array_merge(
134
+				(array) $paths,
135
+				$this->prefixesPsr0[$first][$prefix]
136
+			);
137
+		} else {
138
+			$this->prefixesPsr0[$first][$prefix] = array_merge(
139
+				$this->prefixesPsr0[$first][$prefix],
140
+				(array) $paths
141
+			);
142
+		}
143
+	}
144
+
145
+	/**
146
+	 * Registers a set of PSR-4 directories for a given namespace, either
147
+	 * appending or prepending to the ones previously set for this namespace.
148
+	 *
149
+	 * @param string       $prefix  The prefix/namespace, with trailing '\\'
150
+	 * @param array|string $paths   The PSR-4 base directories
151
+	 * @param bool         $prepend Whether to prepend the directories
152
+	 *
153
+	 * @throws \InvalidArgumentException
154
+	 */
155
+	public function addPsr4($prefix, $paths, $prepend = false)
156
+	{
157
+		if (!$prefix) {
158
+			// Register directories for the root namespace.
159
+			if ($prepend) {
160
+				$this->fallbackDirsPsr4 = array_merge(
161
+					(array) $paths,
162
+					$this->fallbackDirsPsr4
163
+				);
164
+			} else {
165
+				$this->fallbackDirsPsr4 = array_merge(
166
+					$this->fallbackDirsPsr4,
167
+					(array) $paths
168
+				);
169
+			}
170
+		} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
171
+			// Register directories for a new namespace.
172
+			$length = strlen($prefix);
173
+			if ('\\' !== $prefix[$length - 1]) {
174
+				throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
175
+			}
176
+			$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
177
+			$this->prefixDirsPsr4[$prefix] = (array) $paths;
178
+		} elseif ($prepend) {
179
+			// Prepend directories for an already registered namespace.
180
+			$this->prefixDirsPsr4[$prefix] = array_merge(
181
+				(array) $paths,
182
+				$this->prefixDirsPsr4[$prefix]
183
+			);
184
+		} else {
185
+			// Append directories for an already registered namespace.
186
+			$this->prefixDirsPsr4[$prefix] = array_merge(
187
+				$this->prefixDirsPsr4[$prefix],
188
+				(array) $paths
189
+			);
190
+		}
191
+	}
192
+
193
+	/**
194
+	 * Registers a set of PSR-0 directories for a given prefix,
195
+	 * replacing any others previously set for this prefix.
196
+	 *
197
+	 * @param string       $prefix The prefix
198
+	 * @param array|string $paths  The PSR-0 base directories
199
+	 */
200
+	public function set($prefix, $paths)
201
+	{
202
+		if (!$prefix) {
203
+			$this->fallbackDirsPsr0 = (array) $paths;
204
+		} else {
205
+			$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
206
+		}
207
+	}
208
+
209
+	/**
210
+	 * Registers a set of PSR-4 directories for a given namespace,
211
+	 * replacing any others previously set for this namespace.
212
+	 *
213
+	 * @param string       $prefix The prefix/namespace, with trailing '\\'
214
+	 * @param array|string $paths  The PSR-4 base directories
215
+	 *
216
+	 * @throws \InvalidArgumentException
217
+	 */
218
+	public function setPsr4($prefix, $paths)
219
+	{
220
+		if (!$prefix) {
221
+			$this->fallbackDirsPsr4 = (array) $paths;
222
+		} else {
223
+			$length = strlen($prefix);
224
+			if ('\\' !== $prefix[$length - 1]) {
225
+				throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
226
+			}
227
+			$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
228
+			$this->prefixDirsPsr4[$prefix] = (array) $paths;
229
+		}
230
+	}
231
+
232
+	/**
233
+	 * Turns on searching the include path for class files.
234
+	 *
235
+	 * @param bool $useIncludePath
236
+	 */
237
+	public function setUseIncludePath($useIncludePath)
238
+	{
239
+		$this->useIncludePath = $useIncludePath;
240
+	}
241
+
242
+	/**
243
+	 * Can be used to check if the autoloader uses the include path to check
244
+	 * for classes.
245
+	 *
246
+	 * @return bool
247
+	 */
248
+	public function getUseIncludePath()
249
+	{
250
+		return $this->useIncludePath;
251
+	}
252
+
253
+	/**
254
+	 * Turns off searching the prefix and fallback directories for classes
255
+	 * that have not been registered with the class map.
256
+	 *
257
+	 * @param bool $classMapAuthoritative
258
+	 */
259
+	public function setClassMapAuthoritative($classMapAuthoritative)
260
+	{
261
+		$this->classMapAuthoritative = $classMapAuthoritative;
262
+	}
263
+
264
+	/**
265
+	 * Should class lookup fail if not found in the current class map?
266
+	 *
267
+	 * @return bool
268
+	 */
269
+	public function isClassMapAuthoritative()
270
+	{
271
+		return $this->classMapAuthoritative;
272
+	}
273
+
274
+	/**
275
+	 * Registers this instance as an autoloader.
276
+	 *
277
+	 * @param bool $prepend Whether to prepend the autoloader or not
278
+	 */
279
+	public function register($prepend = false)
280
+	{
281
+		spl_autoload_register(array($this, 'loadClass'), true, $prepend);
282
+	}
283
+
284
+	/**
285
+	 * Unregisters this instance as an autoloader.
286
+	 */
287
+	public function unregister()
288
+	{
289
+		spl_autoload_unregister(array($this, 'loadClass'));
290
+	}
291
+
292
+	/**
293
+	 * Loads the given class or interface.
294
+	 *
295
+	 * @param  string    $class The name of the class
296
+	 * @return bool|null True if loaded, null otherwise
297
+	 */
298
+	public function loadClass($class)
299
+	{
300
+		if ($file = $this->findFile($class)) {
301
+			includeFile($file);
302
+
303
+			return true;
304
+		}
305
+	}
306
+
307
+	/**
308
+	 * Finds the path to the file where the class is defined.
309
+	 *
310
+	 * @param string $class The name of the class
311
+	 *
312
+	 * @return string|false The path if found, false otherwise
313
+	 */
314
+	public function findFile($class)
315
+	{
316
+		// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
317
+		if ('\\' == $class[0]) {
318
+			$class = substr($class, 1);
319
+		}
320
+
321
+		// class map lookup
322
+		if (isset($this->classMap[$class])) {
323
+			return $this->classMap[$class];
324
+		}
325
+		if ($this->classMapAuthoritative) {
326
+			return false;
327
+		}
328
+
329
+		$file = $this->findFileWithExtension($class, '.php');
330
+
331
+		// Search for Hack files if we are running on HHVM
332
+		if ($file === null && defined('HHVM_VERSION')) {
333
+			$file = $this->findFileWithExtension($class, '.hh');
334
+		}
335
+
336
+		if ($file === null) {
337
+			// Remember that this class does not exist.
338
+			return $this->classMap[$class] = false;
339
+		}
340
+
341
+		return $file;
342
+	}
343
+
344
+	private function findFileWithExtension($class, $ext)
345
+	{
346
+		// PSR-4 lookup
347
+		$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
348
+
349
+		$first = $class[0];
350
+		if (isset($this->prefixLengthsPsr4[$first])) {
351
+			foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
352
+				if (0 === strpos($class, $prefix)) {
353
+					foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
354
+						if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
355
+							return $file;
356
+						}
357
+					}
358
+				}
359
+			}
360
+		}
361
+
362
+		// PSR-4 fallback dirs
363
+		foreach ($this->fallbackDirsPsr4 as $dir) {
364
+			if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
365
+				return $file;
366
+			}
367
+		}
368
+
369
+		// PSR-0 lookup
370
+		if (false !== $pos = strrpos($class, '\\')) {
371
+			// namespaced class name
372
+			$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
373
+				. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
374
+		} else {
375
+			// PEAR-like class name
376
+			$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
377
+		}
378
+
379
+		if (isset($this->prefixesPsr0[$first])) {
380
+			foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
381
+				if (0 === strpos($class, $prefix)) {
382
+					foreach ($dirs as $dir) {
383
+						if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
384
+							return $file;
385
+						}
386
+					}
387
+				}
388
+			}
389
+		}
390
+
391
+		// PSR-0 fallback dirs
392
+		foreach ($this->fallbackDirsPsr0 as $dir) {
393
+			if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
394
+				return $file;
395
+			}
396
+		}
397
+
398
+		// PSR-0 include paths.
399
+		if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
400
+			return $file;
401
+		}
402
+	}
403 403
 }
404 404
 
405 405
 /**
@@ -409,5 +409,5 @@  discard block
 block discarded – undo
409 409
  */
410 410
 function includeFile($file)
411 411
 {
412
-    include $file;
412
+	include $file;
413 413
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -344,14 +344,14 @@  discard block
 block discarded – undo
344 344
     private function findFileWithExtension($class, $ext)
345 345
     {
346 346
         // PSR-4 lookup
347
-        $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
347
+        $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext;
348 348
 
349 349
         $first = $class[0];
350 350
         if (isset($this->prefixLengthsPsr4[$first])) {
351 351
             foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
352 352
                 if (0 === strpos($class, $prefix)) {
353 353
                     foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
354
-                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
354
+                        if (file_exists($file = $dir.DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $length))) {
355 355
                             return $file;
356 356
                         }
357 357
                     }
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 
362 362
         // PSR-4 fallback dirs
363 363
         foreach ($this->fallbackDirsPsr4 as $dir) {
364
-            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
364
+            if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) {
365 365
                 return $file;
366 366
             }
367 367
         }
@@ -373,14 +373,14 @@  discard block
 block discarded – undo
373 373
                 . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
374 374
         } else {
375 375
             // PEAR-like class name
376
-            $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
376
+            $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext;
377 377
         }
378 378
 
379 379
         if (isset($this->prefixesPsr0[$first])) {
380 380
             foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
381 381
                 if (0 === strpos($class, $prefix)) {
382 382
                     foreach ($dirs as $dir) {
383
-                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
383
+                        if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) {
384 384
                             return $file;
385 385
                         }
386 386
                     }
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 
391 391
         // PSR-0 fallback dirs
392 392
         foreach ($this->fallbackDirsPsr0 as $dir) {
393
-            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
393
+            if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) {
394 394
                 return $file;
395 395
             }
396 396
         }
Please login to merge, or discard this patch.