@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | $namespace = 'portfolio'; |
4 | -require_once __DIR__ . '/../../bootstrap.php'; |
|
4 | +require_once __DIR__.'/../../bootstrap.php'; |
|
5 | 5 | |
6 | 6 | // route |
7 | 7 | Loader::loadInstance('router', 'Router'); |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | static private function form_url_array($host, $uri) |
16 | 16 | { |
17 | 17 | $uri = substr($uri, 1); |
18 | - if(strpos($uri, '?')) |
|
18 | + if (strpos($uri, '?')) |
|
19 | 19 | $uri = substr($uri, 0, strpos($uri, '?')); |
20 | 20 | $uri_array = explode('/', $uri); |
21 | 21 | |
22 | - if(!Loader::isLive()) |
|
22 | + if (!Loader::isLive()) |
|
23 | 23 | $host = substr($host, strpos($host, '.') + 1); |
24 | 24 | |
25 | 25 | self::$array['host'] = $host; |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | $base .= '/'; |
42 | 42 | |
43 | 43 | self::$array['base'] = $base; |
44 | - self::$array['uri'] = '/' . implode('/', $uri_array); |
|
44 | + self::$array['uri'] = '/'.implode('/', $uri_array); |
|
45 | 45 | |
46 | - if(end($uri_array) == '') |
|
46 | + if (end($uri_array) == '') |
|
47 | 47 | $uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
48 | 48 | self::$array['pieces'] = (array) $uri_array; |
49 | 49 | } |
@@ -71,21 +71,21 @@ discard block |
||
71 | 71 | static function getExtension() |
72 | 72 | { |
73 | 73 | $file = self::getPiece(-1); |
74 | - if(substr($file, -1) == '/') |
|
74 | + if (substr($file, -1) == '/') |
|
75 | 75 | return false; |
76 | - return substr($file, strrpos($file, '.') + 1);; |
|
76 | + return substr($file, strrpos($file, '.') + 1); ; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | static function getPiece($piece = null) |
80 | 80 | { |
81 | - if(!$piece) |
|
81 | + if (!$piece) |
|
82 | 82 | return self::$array['pieces']; |
83 | 83 | |
84 | - if($piece == -1) |
|
84 | + if ($piece == -1) |
|
85 | 85 | return end(self::$array['pieces']); |
86 | 86 | |
87 | 87 | $piece = $piece - 1; |
88 | - if(array_key_exists($piece, self::$array['pieces'])) |
|
88 | + if (array_key_exists($piece, self::$array['pieces'])) |
|
89 | 89 | return self::$array['pieces'][$piece]; |
90 | 90 | return; |
91 | 91 | } |
@@ -3,35 +3,35 @@ discard block |
||
3 | 3 | class URLDecode |
4 | 4 | { |
5 | 5 | |
6 | - private static $array = array(); |
|
6 | + private static $array = array(); |
|
7 | 7 | |
8 | - static function init() |
|
9 | - { |
|
10 | - $host = $_SERVER['HTTP_HOST']; |
|
11 | - $uri = $_SERVER['REQUEST_URI']; |
|
12 | - self::form_url_array($host, $uri); |
|
13 | - } |
|
8 | + static function init() |
|
9 | + { |
|
10 | + $host = $_SERVER['HTTP_HOST']; |
|
11 | + $uri = $_SERVER['REQUEST_URI']; |
|
12 | + self::form_url_array($host, $uri); |
|
13 | + } |
|
14 | 14 | |
15 | - static private function form_url_array($host, $uri) |
|
16 | - { |
|
17 | - $uri = substr($uri, 1); |
|
18 | - if(strpos($uri, '?')) |
|
19 | - $uri = substr($uri, 0, strpos($uri, '?')); |
|
20 | - $uri_array = explode('/', $uri); |
|
15 | + static private function form_url_array($host, $uri) |
|
16 | + { |
|
17 | + $uri = substr($uri, 1); |
|
18 | + if(strpos($uri, '?')) |
|
19 | + $uri = substr($uri, 0, strpos($uri, '?')); |
|
20 | + $uri_array = explode('/', $uri); |
|
21 | 21 | |
22 | - if(!Loader::isLive()) |
|
23 | - $host = substr($host, strpos($host, '.') + 1); |
|
22 | + if(!Loader::isLive()) |
|
23 | + $host = substr($host, strpos($host, '.') + 1); |
|
24 | 24 | |
25 | - self::$array['host'] = $host; |
|
25 | + self::$array['host'] = $host; |
|
26 | 26 | |
27 | 27 | if ( |
28 | - $host == 'www.waterfallsofthekeweenaw.com' || |
|
28 | + $host == 'www.waterfallsofthekeweenaw.com' || |
|
29 | 29 | $host == 'waterfallsofthekeweenaw.com' |
30 | 30 | ) { |
31 | - self::$array['site'] = 'waterfalls'; |
|
32 | - } else { |
|
33 | - self::$array['site'] = substr($host, 0, strpos($host, '.')); |
|
34 | - } |
|
31 | + self::$array['site'] = 'waterfalls'; |
|
32 | + } else { |
|
33 | + self::$array['site'] = substr($host, 0, strpos($host, '.')); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | $base = ''; |
37 | 37 | $base .= (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; |
@@ -40,55 +40,55 @@ discard block |
||
40 | 40 | $base .= $host; |
41 | 41 | $base .= '/'; |
42 | 42 | |
43 | - self::$array['base'] = $base; |
|
44 | - self::$array['uri'] = '/' . implode('/', $uri_array); |
|
43 | + self::$array['base'] = $base; |
|
44 | + self::$array['uri'] = '/' . implode('/', $uri_array); |
|
45 | 45 | |
46 | - if(end($uri_array) == '') |
|
47 | - $uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
|
48 | - self::$array['pieces'] = (array) $uri_array; |
|
49 | - } |
|
46 | + if(end($uri_array) == '') |
|
47 | + $uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
|
48 | + self::$array['pieces'] = (array) $uri_array; |
|
49 | + } |
|
50 | 50 | |
51 | - static function getSite() |
|
52 | - { |
|
53 | - return self::$array['site']; |
|
54 | - } |
|
51 | + static function getSite() |
|
52 | + { |
|
53 | + return self::$array['site']; |
|
54 | + } |
|
55 | 55 | |
56 | - static function getHost() |
|
57 | - { |
|
58 | - return self::$array['host']; |
|
59 | - } |
|
56 | + static function getHost() |
|
57 | + { |
|
58 | + return self::$array['host']; |
|
59 | + } |
|
60 | 60 | |
61 | - static function getBase() |
|
62 | - { |
|
63 | - return self::$array['base']; |
|
64 | - } |
|
61 | + static function getBase() |
|
62 | + { |
|
63 | + return self::$array['base']; |
|
64 | + } |
|
65 | 65 | |
66 | - static function getURI() |
|
67 | - { |
|
68 | - return self::$array['uri']; |
|
69 | - } |
|
66 | + static function getURI() |
|
67 | + { |
|
68 | + return self::$array['uri']; |
|
69 | + } |
|
70 | 70 | |
71 | - static function getExtension() |
|
72 | - { |
|
73 | - $file = self::getPiece(-1); |
|
74 | - if(substr($file, -1) == '/') |
|
75 | - return false; |
|
76 | - return substr($file, strrpos($file, '.') + 1);; |
|
77 | - } |
|
71 | + static function getExtension() |
|
72 | + { |
|
73 | + $file = self::getPiece(-1); |
|
74 | + if(substr($file, -1) == '/') |
|
75 | + return false; |
|
76 | + return substr($file, strrpos($file, '.') + 1);; |
|
77 | + } |
|
78 | 78 | |
79 | - static function getPiece($piece = null) |
|
80 | - { |
|
81 | - if(!$piece) |
|
82 | - return self::$array['pieces']; |
|
79 | + static function getPiece($piece = null) |
|
80 | + { |
|
81 | + if(!$piece) |
|
82 | + return self::$array['pieces']; |
|
83 | 83 | |
84 | - if($piece == -1) |
|
85 | - return end(self::$array['pieces']); |
|
84 | + if($piece == -1) |
|
85 | + return end(self::$array['pieces']); |
|
86 | 86 | |
87 | - $piece = $piece - 1; |
|
88 | - if(array_key_exists($piece, self::$array['pieces'])) |
|
89 | - return self::$array['pieces'][$piece]; |
|
90 | - return; |
|
91 | - } |
|
87 | + $piece = $piece - 1; |
|
88 | + if(array_key_exists($piece, self::$array['pieces'])) |
|
89 | + return self::$array['pieces'][$piece]; |
|
90 | + return; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
94 | 94 |
@@ -1,26 +1,28 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class URLDecode |
|
4 | -{ |
|
3 | +class URLDecode |
|
4 | +{ |
|
5 | 5 | |
6 | 6 | private static $array = array(); |
7 | 7 | |
8 | - static function init() |
|
9 | - { |
|
8 | + static function init() |
|
9 | + { |
|
10 | 10 | $host = $_SERVER['HTTP_HOST']; |
11 | 11 | $uri = $_SERVER['REQUEST_URI']; |
12 | 12 | self::form_url_array($host, $uri); |
13 | 13 | } |
14 | 14 | |
15 | - static private function form_url_array($host, $uri) |
|
16 | - { |
|
15 | + static private function form_url_array($host, $uri) |
|
16 | + { |
|
17 | 17 | $uri = substr($uri, 1); |
18 | - if(strpos($uri, '?')) |
|
19 | - $uri = substr($uri, 0, strpos($uri, '?')); |
|
18 | + if(strpos($uri, '?')) { |
|
19 | + $uri = substr($uri, 0, strpos($uri, '?')); |
|
20 | + } |
|
20 | 21 | $uri_array = explode('/', $uri); |
21 | 22 | |
22 | - if(!Loader::isLive()) |
|
23 | - $host = substr($host, strpos($host, '.') + 1); |
|
23 | + if(!Loader::isLive()) { |
|
24 | + $host = substr($host, strpos($host, '.') + 1); |
|
25 | + } |
|
24 | 26 | |
25 | 27 | self::$array['host'] = $host; |
26 | 28 | |
@@ -43,50 +45,55 @@ discard block |
||
43 | 45 | self::$array['base'] = $base; |
44 | 46 | self::$array['uri'] = '/' . implode('/', $uri_array); |
45 | 47 | |
46 | - if(end($uri_array) == '') |
|
47 | - $uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
|
48 | + if(end($uri_array) == '') { |
|
49 | + $uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
|
50 | + } |
|
48 | 51 | self::$array['pieces'] = (array) $uri_array; |
49 | 52 | } |
50 | 53 | |
51 | - static function getSite() |
|
52 | - { |
|
54 | + static function getSite() |
|
55 | + { |
|
53 | 56 | return self::$array['site']; |
54 | 57 | } |
55 | 58 | |
56 | - static function getHost() |
|
57 | - { |
|
59 | + static function getHost() |
|
60 | + { |
|
58 | 61 | return self::$array['host']; |
59 | 62 | } |
60 | 63 | |
61 | - static function getBase() |
|
62 | - { |
|
64 | + static function getBase() |
|
65 | + { |
|
63 | 66 | return self::$array['base']; |
64 | 67 | } |
65 | 68 | |
66 | - static function getURI() |
|
67 | - { |
|
69 | + static function getURI() |
|
70 | + { |
|
68 | 71 | return self::$array['uri']; |
69 | 72 | } |
70 | 73 | |
71 | - static function getExtension() |
|
72 | - { |
|
74 | + static function getExtension() |
|
75 | + { |
|
73 | 76 | $file = self::getPiece(-1); |
74 | - if(substr($file, -1) == '/') |
|
75 | - return false; |
|
77 | + if(substr($file, -1) == '/') { |
|
78 | + return false; |
|
79 | + } |
|
76 | 80 | return substr($file, strrpos($file, '.') + 1);; |
77 | 81 | } |
78 | 82 | |
79 | - static function getPiece($piece = null) |
|
80 | - { |
|
81 | - if(!$piece) |
|
82 | - return self::$array['pieces']; |
|
83 | + static function getPiece($piece = null) |
|
84 | + { |
|
85 | + if(!$piece) { |
|
86 | + return self::$array['pieces']; |
|
87 | + } |
|
83 | 88 | |
84 | - if($piece == -1) |
|
85 | - return end(self::$array['pieces']); |
|
89 | + if($piece == -1) { |
|
90 | + return end(self::$array['pieces']); |
|
91 | + } |
|
86 | 92 | |
87 | 93 | $piece = $piece - 1; |
88 | - if(array_key_exists($piece, self::$array['pieces'])) |
|
89 | - return self::$array['pieces'][$piece]; |
|
94 | + if(array_key_exists($piece, self::$array['pieces'])) { |
|
95 | + return self::$array['pieces'][$piece]; |
|
96 | + } |
|
90 | 97 | return; |
91 | 98 | } |
92 | 99 |
@@ -17,14 +17,14 @@ discard block |
||
17 | 17 | |
18 | 18 | public static function instance() |
19 | 19 | { |
20 | - if(!isset(self::$instance)) |
|
20 | + if (!isset(self::$instance)) |
|
21 | 21 | self::$instance = new Loader(); |
22 | 22 | return self::$instance; |
23 | 23 | } |
24 | 24 | |
25 | 25 | private function get_root() |
26 | 26 | { |
27 | - if(!isset($this->root)) |
|
27 | + if (!isset($this->root)) |
|
28 | 28 | { |
29 | 29 | $current_directory = dirname(__FILE__); |
30 | 30 | $current_directory = substr($current_directory, 0, -7); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | private static function get_extension($type) |
54 | 54 | { |
55 | - switch($type) |
|
55 | + switch ($type) |
|
56 | 56 | { |
57 | 57 | case 'collector' : |
58 | 58 | case 'controller' : |
@@ -104,15 +104,15 @@ discard block |
||
104 | 104 | |
105 | 105 | public static function load($type, $files, $data = array()) |
106 | 106 | { |
107 | - foreach((array) $files as $file) |
|
107 | + foreach ((array) $files as $file) |
|
108 | 108 | { |
109 | 109 | $file_path = self::instance()->get_path($type, $file); |
110 | - if(in_array($file_path, self::instance()->get_included_files()) && $type !== 'view') |
|
110 | + if (in_array($file_path, self::instance()->get_included_files()) && $type !== 'view') |
|
111 | 111 | continue; |
112 | 112 | |
113 | 113 | self::instance()->add_included_file($file_path); |
114 | 114 | |
115 | - switch($type) |
|
115 | + switch ($type) |
|
116 | 116 | { |
117 | 117 | case 'images' : |
118 | 118 | case 'scripts' : |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | |
143 | 143 | $reflectionObject = self::create_reflection_class($file); |
144 | 144 | |
145 | - if( |
|
145 | + if ( |
|
146 | 146 | $reflectionObject->hasMethod('instance') && |
147 | 147 | $reflectionObject->getMethod('instance')->isStatic()) |
148 | 148 | { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | $reflectionObject = self::create_reflection_class($file); |
159 | 159 | |
160 | - if($reflectionObject->hasMethod('__construct')) |
|
160 | + if ($reflectionObject->hasMethod('__construct')) |
|
161 | 161 | return $reflectionObject->newInstanceArgs($data); |
162 | 162 | else |
163 | 163 | return $reflectionObject->newInstance(); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | if ($site == 'waterfalls' && self::instance()->is_live) { |
181 | 181 | return "{$protocol}://www.waterfallsofthekeweenaw.com/"; |
182 | 182 | } else { |
183 | - return $protocol . '://' . (self::instance()->is_live ? '' : 'dev.') . $site . '.jacobemerick.com/'; |
|
183 | + return $protocol.'://'.(self::instance()->is_live ? '' : 'dev.').$site.'.jacobemerick.com/'; |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | return '/'; |
@@ -3,175 +3,175 @@ |
||
3 | 3 | final class Loader |
4 | 4 | { |
5 | 5 | |
6 | - private $root; |
|
7 | - private $is_live; |
|
8 | - private $included_files = array(); |
|
9 | - |
|
10 | - private static $instance; |
|
11 | - |
|
12 | - private function __construct() |
|
13 | - { |
|
14 | - $this->is_live = (isset($_SERVER['HTTP_HOST']) && substr($_SERVER['HTTP_HOST'], 0, 4) !== 'dev.'); |
|
15 | - return $this; |
|
16 | - } |
|
17 | - |
|
18 | - public static function instance() |
|
19 | - { |
|
20 | - if(!isset(self::$instance)) |
|
21 | - self::$instance = new Loader(); |
|
22 | - return self::$instance; |
|
23 | - } |
|
24 | - |
|
25 | - private function get_root() |
|
26 | - { |
|
27 | - if(!isset($this->root)) |
|
28 | - { |
|
29 | - $current_directory = dirname(__FILE__); |
|
30 | - $current_directory = substr($current_directory, 0, -7); |
|
31 | - $this->root = $current_directory; |
|
32 | - } |
|
6 | + private $root; |
|
7 | + private $is_live; |
|
8 | + private $included_files = array(); |
|
9 | + |
|
10 | + private static $instance; |
|
11 | + |
|
12 | + private function __construct() |
|
13 | + { |
|
14 | + $this->is_live = (isset($_SERVER['HTTP_HOST']) && substr($_SERVER['HTTP_HOST'], 0, 4) !== 'dev.'); |
|
15 | + return $this; |
|
16 | + } |
|
17 | + |
|
18 | + public static function instance() |
|
19 | + { |
|
20 | + if(!isset(self::$instance)) |
|
21 | + self::$instance = new Loader(); |
|
22 | + return self::$instance; |
|
23 | + } |
|
24 | + |
|
25 | + private function get_root() |
|
26 | + { |
|
27 | + if(!isset($this->root)) |
|
28 | + { |
|
29 | + $current_directory = dirname(__FILE__); |
|
30 | + $current_directory = substr($current_directory, 0, -7); |
|
31 | + $this->root = $current_directory; |
|
32 | + } |
|
33 | 33 | |
34 | - return $this->root; |
|
35 | - } |
|
36 | - |
|
37 | - private function get_delimiter() |
|
38 | - { |
|
39 | - return (true || $this->is_live) ? '/' : '\\'; |
|
40 | - } |
|
41 | - |
|
42 | - private function check_delimiters($path) |
|
43 | - { |
|
44 | - return (true || $this->is_live) ? $path : str_replace('/', '\\', $path); |
|
45 | - } |
|
46 | - |
|
47 | - private static function get_class_name($path) |
|
48 | - { |
|
49 | - $path_array = explode('/', $path); |
|
50 | - return array_pop($path_array); |
|
51 | - } |
|
52 | - |
|
53 | - private static function get_extension($type) |
|
54 | - { |
|
55 | - switch($type) |
|
56 | - { |
|
57 | - case 'collector' : |
|
58 | - case 'controller' : |
|
59 | - case 'model' : |
|
60 | - case 'module' : |
|
61 | - case 'router' : |
|
62 | - case 'utility' : |
|
63 | - $extension = '.class.inc.php'; |
|
64 | - break; |
|
65 | - case 'view' : |
|
66 | - $extension = '.tpl.php'; |
|
67 | - break; |
|
68 | - } |
|
69 | - return $extension; |
|
70 | - } |
|
71 | - |
|
72 | - public static function getImagePath($type, $file) |
|
73 | - { |
|
74 | - $path = self::instance()->get_root(); |
|
75 | - $path .= 'public'; |
|
76 | - $path .= self::instance()->get_delimiter(); |
|
77 | - $path .= $type; |
|
78 | - $path .= self::instance()->get_delimiter(); |
|
79 | - $path .= self::instance()->check_delimiters($file); |
|
34 | + return $this->root; |
|
35 | + } |
|
36 | + |
|
37 | + private function get_delimiter() |
|
38 | + { |
|
39 | + return (true || $this->is_live) ? '/' : '\\'; |
|
40 | + } |
|
41 | + |
|
42 | + private function check_delimiters($path) |
|
43 | + { |
|
44 | + return (true || $this->is_live) ? $path : str_replace('/', '\\', $path); |
|
45 | + } |
|
46 | + |
|
47 | + private static function get_class_name($path) |
|
48 | + { |
|
49 | + $path_array = explode('/', $path); |
|
50 | + return array_pop($path_array); |
|
51 | + } |
|
52 | + |
|
53 | + private static function get_extension($type) |
|
54 | + { |
|
55 | + switch($type) |
|
56 | + { |
|
57 | + case 'collector' : |
|
58 | + case 'controller' : |
|
59 | + case 'model' : |
|
60 | + case 'module' : |
|
61 | + case 'router' : |
|
62 | + case 'utility' : |
|
63 | + $extension = '.class.inc.php'; |
|
64 | + break; |
|
65 | + case 'view' : |
|
66 | + $extension = '.tpl.php'; |
|
67 | + break; |
|
68 | + } |
|
69 | + return $extension; |
|
70 | + } |
|
71 | + |
|
72 | + public static function getImagePath($type, $file) |
|
73 | + { |
|
74 | + $path = self::instance()->get_root(); |
|
75 | + $path .= 'public'; |
|
76 | + $path .= self::instance()->get_delimiter(); |
|
77 | + $path .= $type; |
|
78 | + $path .= self::instance()->get_delimiter(); |
|
79 | + $path .= self::instance()->check_delimiters($file); |
|
80 | 80 | |
81 | - return $path; |
|
82 | - } |
|
83 | - |
|
84 | - private static function get_path($type, $file) |
|
85 | - { |
|
86 | - $path = self::instance()->get_root(); |
|
87 | - $path .= $type; |
|
88 | - $path .= self::instance()->get_delimiter(); |
|
89 | - $path .= self::instance()->check_delimiters($file); |
|
90 | - $path .= self::get_extension($type); |
|
81 | + return $path; |
|
82 | + } |
|
83 | + |
|
84 | + private static function get_path($type, $file) |
|
85 | + { |
|
86 | + $path = self::instance()->get_root(); |
|
87 | + $path .= $type; |
|
88 | + $path .= self::instance()->get_delimiter(); |
|
89 | + $path .= self::instance()->check_delimiters($file); |
|
90 | + $path .= self::get_extension($type); |
|
91 | 91 | |
92 | - return $path; |
|
93 | - } |
|
94 | - |
|
95 | - private function get_included_files() |
|
96 | - { |
|
97 | - return $this->included_files; |
|
98 | - } |
|
99 | - |
|
100 | - private function add_included_file($path) |
|
101 | - { |
|
102 | - $this->included_files[] = $path; |
|
103 | - } |
|
104 | - |
|
105 | - public static function load($type, $files, $data = array()) |
|
106 | - { |
|
107 | - foreach((array) $files as $file) |
|
108 | - { |
|
109 | - $file_path = self::instance()->get_path($type, $file); |
|
110 | - if(in_array($file_path, self::instance()->get_included_files()) && $type !== 'view') |
|
111 | - continue; |
|
92 | + return $path; |
|
93 | + } |
|
94 | + |
|
95 | + private function get_included_files() |
|
96 | + { |
|
97 | + return $this->included_files; |
|
98 | + } |
|
99 | + |
|
100 | + private function add_included_file($path) |
|
101 | + { |
|
102 | + $this->included_files[] = $path; |
|
103 | + } |
|
104 | + |
|
105 | + public static function load($type, $files, $data = array()) |
|
106 | + { |
|
107 | + foreach((array) $files as $file) |
|
108 | + { |
|
109 | + $file_path = self::instance()->get_path($type, $file); |
|
110 | + if(in_array($file_path, self::instance()->get_included_files()) && $type !== 'view') |
|
111 | + continue; |
|
112 | 112 | |
113 | - self::instance()->add_included_file($file_path); |
|
113 | + self::instance()->add_included_file($file_path); |
|
114 | 114 | |
115 | - switch($type) |
|
116 | - { |
|
117 | - case 'images' : |
|
118 | - case 'scripts' : |
|
119 | - case 'styles' : |
|
120 | - echo file_get_contents($file_path); |
|
121 | - break; |
|
122 | - case 'view' : |
|
123 | - extract($data); |
|
124 | - include($file_path); |
|
125 | - break; |
|
126 | - default : |
|
127 | - include_once($file_path); |
|
128 | - break; |
|
129 | - } |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - private static function create_reflection_class($file) |
|
134 | - { |
|
135 | - $class_name = self::instance()->get_class_name($file); |
|
136 | - return new ReflectionClass($class_name); |
|
137 | - } |
|
138 | - |
|
139 | - public static function loadInstance($type, $file) |
|
140 | - { |
|
141 | - self::load($type, $file); |
|
115 | + switch($type) |
|
116 | + { |
|
117 | + case 'images' : |
|
118 | + case 'scripts' : |
|
119 | + case 'styles' : |
|
120 | + echo file_get_contents($file_path); |
|
121 | + break; |
|
122 | + case 'view' : |
|
123 | + extract($data); |
|
124 | + include($file_path); |
|
125 | + break; |
|
126 | + default : |
|
127 | + include_once($file_path); |
|
128 | + break; |
|
129 | + } |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + private static function create_reflection_class($file) |
|
134 | + { |
|
135 | + $class_name = self::instance()->get_class_name($file); |
|
136 | + return new ReflectionClass($class_name); |
|
137 | + } |
|
138 | + |
|
139 | + public static function loadInstance($type, $file) |
|
140 | + { |
|
141 | + self::load($type, $file); |
|
142 | 142 | |
143 | - $reflectionObject = self::create_reflection_class($file); |
|
143 | + $reflectionObject = self::create_reflection_class($file); |
|
144 | 144 | |
145 | - if( |
|
146 | - $reflectionObject->hasMethod('instance') && |
|
147 | - $reflectionObject->getMethod('instance')->isStatic()) |
|
148 | - { |
|
149 | - return $reflectionObject->getMethod('instance')->invoke(null); |
|
150 | - } |
|
151 | - trigger_error("Requested class cannot be instance'd: {$type}, {$file}"); |
|
152 | - } |
|
153 | - |
|
154 | - public static function loadNew($type, $file, $data = array()) |
|
155 | - { |
|
156 | - self::load($type, $file); |
|
145 | + if( |
|
146 | + $reflectionObject->hasMethod('instance') && |
|
147 | + $reflectionObject->getMethod('instance')->isStatic()) |
|
148 | + { |
|
149 | + return $reflectionObject->getMethod('instance')->invoke(null); |
|
150 | + } |
|
151 | + trigger_error("Requested class cannot be instance'd: {$type}, {$file}"); |
|
152 | + } |
|
153 | + |
|
154 | + public static function loadNew($type, $file, $data = array()) |
|
155 | + { |
|
156 | + self::load($type, $file); |
|
157 | 157 | |
158 | - $reflectionObject = self::create_reflection_class($file); |
|
158 | + $reflectionObject = self::create_reflection_class($file); |
|
159 | 159 | |
160 | - if($reflectionObject->hasMethod('__construct')) |
|
161 | - return $reflectionObject->newInstanceArgs($data); |
|
162 | - else |
|
163 | - return $reflectionObject->newInstance(); |
|
164 | - } |
|
165 | - |
|
166 | - public static function getRoot() |
|
167 | - { |
|
168 | - return self::instance()->get_root(); |
|
169 | - } |
|
170 | - |
|
171 | - public static function isLive() |
|
172 | - { |
|
173 | - return self::instance()->is_live; |
|
174 | - } |
|
160 | + if($reflectionObject->hasMethod('__construct')) |
|
161 | + return $reflectionObject->newInstanceArgs($data); |
|
162 | + else |
|
163 | + return $reflectionObject->newInstance(); |
|
164 | + } |
|
165 | + |
|
166 | + public static function getRoot() |
|
167 | + { |
|
168 | + return self::instance()->get_root(); |
|
169 | + } |
|
170 | + |
|
171 | + public static function isLive() |
|
172 | + { |
|
173 | + return self::instance()->is_live; |
|
174 | + } |
|
175 | 175 | |
176 | 176 | public static function getRootURL($site = '') |
177 | 177 | { |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -final class Loader |
|
4 | -{ |
|
3 | +final class Loader |
|
4 | +{ |
|
5 | 5 | |
6 | 6 | private $root; |
7 | 7 | private $is_live; |
@@ -9,21 +9,22 @@ discard block |
||
9 | 9 | |
10 | 10 | private static $instance; |
11 | 11 | |
12 | - private function __construct() |
|
13 | - { |
|
12 | + private function __construct() |
|
13 | + { |
|
14 | 14 | $this->is_live = (isset($_SERVER['HTTP_HOST']) && substr($_SERVER['HTTP_HOST'], 0, 4) !== 'dev.'); |
15 | 15 | return $this; |
16 | 16 | } |
17 | 17 | |
18 | - public static function instance() |
|
19 | - { |
|
20 | - if(!isset(self::$instance)) |
|
21 | - self::$instance = new Loader(); |
|
18 | + public static function instance() |
|
19 | + { |
|
20 | + if(!isset(self::$instance)) { |
|
21 | + self::$instance = new Loader(); |
|
22 | + } |
|
22 | 23 | return self::$instance; |
23 | 24 | } |
24 | 25 | |
25 | - private function get_root() |
|
26 | - { |
|
26 | + private function get_root() |
|
27 | + { |
|
27 | 28 | if(!isset($this->root)) |
28 | 29 | { |
29 | 30 | $current_directory = dirname(__FILE__); |
@@ -34,24 +35,24 @@ discard block |
||
34 | 35 | return $this->root; |
35 | 36 | } |
36 | 37 | |
37 | - private function get_delimiter() |
|
38 | - { |
|
38 | + private function get_delimiter() |
|
39 | + { |
|
39 | 40 | return (true || $this->is_live) ? '/' : '\\'; |
40 | 41 | } |
41 | 42 | |
42 | - private function check_delimiters($path) |
|
43 | - { |
|
43 | + private function check_delimiters($path) |
|
44 | + { |
|
44 | 45 | return (true || $this->is_live) ? $path : str_replace('/', '\\', $path); |
45 | 46 | } |
46 | 47 | |
47 | - private static function get_class_name($path) |
|
48 | - { |
|
48 | + private static function get_class_name($path) |
|
49 | + { |
|
49 | 50 | $path_array = explode('/', $path); |
50 | 51 | return array_pop($path_array); |
51 | 52 | } |
52 | 53 | |
53 | - private static function get_extension($type) |
|
54 | - { |
|
54 | + private static function get_extension($type) |
|
55 | + { |
|
55 | 56 | switch($type) |
56 | 57 | { |
57 | 58 | case 'collector' : |
@@ -69,8 +70,8 @@ discard block |
||
69 | 70 | return $extension; |
70 | 71 | } |
71 | 72 | |
72 | - public static function getImagePath($type, $file) |
|
73 | - { |
|
73 | + public static function getImagePath($type, $file) |
|
74 | + { |
|
74 | 75 | $path = self::instance()->get_root(); |
75 | 76 | $path .= 'public'; |
76 | 77 | $path .= self::instance()->get_delimiter(); |
@@ -81,8 +82,8 @@ discard block |
||
81 | 82 | return $path; |
82 | 83 | } |
83 | 84 | |
84 | - private static function get_path($type, $file) |
|
85 | - { |
|
85 | + private static function get_path($type, $file) |
|
86 | + { |
|
86 | 87 | $path = self::instance()->get_root(); |
87 | 88 | $path .= $type; |
88 | 89 | $path .= self::instance()->get_delimiter(); |
@@ -92,23 +93,24 @@ discard block |
||
92 | 93 | return $path; |
93 | 94 | } |
94 | 95 | |
95 | - private function get_included_files() |
|
96 | - { |
|
96 | + private function get_included_files() |
|
97 | + { |
|
97 | 98 | return $this->included_files; |
98 | 99 | } |
99 | 100 | |
100 | - private function add_included_file($path) |
|
101 | - { |
|
101 | + private function add_included_file($path) |
|
102 | + { |
|
102 | 103 | $this->included_files[] = $path; |
103 | 104 | } |
104 | 105 | |
105 | - public static function load($type, $files, $data = array()) |
|
106 | - { |
|
106 | + public static function load($type, $files, $data = array()) |
|
107 | + { |
|
107 | 108 | foreach((array) $files as $file) |
108 | 109 | { |
109 | 110 | $file_path = self::instance()->get_path($type, $file); |
110 | - if(in_array($file_path, self::instance()->get_included_files()) && $type !== 'view') |
|
111 | - continue; |
|
111 | + if(in_array($file_path, self::instance()->get_included_files()) && $type !== 'view') { |
|
112 | + continue; |
|
113 | + } |
|
112 | 114 | |
113 | 115 | self::instance()->add_included_file($file_path); |
114 | 116 | |
@@ -130,14 +132,14 @@ discard block |
||
130 | 132 | } |
131 | 133 | } |
132 | 134 | |
133 | - private static function create_reflection_class($file) |
|
134 | - { |
|
135 | + private static function create_reflection_class($file) |
|
136 | + { |
|
135 | 137 | $class_name = self::instance()->get_class_name($file); |
136 | 138 | return new ReflectionClass($class_name); |
137 | 139 | } |
138 | 140 | |
139 | - public static function loadInstance($type, $file) |
|
140 | - { |
|
141 | + public static function loadInstance($type, $file) |
|
142 | + { |
|
141 | 143 | self::load($type, $file); |
142 | 144 | |
143 | 145 | $reflectionObject = self::create_reflection_class($file); |
@@ -151,30 +153,31 @@ discard block |
||
151 | 153 | trigger_error("Requested class cannot be instance'd: {$type}, {$file}"); |
152 | 154 | } |
153 | 155 | |
154 | - public static function loadNew($type, $file, $data = array()) |
|
155 | - { |
|
156 | + public static function loadNew($type, $file, $data = array()) |
|
157 | + { |
|
156 | 158 | self::load($type, $file); |
157 | 159 | |
158 | 160 | $reflectionObject = self::create_reflection_class($file); |
159 | 161 | |
160 | - if($reflectionObject->hasMethod('__construct')) |
|
161 | - return $reflectionObject->newInstanceArgs($data); |
|
162 | - else |
|
163 | - return $reflectionObject->newInstance(); |
|
162 | + if($reflectionObject->hasMethod('__construct')) { |
|
163 | + return $reflectionObject->newInstanceArgs($data); |
|
164 | + } else { |
|
165 | + return $reflectionObject->newInstance(); |
|
166 | + } |
|
164 | 167 | } |
165 | 168 | |
166 | - public static function getRoot() |
|
167 | - { |
|
169 | + public static function getRoot() |
|
170 | + { |
|
168 | 171 | return self::instance()->get_root(); |
169 | 172 | } |
170 | 173 | |
171 | - public static function isLive() |
|
172 | - { |
|
174 | + public static function isLive() |
|
175 | + { |
|
173 | 176 | return self::instance()->is_live; |
174 | 177 | } |
175 | 178 | |
176 | - public static function getRootURL($site = '') |
|
177 | - { |
|
179 | + public static function getRootURL($site = '') |
|
180 | + { |
|
178 | 181 | if (strlen($site) > 0) { |
179 | 182 | $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; |
180 | 183 | if ($site == 'waterfalls' && self::instance()->is_live) { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $mysqli = new mysqli($host, $username, $password); |
37 | 37 | |
38 | 38 | $has_connection_error = $mysqli->connect_error; |
39 | - if(isset($has_connection_error)) |
|
39 | + if (isset($has_connection_error)) |
|
40 | 40 | $this->has_connection_error = true; |
41 | 41 | |
42 | 42 | return $mysqli; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | |
45 | 45 | public static function instance() |
46 | 46 | { |
47 | - if(!isset(self::$instance)) { |
|
47 | + if (!isset(self::$instance)) { |
|
48 | 48 | global $config; |
49 | 49 | self::$instance = new Database( |
50 | 50 | $config->database->master, |
@@ -63,23 +63,23 @@ discard block |
||
63 | 63 | public static function select($query) |
64 | 64 | { |
65 | 65 | $start = microtime(true); |
66 | - if($result = self::instance()->read_connection->query($query)) |
|
66 | + if ($result = self::instance()->read_connection->query($query)) |
|
67 | 67 | { |
68 | 68 | self::instance()->log_query($query, $start); |
69 | 69 | $array = array(); |
70 | - while($row = $result->fetch_object()) |
|
70 | + while ($row = $result->fetch_object()) |
|
71 | 71 | $array[] = $row; |
72 | 72 | $result->close(); |
73 | 73 | return $array; |
74 | 74 | } |
75 | - trigger_error('Could not preform query - ' . $query . ' - ' . self::instance()->read_connection->error); |
|
75 | + trigger_error('Could not preform query - '.$query.' - '.self::instance()->read_connection->error); |
|
76 | 76 | return false; |
77 | 77 | } |
78 | 78 | |
79 | 79 | public static function selectRow($query) |
80 | 80 | { |
81 | 81 | $result = self::select($query); |
82 | - if(is_array($result)) |
|
82 | + if (is_array($result)) |
|
83 | 83 | return array_pop($result); |
84 | 84 | return false; |
85 | 85 | } |
@@ -87,19 +87,19 @@ discard block |
||
87 | 87 | public static function execute($query) |
88 | 88 | { |
89 | 89 | $start = microtime(true); |
90 | - if(self::instance()->write_connection->query($query)) |
|
90 | + if (self::instance()->write_connection->query($query)) |
|
91 | 91 | { |
92 | 92 | self::instance()->log_query($query, $start); |
93 | 93 | return true; |
94 | 94 | } |
95 | - trigger_error('Could not preform query - ' . $query . '-' . self::instance()->write_connection->error); |
|
95 | + trigger_error('Could not preform query - '.$query.'-'.self::instance()->write_connection->error); |
|
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
99 | 99 | public static function lastInsertID() |
100 | 100 | { |
101 | 101 | $id = self::instance()->write_connection->insert_id; |
102 | - if($id == 0) |
|
102 | + if ($id == 0) |
|
103 | 103 | return false; |
104 | 104 | return $id; |
105 | 105 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | private function gather_query_data() |
120 | 120 | { |
121 | 121 | $query_data = array(); |
122 | - foreach($this->query_log as $query) |
|
122 | + foreach ($this->query_log as $query) |
|
123 | 123 | { |
124 | 124 | $query = self::explain($query); |
125 | 125 | $query_data[] = $query; |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | |
130 | 130 | public static function explain($query) |
131 | 131 | { |
132 | - $sql = 'EXPLAIN ' . $query['sql']; |
|
132 | + $sql = 'EXPLAIN '.$query['sql']; |
|
133 | 133 | |
134 | - if($result = self::instance()->read_connection->query($sql)) |
|
134 | + if ($result = self::instance()->read_connection->query($sql)) |
|
135 | 135 | { |
136 | 136 | $row = $result->fetch_assoc(); |
137 | 137 | $query['explain'] = $row; |
@@ -3,19 +3,19 @@ discard block |
||
3 | 3 | final class Database |
4 | 4 | { |
5 | 5 | |
6 | - private $read_connection; |
|
7 | - private $write_connection; |
|
8 | - private $query_log = array(); |
|
9 | - private $query_total = array( |
|
10 | - 'count' => 0, |
|
11 | - 'time' => 0); |
|
6 | + private $read_connection; |
|
7 | + private $write_connection; |
|
8 | + private $query_log = array(); |
|
9 | + private $query_total = array( |
|
10 | + 'count' => 0, |
|
11 | + 'time' => 0); |
|
12 | 12 | |
13 | - private $has_connection_error = false; |
|
13 | + private $has_connection_error = false; |
|
14 | 14 | |
15 | - private static $instance; |
|
15 | + private static $instance; |
|
16 | 16 | |
17 | - private function __construct($write_params, $read_params) |
|
18 | - { |
|
17 | + private function __construct($write_params, $read_params) |
|
18 | + { |
|
19 | 19 | $this->write_connection = $this->connect( |
20 | 20 | $write_params->host, |
21 | 21 | $write_params->user, |
@@ -28,23 +28,23 @@ discard block |
||
28 | 28 | $read_params->password |
29 | 29 | ); |
30 | 30 | |
31 | - return $this; |
|
32 | - } |
|
31 | + return $this; |
|
32 | + } |
|
33 | 33 | |
34 | - private function connect($host, $username, $password) |
|
35 | - { |
|
36 | - $mysqli = new mysqli($host, $username, $password); |
|
34 | + private function connect($host, $username, $password) |
|
35 | + { |
|
36 | + $mysqli = new mysqli($host, $username, $password); |
|
37 | 37 | |
38 | - $has_connection_error = $mysqli->connect_error; |
|
39 | - if(isset($has_connection_error)) |
|
40 | - $this->has_connection_error = true; |
|
38 | + $has_connection_error = $mysqli->connect_error; |
|
39 | + if(isset($has_connection_error)) |
|
40 | + $this->has_connection_error = true; |
|
41 | 41 | |
42 | - return $mysqli; |
|
43 | - } |
|
42 | + return $mysqli; |
|
43 | + } |
|
44 | 44 | |
45 | - public static function instance() |
|
46 | - { |
|
47 | - if(!isset(self::$instance)) { |
|
45 | + public static function instance() |
|
46 | + { |
|
47 | + if(!isset(self::$instance)) { |
|
48 | 48 | global $config; |
49 | 49 | self::$instance = new Database( |
50 | 50 | $config->database->master, |
@@ -52,107 +52,107 @@ discard block |
||
52 | 52 | ); |
53 | 53 | } |
54 | 54 | |
55 | - return self::$instance; |
|
56 | - } |
|
57 | - |
|
58 | - public static function escape($string) |
|
59 | - { |
|
60 | - return self::instance()->read_connection->real_escape_string($string); |
|
61 | - } |
|
62 | - |
|
63 | - public static function select($query) |
|
64 | - { |
|
65 | - $start = microtime(true); |
|
66 | - if($result = self::instance()->read_connection->query($query)) |
|
67 | - { |
|
68 | - self::instance()->log_query($query, $start); |
|
69 | - $array = array(); |
|
70 | - while($row = $result->fetch_object()) |
|
71 | - $array[] = $row; |
|
72 | - $result->close(); |
|
73 | - return $array; |
|
74 | - } |
|
75 | - trigger_error('Could not preform query - ' . $query . ' - ' . self::instance()->read_connection->error); |
|
76 | - return false; |
|
77 | - } |
|
78 | - |
|
79 | - public static function selectRow($query) |
|
80 | - { |
|
81 | - $result = self::select($query); |
|
82 | - if(is_array($result)) |
|
83 | - return array_pop($result); |
|
84 | - return false; |
|
85 | - } |
|
86 | - |
|
87 | - public static function execute($query) |
|
88 | - { |
|
89 | - $start = microtime(true); |
|
90 | - if(self::instance()->write_connection->query($query)) |
|
91 | - { |
|
92 | - self::instance()->log_query($query, $start); |
|
93 | - return true; |
|
94 | - } |
|
95 | - trigger_error('Could not preform query - ' . $query . '-' . self::instance()->write_connection->error); |
|
96 | - return false; |
|
97 | - } |
|
98 | - |
|
99 | - public static function lastInsertID() |
|
100 | - { |
|
101 | - $id = self::instance()->write_connection->insert_id; |
|
102 | - if($id == 0) |
|
103 | - return false; |
|
104 | - return $id; |
|
105 | - } |
|
106 | - |
|
107 | - private function log_query($query, $start) |
|
108 | - { |
|
109 | - $time = (microtime(true) - $start) * 1000; |
|
110 | - $query = array( |
|
111 | - 'sql' => $query, |
|
112 | - 'time' => $time); |
|
113 | - array_push($this->query_log, $query); |
|
55 | + return self::$instance; |
|
56 | + } |
|
57 | + |
|
58 | + public static function escape($string) |
|
59 | + { |
|
60 | + return self::instance()->read_connection->real_escape_string($string); |
|
61 | + } |
|
62 | + |
|
63 | + public static function select($query) |
|
64 | + { |
|
65 | + $start = microtime(true); |
|
66 | + if($result = self::instance()->read_connection->query($query)) |
|
67 | + { |
|
68 | + self::instance()->log_query($query, $start); |
|
69 | + $array = array(); |
|
70 | + while($row = $result->fetch_object()) |
|
71 | + $array[] = $row; |
|
72 | + $result->close(); |
|
73 | + return $array; |
|
74 | + } |
|
75 | + trigger_error('Could not preform query - ' . $query . ' - ' . self::instance()->read_connection->error); |
|
76 | + return false; |
|
77 | + } |
|
78 | + |
|
79 | + public static function selectRow($query) |
|
80 | + { |
|
81 | + $result = self::select($query); |
|
82 | + if(is_array($result)) |
|
83 | + return array_pop($result); |
|
84 | + return false; |
|
85 | + } |
|
86 | + |
|
87 | + public static function execute($query) |
|
88 | + { |
|
89 | + $start = microtime(true); |
|
90 | + if(self::instance()->write_connection->query($query)) |
|
91 | + { |
|
92 | + self::instance()->log_query($query, $start); |
|
93 | + return true; |
|
94 | + } |
|
95 | + trigger_error('Could not preform query - ' . $query . '-' . self::instance()->write_connection->error); |
|
96 | + return false; |
|
97 | + } |
|
98 | + |
|
99 | + public static function lastInsertID() |
|
100 | + { |
|
101 | + $id = self::instance()->write_connection->insert_id; |
|
102 | + if($id == 0) |
|
103 | + return false; |
|
104 | + return $id; |
|
105 | + } |
|
106 | + |
|
107 | + private function log_query($query, $start) |
|
108 | + { |
|
109 | + $time = (microtime(true) - $start) * 1000; |
|
110 | + $query = array( |
|
111 | + 'sql' => $query, |
|
112 | + 'time' => $time); |
|
113 | + array_push($this->query_log, $query); |
|
114 | 114 | |
115 | - $this->query_total['count']++; |
|
116 | - $this->query_total['time'] += $time; |
|
117 | - } |
|
118 | - |
|
119 | - private function gather_query_data() |
|
120 | - { |
|
121 | - $query_data = array(); |
|
122 | - foreach($this->query_log as $query) |
|
123 | - { |
|
124 | - $query = self::explain($query); |
|
125 | - $query_data[] = $query; |
|
126 | - } |
|
127 | - return $query_data; |
|
128 | - } |
|
129 | - |
|
130 | - public static function explain($query) |
|
131 | - { |
|
132 | - $sql = 'EXPLAIN ' . $query['sql']; |
|
115 | + $this->query_total['count']++; |
|
116 | + $this->query_total['time'] += $time; |
|
117 | + } |
|
118 | + |
|
119 | + private function gather_query_data() |
|
120 | + { |
|
121 | + $query_data = array(); |
|
122 | + foreach($this->query_log as $query) |
|
123 | + { |
|
124 | + $query = self::explain($query); |
|
125 | + $query_data[] = $query; |
|
126 | + } |
|
127 | + return $query_data; |
|
128 | + } |
|
129 | + |
|
130 | + public static function explain($query) |
|
131 | + { |
|
132 | + $sql = 'EXPLAIN ' . $query['sql']; |
|
133 | 133 | |
134 | - if($result = self::instance()->read_connection->query($sql)) |
|
135 | - { |
|
136 | - $row = $result->fetch_assoc(); |
|
137 | - $query['explain'] = $row; |
|
138 | - } |
|
134 | + if($result = self::instance()->read_connection->query($sql)) |
|
135 | + { |
|
136 | + $row = $result->fetch_assoc(); |
|
137 | + $query['explain'] = $row; |
|
138 | + } |
|
139 | 139 | |
140 | - return $query; |
|
141 | - } |
|
142 | - |
|
143 | - public static function getQueryLog() |
|
144 | - { |
|
145 | - return self::instance()->gather_query_data(); |
|
146 | - } |
|
147 | - |
|
148 | - public static function getQueryTotals() |
|
149 | - { |
|
150 | - return self::instance()->query_total; |
|
151 | - } |
|
152 | - |
|
153 | - public static function isConnected() |
|
154 | - { |
|
155 | - return !self::instance()->has_connection_error; |
|
156 | - } |
|
140 | + return $query; |
|
141 | + } |
|
142 | + |
|
143 | + public static function getQueryLog() |
|
144 | + { |
|
145 | + return self::instance()->gather_query_data(); |
|
146 | + } |
|
147 | + |
|
148 | + public static function getQueryTotals() |
|
149 | + { |
|
150 | + return self::instance()->query_total; |
|
151 | + } |
|
152 | + |
|
153 | + public static function isConnected() |
|
154 | + { |
|
155 | + return !self::instance()->has_connection_error; |
|
156 | + } |
|
157 | 157 | |
158 | 158 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -final class Database |
|
4 | -{ |
|
3 | +final class Database |
|
4 | +{ |
|
5 | 5 | |
6 | 6 | private $read_connection; |
7 | 7 | private $write_connection; |
@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | |
15 | 15 | private static $instance; |
16 | 16 | |
17 | - private function __construct($write_params, $read_params) |
|
18 | - { |
|
17 | + private function __construct($write_params, $read_params) |
|
18 | + { |
|
19 | 19 | $this->write_connection = $this->connect( |
20 | 20 | $write_params->host, |
21 | 21 | $write_params->user, |
@@ -31,19 +31,20 @@ discard block |
||
31 | 31 | return $this; |
32 | 32 | } |
33 | 33 | |
34 | - private function connect($host, $username, $password) |
|
35 | - { |
|
34 | + private function connect($host, $username, $password) |
|
35 | + { |
|
36 | 36 | $mysqli = new mysqli($host, $username, $password); |
37 | 37 | |
38 | 38 | $has_connection_error = $mysqli->connect_error; |
39 | - if(isset($has_connection_error)) |
|
40 | - $this->has_connection_error = true; |
|
39 | + if(isset($has_connection_error)) { |
|
40 | + $this->has_connection_error = true; |
|
41 | + } |
|
41 | 42 | |
42 | 43 | return $mysqli; |
43 | 44 | } |
44 | 45 | |
45 | - public static function instance() |
|
46 | - { |
|
46 | + public static function instance() |
|
47 | + { |
|
47 | 48 | if(!isset(self::$instance)) { |
48 | 49 | global $config; |
49 | 50 | self::$instance = new Database( |
@@ -55,20 +56,21 @@ discard block |
||
55 | 56 | return self::$instance; |
56 | 57 | } |
57 | 58 | |
58 | - public static function escape($string) |
|
59 | - { |
|
59 | + public static function escape($string) |
|
60 | + { |
|
60 | 61 | return self::instance()->read_connection->real_escape_string($string); |
61 | 62 | } |
62 | 63 | |
63 | - public static function select($query) |
|
64 | - { |
|
64 | + public static function select($query) |
|
65 | + { |
|
65 | 66 | $start = microtime(true); |
66 | 67 | if($result = self::instance()->read_connection->query($query)) |
67 | 68 | { |
68 | 69 | self::instance()->log_query($query, $start); |
69 | 70 | $array = array(); |
70 | - while($row = $result->fetch_object()) |
|
71 | - $array[] = $row; |
|
71 | + while($row = $result->fetch_object()) { |
|
72 | + $array[] = $row; |
|
73 | + } |
|
72 | 74 | $result->close(); |
73 | 75 | return $array; |
74 | 76 | } |
@@ -76,16 +78,17 @@ discard block |
||
76 | 78 | return false; |
77 | 79 | } |
78 | 80 | |
79 | - public static function selectRow($query) |
|
80 | - { |
|
81 | + public static function selectRow($query) |
|
82 | + { |
|
81 | 83 | $result = self::select($query); |
82 | - if(is_array($result)) |
|
83 | - return array_pop($result); |
|
84 | + if(is_array($result)) { |
|
85 | + return array_pop($result); |
|
86 | + } |
|
84 | 87 | return false; |
85 | 88 | } |
86 | 89 | |
87 | - public static function execute($query) |
|
88 | - { |
|
90 | + public static function execute($query) |
|
91 | + { |
|
89 | 92 | $start = microtime(true); |
90 | 93 | if(self::instance()->write_connection->query($query)) |
91 | 94 | { |
@@ -96,16 +99,17 @@ discard block |
||
96 | 99 | return false; |
97 | 100 | } |
98 | 101 | |
99 | - public static function lastInsertID() |
|
100 | - { |
|
102 | + public static function lastInsertID() |
|
103 | + { |
|
101 | 104 | $id = self::instance()->write_connection->insert_id; |
102 | - if($id == 0) |
|
103 | - return false; |
|
105 | + if($id == 0) { |
|
106 | + return false; |
|
107 | + } |
|
104 | 108 | return $id; |
105 | 109 | } |
106 | 110 | |
107 | - private function log_query($query, $start) |
|
108 | - { |
|
111 | + private function log_query($query, $start) |
|
112 | + { |
|
109 | 113 | $time = (microtime(true) - $start) * 1000; |
110 | 114 | $query = array( |
111 | 115 | 'sql' => $query, |
@@ -116,8 +120,8 @@ discard block |
||
116 | 120 | $this->query_total['time'] += $time; |
117 | 121 | } |
118 | 122 | |
119 | - private function gather_query_data() |
|
120 | - { |
|
123 | + private function gather_query_data() |
|
124 | + { |
|
121 | 125 | $query_data = array(); |
122 | 126 | foreach($this->query_log as $query) |
123 | 127 | { |
@@ -127,8 +131,8 @@ discard block |
||
127 | 131 | return $query_data; |
128 | 132 | } |
129 | 133 | |
130 | - public static function explain($query) |
|
131 | - { |
|
134 | + public static function explain($query) |
|
135 | + { |
|
132 | 136 | $sql = 'EXPLAIN ' . $query['sql']; |
133 | 137 | |
134 | 138 | if($result = self::instance()->read_connection->query($sql)) |
@@ -140,18 +144,18 @@ discard block |
||
140 | 144 | return $query; |
141 | 145 | } |
142 | 146 | |
143 | - public static function getQueryLog() |
|
144 | - { |
|
147 | + public static function getQueryLog() |
|
148 | + { |
|
145 | 149 | return self::instance()->gather_query_data(); |
146 | 150 | } |
147 | 151 | |
148 | - public static function getQueryTotals() |
|
149 | - { |
|
152 | + public static function getQueryTotals() |
|
153 | + { |
|
150 | 154 | return self::instance()->query_total; |
151 | 155 | } |
152 | 156 | |
153 | - public static function isConnected() |
|
154 | - { |
|
157 | + public static function isConnected() |
|
158 | + { |
|
155 | 159 | return !self::instance()->has_connection_error; |
156 | 160 | } |
157 | 161 |
@@ -48,11 +48,11 @@ |
||
48 | 48 | $recentPosts = $postRepository->getActivePosts(3); |
49 | 49 | |
50 | 50 | $recent_post_array = array(); |
51 | - foreach($recentPosts as $postResult) |
|
51 | + foreach ($recentPosts as $postResult) |
|
52 | 52 | { |
53 | 53 | $post = new stdclass(); |
54 | 54 | $post->title = $postResult['title']; |
55 | - $post->url = Loader::getRootUrl('blog') . "{$postResult['category']}/{$postResult['path']}/"; |
|
55 | + $post->url = Loader::getRootUrl('blog')."{$postResult['category']}/{$postResult['path']}/"; |
|
56 | 56 | $post->category = ucwords(str_replace('-', ' ', $postResult['category'])); |
57 | 57 | $post->thumb = Content::instance('FetchFirstPhoto', $postResult['body'])->activate(); |
58 | 58 | $post->body = Content::instance('SmartTrim', $postResult['body'])->activate(($post->thumb !== '') ? self::$POST_LENGTH_SHORT : self::$POST_LENGTH_LONG); |
@@ -8,58 +8,58 @@ |
||
8 | 8 | final class HomeController extends DefaultPageController |
9 | 9 | { |
10 | 10 | |
11 | - private static $TITLE = "Jacob Emerick's Home | Web Developer, Hiker, Innovator"; |
|
12 | - private static $DESCRIPTION = 'Home page for Jacob Emerick, with links to his blog, waterfall site, and other side projects'; |
|
11 | + private static $TITLE = "Jacob Emerick's Home | Web Developer, Hiker, Innovator"; |
|
12 | + private static $DESCRIPTION = 'Home page for Jacob Emerick, with links to his blog, waterfall site, and other side projects'; |
|
13 | 13 | |
14 | - private static $KEYWORD_ARRAY = array( |
|
15 | - 'Jacob Emerick', |
|
16 | - 'jacobemerick', |
|
17 | - 'jpemeric', |
|
18 | - 'home', |
|
19 | - 'web developer', |
|
20 | - 'hiker', |
|
21 | - 'application programmer', |
|
22 | - 'innovator'); |
|
14 | + private static $KEYWORD_ARRAY = array( |
|
15 | + 'Jacob Emerick', |
|
16 | + 'jacobemerick', |
|
17 | + 'jpemeric', |
|
18 | + 'home', |
|
19 | + 'web developer', |
|
20 | + 'hiker', |
|
21 | + 'application programmer', |
|
22 | + 'innovator'); |
|
23 | 23 | |
24 | - private static $POST_LENGTH_SHORT = 160; |
|
25 | - private static $POST_LENGTH_LONG = 240; |
|
24 | + private static $POST_LENGTH_SHORT = 160; |
|
25 | + private static $POST_LENGTH_LONG = 240; |
|
26 | 26 | |
27 | - protected function set_head_data() |
|
28 | - { |
|
29 | - $this->set_title(self::$TITLE); |
|
30 | - $this->set_description(self::$DESCRIPTION); |
|
31 | - $this->set_keywords(self::$KEYWORD_ARRAY); |
|
27 | + protected function set_head_data() |
|
28 | + { |
|
29 | + $this->set_title(self::$TITLE); |
|
30 | + $this->set_description(self::$DESCRIPTION); |
|
31 | + $this->set_keywords(self::$KEYWORD_ARRAY); |
|
32 | 32 | |
33 | - parent::set_head_data(); |
|
34 | - } |
|
33 | + parent::set_head_data(); |
|
34 | + } |
|
35 | 35 | |
36 | - protected function set_body_data() |
|
37 | - { |
|
38 | - $this->set_body('post_array', $this->get_recent_posts()); |
|
39 | - $this->set_body_view('Home'); |
|
36 | + protected function set_body_data() |
|
37 | + { |
|
38 | + $this->set_body('post_array', $this->get_recent_posts()); |
|
39 | + $this->set_body_view('Home'); |
|
40 | 40 | |
41 | - parent::set_body_data(); |
|
42 | - } |
|
41 | + parent::set_body_data(); |
|
42 | + } |
|
43 | 43 | |
44 | - private function get_recent_posts() |
|
45 | - { |
|
44 | + private function get_recent_posts() |
|
45 | + { |
|
46 | 46 | global $container; |
47 | 47 | $postRepository = new MysqlPostRepository($container['db_connection_locator']); |
48 | 48 | $recentPosts = $postRepository->getActivePosts(3); |
49 | 49 | |
50 | - $recent_post_array = array(); |
|
51 | - foreach($recentPosts as $postResult) |
|
52 | - { |
|
53 | - $post = new stdclass(); |
|
54 | - $post->title = $postResult['title']; |
|
55 | - $post->url = Loader::getRootUrl('blog') . "{$postResult['category']}/{$postResult['path']}/"; |
|
56 | - $post->category = ucwords(str_replace('-', ' ', $postResult['category'])); |
|
57 | - $post->thumb = Content::instance('FetchFirstPhoto', $postResult['body'])->activate(); |
|
58 | - $post->body = Content::instance('SmartTrim', $postResult['body'])->activate(($post->thumb !== '') ? self::$POST_LENGTH_SHORT : self::$POST_LENGTH_LONG); |
|
50 | + $recent_post_array = array(); |
|
51 | + foreach($recentPosts as $postResult) |
|
52 | + { |
|
53 | + $post = new stdclass(); |
|
54 | + $post->title = $postResult['title']; |
|
55 | + $post->url = Loader::getRootUrl('blog') . "{$postResult['category']}/{$postResult['path']}/"; |
|
56 | + $post->category = ucwords(str_replace('-', ' ', $postResult['category'])); |
|
57 | + $post->thumb = Content::instance('FetchFirstPhoto', $postResult['body'])->activate(); |
|
58 | + $post->body = Content::instance('SmartTrim', $postResult['body'])->activate(($post->thumb !== '') ? self::$POST_LENGTH_SHORT : self::$POST_LENGTH_LONG); |
|
59 | 59 | |
60 | - $recent_post_array[] = $post; |
|
61 | - } |
|
62 | - return $recent_post_array; |
|
63 | - } |
|
60 | + $recent_post_array[] = $post; |
|
61 | + } |
|
62 | + return $recent_post_array; |
|
63 | + } |
|
64 | 64 | |
65 | 65 | } |
@@ -5,8 +5,8 @@ discard block |
||
5 | 5 | Loader::load('controller', 'home/DefaultPageController'); |
6 | 6 | Loader::load('utility', 'Content'); |
7 | 7 | |
8 | -final class HomeController extends DefaultPageController |
|
9 | -{ |
|
8 | +final class HomeController extends DefaultPageController |
|
9 | +{ |
|
10 | 10 | |
11 | 11 | private static $TITLE = "Jacob Emerick's Home | Web Developer, Hiker, Innovator"; |
12 | 12 | private static $DESCRIPTION = 'Home page for Jacob Emerick, with links to his blog, waterfall site, and other side projects'; |
@@ -24,8 +24,8 @@ discard block |
||
24 | 24 | private static $POST_LENGTH_SHORT = 160; |
25 | 25 | private static $POST_LENGTH_LONG = 240; |
26 | 26 | |
27 | - protected function set_head_data() |
|
28 | - { |
|
27 | + protected function set_head_data() |
|
28 | + { |
|
29 | 29 | $this->set_title(self::$TITLE); |
30 | 30 | $this->set_description(self::$DESCRIPTION); |
31 | 31 | $this->set_keywords(self::$KEYWORD_ARRAY); |
@@ -33,16 +33,16 @@ discard block |
||
33 | 33 | parent::set_head_data(); |
34 | 34 | } |
35 | 35 | |
36 | - protected function set_body_data() |
|
37 | - { |
|
36 | + protected function set_body_data() |
|
37 | + { |
|
38 | 38 | $this->set_body('post_array', $this->get_recent_posts()); |
39 | 39 | $this->set_body_view('Home'); |
40 | 40 | |
41 | 41 | parent::set_body_data(); |
42 | 42 | } |
43 | 43 | |
44 | - private function get_recent_posts() |
|
45 | - { |
|
44 | + private function get_recent_posts() |
|
45 | + { |
|
46 | 46 | global $container; |
47 | 47 | $postRepository = new MysqlPostRepository($container['db_connection_locator']); |
48 | 48 | $recentPosts = $postRepository->getActivePosts(3); |
@@ -25,7 +25,7 @@ |
||
25 | 25 | { |
26 | 26 | $this->set_body('body_view', 'Resume'); |
27 | 27 | |
28 | - $resumePath = Loader::getRootURL('portfolio') . "/jsonresume/{$this->resume}"; |
|
28 | + $resumePath = Loader::getRootURL('portfolio')."/jsonresume/{$this->resume}"; |
|
29 | 29 | $resume = file_get_contents($resumePath); |
30 | 30 | $resume = json_decode($resume, true); |
31 | 31 | $this->set_body('body_data', $resume); |
@@ -2,13 +2,13 @@ discard block |
||
2 | 2 | |
3 | 3 | Loader::load('controller', 'portfolio/DefaultPageController'); |
4 | 4 | |
5 | -class ResumeController extends DefaultPageController |
|
6 | -{ |
|
5 | +class ResumeController extends DefaultPageController |
|
6 | +{ |
|
7 | 7 | |
8 | 8 | protected $resume = 'resume-20160318.json'; |
9 | 9 | |
10 | - protected function set_head_data() |
|
11 | - { |
|
10 | + protected function set_head_data() |
|
11 | + { |
|
12 | 12 | $this->set_title("Resume | Jacob Emerick's Portfolio"); |
13 | 13 | $this->set_description("Resume for Jacob Emerick, a software engineer extraordinaire"); |
14 | 14 | $this->set_keywords([ |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | ]); |
22 | 22 | } |
23 | 23 | |
24 | - protected function set_body_data() |
|
25 | - { |
|
24 | + protected function set_body_data() |
|
25 | + { |
|
26 | 26 | $this->set_body('body_view', 'Resume'); |
27 | 27 | |
28 | 28 | $resumePath = Loader::getRootURL('portfolio') . "/jsonresume/{$this->resume}"; |
@@ -89,7 +89,7 @@ |
||
89 | 89 | |
90 | 90 | return [ |
91 | 91 | 'success' => |
92 | - "Thank you for your message, {$_POST['name']}! " . |
|
92 | + "Thank you for your message, {$_POST['name']}! ". |
|
93 | 93 | "I'll get back to you as soon as possible." |
94 | 94 | ]; |
95 | 95 | } |
@@ -2,11 +2,11 @@ discard block |
||
2 | 2 | |
3 | 3 | Loader::load('controller', 'portfolio/DefaultPageController'); |
4 | 4 | |
5 | -class ContactController extends DefaultPageController |
|
6 | -{ |
|
5 | +class ContactController extends DefaultPageController |
|
6 | +{ |
|
7 | 7 | |
8 | - protected function set_head_data() |
|
9 | - { |
|
8 | + protected function set_head_data() |
|
9 | + { |
|
10 | 10 | $this->set_title("Contact Page | Jacob Emerick's Portfolio"); |
11 | 11 | $this->set_description("Contact page for Jacob Emerick's Portfolio"); |
12 | 12 | $this->set_keywords([ |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | ]); |
20 | 20 | } |
21 | 21 | |
22 | - protected function set_body_data() |
|
23 | - { |
|
22 | + protected function set_body_data() |
|
23 | + { |
|
24 | 24 | $this->set_body('body_view', 'Contact'); |
25 | 25 | |
26 | 26 | $body_data = []; |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | parent::set_body_data(); |
34 | 34 | } |
35 | 35 | |
36 | - private function process_form_data() |
|
37 | - { |
|
36 | + private function process_form_data() |
|
37 | + { |
|
38 | 38 | $errors = []; |
39 | 39 | |
40 | 40 | if ( |
@@ -33,15 +33,15 @@ discard block |
||
33 | 33 | ], |
34 | 34 | [ |
35 | 35 | 'name' => 'Projects', |
36 | - 'link' => Loader::getRootURL() . 'projects/', |
|
36 | + 'link' => Loader::getRootURL().'projects/', |
|
37 | 37 | ], |
38 | 38 | [ |
39 | 39 | 'name' => 'Résumé', |
40 | - 'link' => Loader::getRootURL() . 'resume/', |
|
40 | + 'link' => Loader::getRootURL().'resume/', |
|
41 | 41 | ], |
42 | 42 | [ |
43 | 43 | 'name' => 'Contact', |
44 | - 'link' => Loader::getRootURL() . 'contact/', |
|
44 | + 'link' => Loader::getRootURL().'contact/', |
|
45 | 45 | ], |
46 | 46 | ]; |
47 | 47 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $active_page = ucfirst(URLDecode::getPiece(1)); |
52 | 52 | } |
53 | 53 | |
54 | - return array_map(function ($row) use ($active_page) { |
|
54 | + return array_map(function($row) use ($active_page) { |
|
55 | 55 | $row = (object) $row; |
56 | 56 | $row->active = ($row->name == $active_page); |
57 | 57 | return $row; |
@@ -2,19 +2,19 @@ discard block |
||
2 | 2 | |
3 | 3 | Loader::load('controller', '/PageController'); |
4 | 4 | |
5 | -abstract class DefaultPageController extends PageController |
|
6 | -{ |
|
5 | +abstract class DefaultPageController extends PageController |
|
6 | +{ |
|
7 | 7 | |
8 | - public function __construct() |
|
9 | - { |
|
8 | + public function __construct() |
|
9 | + { |
|
10 | 10 | parent::__construct(); |
11 | 11 | |
12 | 12 | $this->add_css('reset'); |
13 | 13 | $this->add_css('portfolio', 4); |
14 | 14 | } |
15 | 15 | |
16 | - protected function set_body_data() |
|
17 | - { |
|
16 | + protected function set_body_data() |
|
17 | + { |
|
18 | 18 | $this->set_body('header_data', [ |
19 | 19 | 'menu' => $this->get_menu(), |
20 | 20 | 'home_link' => Loader::getRootURL(), |
@@ -24,8 +24,8 @@ discard block |
||
24 | 24 | $this->set_body_view('Page'); |
25 | 25 | } |
26 | 26 | |
27 | - protected function get_menu() |
|
28 | - { |
|
27 | + protected function get_menu() |
|
28 | + { |
|
29 | 29 | $menu = [ |
30 | 30 | [ |
31 | 31 | 'name' => 'About', |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace Jacobemerick\Web\Domain\Comment\Comment; |
4 | 4 | |
5 | -interface CommentRepositoryInterface |
|
6 | -{ |
|
5 | +interface CommentRepositoryInterface |
|
6 | +{ |
|
7 | 7 | public function createComment(array $comment); |
8 | 8 | public function getComment($commentId); |
9 | 9 | public function getComments($domain = null, $path = null, $page = null, $perPage = null, $order = null); |