@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * Read JSON config file and return array |
54 | 54 | * |
55 | - * @param string $file |
|
55 | + * @param string $filename |
|
56 | 56 | * @return array $config |
57 | 57 | */ |
58 | 58 | public static function getConfigFile($filename) |
@@ -75,6 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | /** |
77 | 77 | * Get configuration |
78 | + * @param string $context |
|
78 | 79 | */ |
79 | 80 | public static function getConfig($name = 'application', $context = null) |
80 | 81 | { |
@@ -89,6 +90,7 @@ discard block |
||
89 | 90 | * Get the compiled application routes from the config files |
90 | 91 | * |
91 | 92 | * @todo cache the loaded/compiled routes |
93 | + * @param string $context |
|
92 | 94 | */ |
93 | 95 | public static function getRoutes($context = null) |
94 | 96 | { |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * Log Object |
18 | 18 | */ |
19 | - protected static $_logObject=null; // @todo get rid of this |
|
19 | + protected static $_logObject = null; // @todo get rid of this |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Serve your site |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public static function serve($context = null) |
28 | 28 | { |
29 | - if(empty($context)) |
|
29 | + if (empty($context)) |
|
30 | 30 | $context = getenv('ERDIKO_CONTEXT'); |
31 | 31 | |
32 | 32 | $routes = static::getRoutes($context); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public static function getConfig($name = 'application', $context = null) |
80 | 80 | { |
81 | - if($context == null) |
|
81 | + if ($context == null) |
|
82 | 82 | $context = getenv('ERDIKO_CONTEXT'); |
83 | 83 | |
84 | 84 | $filename = ERDIKO_APP."/config/{$context}/{$name}.json"; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public static function getRoutes($context = null) |
94 | 94 | { |
95 | - if($context == null) |
|
95 | + if ($context == null) |
|
96 | 96 | $context = getenv('ERDIKO_CONTEXT'); |
97 | 97 | $file = ERDIKO_APP."/config/{$context}/routes.json"; |
98 | 98 | $applicationConfig = static::getConfigFile($file); |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public static function sendEmail($toEmail, $subject, $body, $fromEmail) |
108 | 108 | { |
109 | - $headers = "From: $fromEmail\r\n" . |
|
110 | - "Reply-To: $fromEmail\r\n" . |
|
111 | - "X-Mailer: PHP/" . phpversion(); |
|
109 | + $headers = "From: $fromEmail\r\n". |
|
110 | + "Reply-To: $fromEmail\r\n". |
|
111 | + "X-Mailer: PHP/".phpversion(); |
|
112 | 112 | |
113 | 113 | return mail($toEmail, $subject, $body, $headers); |
114 | 114 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public static function log($level, $message, array $context = array()) |
129 | 129 | { |
130 | - if(static::$_logObject==null) |
|
130 | + if (static::$_logObject == null) |
|
131 | 131 | { |
132 | 132 | $erdikoContext = getenv('ERDIKO_CONTEXT'); |
133 | 133 | $config = static::getConfig("application", $erdikoContext); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | static::$_logObject = new \erdiko\core\Logger($logFiles, $logDir); |
138 | 138 | } |
139 | 139 | |
140 | - if(empty($level)) |
|
140 | + if (empty($level)) |
|
141 | 141 | $level = \Psr\Log\LogLevel::DEBUG; // Default to debug for convenience |
142 | 142 | |
143 | 143 | return static::$_logObject->log($level, $message, $context); |
@@ -26,8 +26,9 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public static function serve($context = null) |
28 | 28 | { |
29 | - if(empty($context)) |
|
30 | - $context = getenv('ERDIKO_CONTEXT'); |
|
29 | + if(empty($context)) { |
|
30 | + $context = getenv('ERDIKO_CONTEXT'); |
|
31 | + } |
|
31 | 32 | |
32 | 33 | $routes = static::getRoutes($context); |
33 | 34 | Toro::serve($routes); |
@@ -78,8 +79,9 @@ discard block |
||
78 | 79 | */ |
79 | 80 | public static function getConfig($name = 'application', $context = null) |
80 | 81 | { |
81 | - if($context == null) |
|
82 | - $context = getenv('ERDIKO_CONTEXT'); |
|
82 | + if($context == null) { |
|
83 | + $context = getenv('ERDIKO_CONTEXT'); |
|
84 | + } |
|
83 | 85 | |
84 | 86 | $filename = ERDIKO_APP."/config/{$context}/{$name}.json"; |
85 | 87 | return static::getConfigFile($filename); |
@@ -92,8 +94,9 @@ discard block |
||
92 | 94 | */ |
93 | 95 | public static function getRoutes($context = null) |
94 | 96 | { |
95 | - if($context == null) |
|
96 | - $context = getenv('ERDIKO_CONTEXT'); |
|
97 | + if($context == null) { |
|
98 | + $context = getenv('ERDIKO_CONTEXT'); |
|
99 | + } |
|
97 | 100 | $file = ERDIKO_APP."/config/{$context}/routes.json"; |
98 | 101 | $applicationConfig = static::getConfigFile($file); |
99 | 102 | |
@@ -137,8 +140,10 @@ discard block |
||
137 | 140 | static::$_logObject = new \erdiko\core\Logger($logFiles, $logDir); |
138 | 141 | } |
139 | 142 | |
140 | - if(empty($level)) |
|
141 | - $level = \Psr\Log\LogLevel::DEBUG; // Default to debug for convenience |
|
143 | + if(empty($level)) { |
|
144 | + $level = \Psr\Log\LogLevel::DEBUG; |
|
145 | + } |
|
146 | + // Default to debug for convenience |
|
142 | 147 | |
143 | 148 | return static::$_logObject->log($level, $message, $context); |
144 | 149 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @param string $level |
57 | 57 | * @param string or an object with a __toString() method$ message |
58 | 58 | * @param array $context |
59 | - * @return bool |
|
59 | + * @return integer |
|
60 | 60 | */ |
61 | 61 | public function log($level, $message, array $context = array()) |
62 | 62 | { |
@@ -92,7 +92,8 @@ discard block |
||
92 | 92 | * @param string $level |
93 | 93 | * @param string or an object with a __toString() method$ message |
94 | 94 | * @param array $context |
95 | - * @return bool |
|
95 | + * @param string $message |
|
96 | + * @return integer |
|
96 | 97 | */ |
97 | 98 | public function addRecord($level, $message, array $context = array()) |
98 | 99 | { |
@@ -110,7 +111,7 @@ discard block |
||
110 | 111 | * |
111 | 112 | * @param string $message or an object with a __toString() method |
112 | 113 | * @param array $context replacement values for placeholders |
113 | - * @return bool |
|
114 | + * @return string |
|
114 | 115 | */ |
115 | 116 | function interpolate($message, array $context = array()) |
116 | 117 | { |
@@ -134,7 +135,7 @@ discard block |
||
134 | 135 | * |
135 | 136 | * @param mixed $key |
136 | 137 | * @param string $logFileName |
137 | - * @return bool |
|
138 | + * @return string |
|
138 | 139 | */ |
139 | 140 | public function addLogFile($key, $logFileName) |
140 | 141 | { |
@@ -190,7 +191,7 @@ discard block |
||
190 | 191 | * @param string $message |
191 | 192 | * @param array $context |
192 | 193 | * |
193 | - * @return null |
|
194 | + * @return integer |
|
194 | 195 | */ |
195 | 196 | public function emergency($message, array $context = array()) |
196 | 197 | { |
@@ -207,7 +208,7 @@ discard block |
||
207 | 208 | * @param string $message |
208 | 209 | * @param array $context |
209 | 210 | * |
210 | - * @return null |
|
211 | + * @return integer |
|
211 | 212 | */ |
212 | 213 | public function alert($message, array $context = array()) |
213 | 214 | { |
@@ -223,7 +224,7 @@ discard block |
||
223 | 224 | * @param string $message |
224 | 225 | * @param array $context |
225 | 226 | * |
226 | - * @return null |
|
227 | + * @return integer |
|
227 | 228 | */ |
228 | 229 | public function critical($message, array $context = array()) |
229 | 230 | { |
@@ -238,7 +239,7 @@ discard block |
||
238 | 239 | * @param string $message |
239 | 240 | * @param array $context |
240 | 241 | * |
241 | - * @return null |
|
242 | + * @return integer |
|
242 | 243 | */ |
243 | 244 | public function error($message, array $context = array()) |
244 | 245 | { |
@@ -255,7 +256,7 @@ discard block |
||
255 | 256 | * @param string $message |
256 | 257 | * @param array $context |
257 | 258 | * |
258 | - * @return null |
|
259 | + * @return integer |
|
259 | 260 | */ |
260 | 261 | public function warning($message, array $context = array()) |
261 | 262 | { |
@@ -269,7 +270,7 @@ discard block |
||
269 | 270 | * @param string $message |
270 | 271 | * @param array $context |
271 | 272 | * |
272 | - * @return null |
|
273 | + * @return integer |
|
273 | 274 | */ |
274 | 275 | public function notice($message, array $context = array()) |
275 | 276 | { |
@@ -285,7 +286,7 @@ discard block |
||
285 | 286 | * @param string $message |
286 | 287 | * @param array $context |
287 | 288 | * |
288 | - * @return null |
|
289 | + * @return integer |
|
289 | 290 | */ |
290 | 291 | public function info($message, array $context = array()) |
291 | 292 | { |
@@ -299,7 +300,7 @@ discard block |
||
299 | 300 | * @param string $message |
300 | 301 | * @param array $context |
301 | 302 | * |
302 | - * @return null |
|
303 | + * @return integer |
|
303 | 304 | */ |
304 | 305 | public function debug($message, array $context = array()) |
305 | 306 | { |
@@ -26,6 +26,9 @@ |
||
26 | 26 | $instance->hooks[$hook_name][] = $fn; |
27 | 27 | } |
28 | 28 | |
29 | + /** |
|
30 | + * @param string $hook_name |
|
31 | + */ |
|
29 | 32 | public static function fire($hook_name, $params = null) |
30 | 33 | { |
31 | 34 | $instance = static::get_instance(); |
@@ -14,73 +14,73 @@ |
||
14 | 14 | |
15 | 15 | class ErrorHandler |
16 | 16 | { |
17 | - public static function init() |
|
18 | - { |
|
19 | - ini_set('html_errors',0); // @todo review this line |
|
20 | - // error_reporting((E_ALL | E_STRICT)); // @note we shouldn't override by default, but we could inject |
|
21 | - set_error_handler("\\erdiko\\core\\ErrorHandler::errorHandler"); |
|
22 | - register_shutdown_function("\\erdiko\\core\\ErrorHandler::fatalErrorShutdownHandler"); |
|
23 | - } |
|
17 | + public static function init() |
|
18 | + { |
|
19 | + ini_set('html_errors',0); // @todo review this line |
|
20 | + // error_reporting((E_ALL | E_STRICT)); // @note we shouldn't override by default, but we could inject |
|
21 | + set_error_handler("\\erdiko\\core\\ErrorHandler::errorHandler"); |
|
22 | + register_shutdown_function("\\erdiko\\core\\ErrorHandler::fatalErrorShutdownHandler"); |
|
23 | + } |
|
24 | 24 | |
25 | - public static function errorHandler($errno, $errstr, $errfile, $errline) |
|
26 | - { |
|
27 | - $debug = \erdiko\core\ErrorHandler::isDebug(); |
|
28 | - if ( ! ( error_reporting() & $errno ) || empty( $errstr ) ) { |
|
29 | - return null; |
|
30 | - } |
|
25 | + public static function errorHandler($errno, $errstr, $errfile, $errline) |
|
26 | + { |
|
27 | + $debug = \erdiko\core\ErrorHandler::isDebug(); |
|
28 | + if ( ! ( error_reporting() & $errno ) || empty( $errstr ) ) { |
|
29 | + return null; |
|
30 | + } |
|
31 | 31 | |
32 | 32 | $errorHook = "500"; |
33 | 33 | |
34 | - switch ( $errno ) { |
|
35 | - case E_USER_ERROR: |
|
36 | - $vars['msg_type'] = "USER ERROR"; |
|
37 | - $vars['msg_description'] = " Fatal error in line $errline of $errfile file"; |
|
38 | - $vars['msg_description'] .= ", PHP " . PHP_VERSION . " (" . PHP_OS . ")"; |
|
39 | - break; |
|
34 | + switch ( $errno ) { |
|
35 | + case E_USER_ERROR: |
|
36 | + $vars['msg_type'] = "USER ERROR"; |
|
37 | + $vars['msg_description'] = " Fatal error in line $errline of $errfile file"; |
|
38 | + $vars['msg_description'] .= ", PHP " . PHP_VERSION . " (" . PHP_OS . ")"; |
|
39 | + break; |
|
40 | 40 | |
41 | - case E_USER_WARNING: |
|
42 | - $vars['msg_type'] = "USER WARNING"; |
|
43 | - break; |
|
41 | + case E_USER_WARNING: |
|
42 | + $vars['msg_type'] = "USER WARNING"; |
|
43 | + break; |
|
44 | 44 | |
45 | - case E_USER_NOTICE: |
|
46 | - $vars['msg_type'] = "USER NOTICE"; |
|
47 | - break; |
|
45 | + case E_USER_NOTICE: |
|
46 | + $vars['msg_type'] = "USER NOTICE"; |
|
47 | + break; |
|
48 | 48 | |
49 | - case E_ERROR: |
|
50 | - $vars['msg_type'] = "ERROR"; |
|
51 | - $vars['msg_description'] = print_r(debug_backtrace(),1); |
|
52 | - break; |
|
49 | + case E_ERROR: |
|
50 | + $vars['msg_type'] = "ERROR"; |
|
51 | + $vars['msg_description'] = print_r(debug_backtrace(),1); |
|
52 | + break; |
|
53 | 53 | |
54 | - default: |
|
55 | - $vars['msg_type'] = "Type of error: [$errno] $errstr"; |
|
56 | - $vars['msg_description'] = print_r(debug_backtrace(),1); |
|
57 | - break; |
|
58 | - } |
|
54 | + default: |
|
55 | + $vars['msg_type'] = "Type of error: [$errno] $errstr"; |
|
56 | + $vars['msg_description'] = print_r(debug_backtrace(),1); |
|
57 | + break; |
|
58 | + } |
|
59 | 59 | |
60 | - $vars['code'] = $errno; |
|
61 | - $vars['error'] = trim($errstr); |
|
62 | - $vars['path_info'] = $errfile . " on line " . $errline; |
|
63 | - $vars['debug'] = $debug; |
|
60 | + $vars['code'] = $errno; |
|
61 | + $vars['error'] = trim($errstr); |
|
62 | + $vars['path_info'] = $errfile . " on line " . $errline; |
|
63 | + $vars['debug'] = $debug; |
|
64 | 64 | |
65 | - ToroHook::fire($errorHook, $vars ); |
|
65 | + ToroHook::fire($errorHook, $vars ); |
|
66 | 66 | |
67 | - return false; |
|
68 | - } |
|
67 | + return false; |
|
68 | + } |
|
69 | 69 | |
70 | - public static function fatalErrorShutdownHandler() |
|
71 | - { |
|
72 | - $last_error = error_get_last(); |
|
73 | - static::errorHandler(E_ERROR, |
|
74 | - $last_error['message'], $last_error['file'], $last_error['line']); |
|
75 | - } |
|
70 | + public static function fatalErrorShutdownHandler() |
|
71 | + { |
|
72 | + $last_error = error_get_last(); |
|
73 | + static::errorHandler(E_ERROR, |
|
74 | + $last_error['message'], $last_error['file'], $last_error['line']); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * isDebug |
|
79 | - * |
|
80 | - * @return bool |
|
81 | - */ |
|
82 | - public static function isDebug() |
|
83 | - { |
|
84 | - return (getenv("ERDIKO_DEBUG")=='1'); |
|
85 | - } |
|
77 | + /** |
|
78 | + * isDebug |
|
79 | + * |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | + public static function isDebug() |
|
83 | + { |
|
84 | + return (getenv("ERDIKO_DEBUG")=='1'); |
|
85 | + } |
|
86 | 86 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | { |
17 | 17 | public static function init() |
18 | 18 | { |
19 | - ini_set('html_errors',0); // @todo review this line |
|
19 | + ini_set('html_errors', 0); // @todo review this line |
|
20 | 20 | // error_reporting((E_ALL | E_STRICT)); // @note we shouldn't override by default, but we could inject |
21 | 21 | set_error_handler("\\erdiko\\core\\ErrorHandler::errorHandler"); |
22 | 22 | register_shutdown_function("\\erdiko\\core\\ErrorHandler::fatalErrorShutdownHandler"); |
@@ -25,17 +25,17 @@ discard block |
||
25 | 25 | public static function errorHandler($errno, $errstr, $errfile, $errline) |
26 | 26 | { |
27 | 27 | $debug = \erdiko\core\ErrorHandler::isDebug(); |
28 | - if ( ! ( error_reporting() & $errno ) || empty( $errstr ) ) { |
|
28 | + if (!(error_reporting() & $errno) || empty($errstr)) { |
|
29 | 29 | return null; |
30 | 30 | } |
31 | 31 | |
32 | 32 | $errorHook = "500"; |
33 | 33 | |
34 | - switch ( $errno ) { |
|
34 | + switch ($errno) { |
|
35 | 35 | case E_USER_ERROR: |
36 | 36 | $vars['msg_type'] = "USER ERROR"; |
37 | 37 | $vars['msg_description'] = " Fatal error in line $errline of $errfile file"; |
38 | - $vars['msg_description'] .= ", PHP " . PHP_VERSION . " (" . PHP_OS . ")"; |
|
38 | + $vars['msg_description'] .= ", PHP ".PHP_VERSION." (".PHP_OS.")"; |
|
39 | 39 | break; |
40 | 40 | |
41 | 41 | case E_USER_WARNING: |
@@ -48,21 +48,21 @@ discard block |
||
48 | 48 | |
49 | 49 | case E_ERROR: |
50 | 50 | $vars['msg_type'] = "ERROR"; |
51 | - $vars['msg_description'] = print_r(debug_backtrace(),1); |
|
51 | + $vars['msg_description'] = print_r(debug_backtrace(), 1); |
|
52 | 52 | break; |
53 | 53 | |
54 | 54 | default: |
55 | 55 | $vars['msg_type'] = "Type of error: [$errno] $errstr"; |
56 | - $vars['msg_description'] = print_r(debug_backtrace(),1); |
|
56 | + $vars['msg_description'] = print_r(debug_backtrace(), 1); |
|
57 | 57 | break; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $vars['code'] = $errno; |
61 | 61 | $vars['error'] = trim($errstr); |
62 | - $vars['path_info'] = $errfile . " on line " . $errline; |
|
63 | - $vars['debug'] = $debug; |
|
62 | + $vars['path_info'] = $errfile." on line ".$errline; |
|
63 | + $vars['debug'] = $debug; |
|
64 | 64 | |
65 | - ToroHook::fire($errorHook, $vars ); |
|
65 | + ToroHook::fire($errorHook, $vars); |
|
66 | 66 | |
67 | 67 | return false; |
68 | 68 | } |
@@ -81,6 +81,6 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public static function isDebug() |
83 | 83 | { |
84 | - return (getenv("ERDIKO_DEBUG")=='1'); |
|
84 | + return (getenv("ERDIKO_DEBUG") == '1'); |
|
85 | 85 | } |
86 | 86 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | // Search through routes and find first match |
50 | 50 | foreach ($routes as $pattern => $handler_name) { |
51 | 51 | $patternRep = strtr($pattern, $tokens); |
52 | - if (preg_match('#^/?' . $patternRep . '/?$#', $path_info, $matches)) { |
|
52 | + if (preg_match('#^/?'.$patternRep.'/?$#', $path_info, $matches)) { |
|
53 | 53 | $discovered_handler = $handler_name; |
54 | 54 | $regex_matches = $matches; |
55 | 55 | $params = isset($regex_matches[1]) ? explode("/", $regex_matches[1]) : array(); |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | if ($handler_instance) { |
91 | - if (static::is_xhr_request() && method_exists($handler_instance, $action . '_xhr')) { |
|
91 | + if (static::is_xhr_request() && method_exists($handler_instance, $action.'_xhr')) { |
|
92 | 92 | header('Content-type: application/json'); // @todo support xml |
93 | 93 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
94 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
94 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); |
|
95 | 95 | header('Cache-Control: no-store, no-cache, must-revalidate'); |
96 | 96 | header('Cache-Control: post-check=0, pre-check=0', false); |
97 | 97 | header("Access-Control-Allow-Origin: *"); // @todo make this a parameter? |