Skip to content

Commit 80cba82

Browse files
authored
Merge pull request #31 from nguyenanhung/v3.2.0-develop
V3.2.0 develop
2 parents 9b56b8f + 5305b27 commit 80cba82

File tree

4 files changed

+71
-36
lines changed

4 files changed

+71
-36
lines changed

helpers/common.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,35 @@ function bear_str_length($str)
3737
return strlen($str);
3838
}
3939
}
40+
if (!function_exists('__get_error_message__')) {
41+
/**
42+
* Function __get_error_message__
43+
*
44+
* @param \Exception|\Throwable $e
45+
*
46+
* @return string
47+
* @author : 713uk13m <dev@nguyenanhung.com>
48+
* @copyright: 713uk13m <dev@nguyenanhung.com>
49+
* @time : 29/03/2023 53:17
50+
*/
51+
function __get_error_message__($e)
52+
{
53+
return "Error Code: " . $e->getCode() . " - File: " . $e->getFile() . " - Line: " . $e->getLine() . " - Message: " . $e->getMessage();
54+
}
55+
}
56+
if (!function_exists('__get_error_trace__')) {
57+
/**
58+
* Function __get_error_trace__
59+
*
60+
* @param \Exception|\Throwable $e
61+
*
62+
* @return string
63+
* @author : 713uk13m <dev@nguyenanhung.com>
64+
* @copyright: 713uk13m <dev@nguyenanhung.com>
65+
* @time : 29/03/2023 53:48
66+
*/
67+
function __get_error_trace__($e)
68+
{
69+
return "Error Trace: " . $e->getTraceAsString();
70+
}
71+
}

hungng/HungNG_CI_Base_Controllers.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,8 @@ protected function jsonResponsePretty($response = array(), $status = 200)
205205
*/
206206
protected function errorExceptionResponse($exception)
207207
{
208-
$errorMessage = "Error Code: " . $exception->getCode() . " - Error File: " . $exception->getFile() . " - Error Line: " . $exception->getLine() . " - Error Message: " . $exception->getMessage();
209-
log_message('error', $errorMessage);
210-
log_message('error', $exception->getTraceAsString());
208+
log_message('error', __get_error_message__($exception));
209+
log_message('error', __get_error_trace__($exception));
211210

212211
$response = array();
213212
$response['code'] = StatusCodes::HTTP_BAD_REQUEST;
@@ -366,11 +365,11 @@ protected function log($name = '', $message = '', $context = array(), $inputLeve
366365
log_message($inputLevel, $name . " | Error Message: " . $message . ' | Context: ' . json_encode($context));
367366
}
368367
} catch (InvalidArgumentException $exception) {
369-
log_message('error', $exception->getMessage());
370-
log_message('error', $exception->getTraceAsString());
368+
log_message('error', __get_error_message__($exception));
369+
log_message('error', __get_error_trace__($exception));
371370
} catch (Exception $exception) {
372-
log_message('error', $exception->getMessage());
373-
log_message('error', $exception->getTraceAsString());
371+
log_message('error', __get_error_message__($exception));
372+
log_message('error', __get_error_trace__($exception));
374373
}
375374
}
376375

@@ -422,7 +421,7 @@ protected function default_base_flush_logs()
422421
$this->output->set_status_header()->set_content_type('application/json', 'utf-8')->set_output($output . PHP_EOL)->_display();
423422
exit;
424423
} catch (Exception $e) {
425-
$message = 'Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage();
424+
$message = __get_error_message__($e);
426425
log_message('error', $message);
427426
echo $message . PHP_EOL;
428427
exit;

hungng/HungNG_CI_Base_Module.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,8 @@ protected function jsonResponsePretty($response = array(), $status = 200)
205205
*/
206206
protected function errorExceptionResponse($exception)
207207
{
208-
$errorMessage = "Error Code: " . $exception->getCode() . " - Error File: " . $exception->getFile() . " - Error Line: " . $exception->getLine() . " - Error Message: " . $exception->getMessage();
209-
log_message('error', $errorMessage);
210-
log_message('error', $exception->getTraceAsString());
208+
log_message('error', __get_error_message__($exception));
209+
log_message('error', __get_error_trace__($exception));
211210

212211
$response = array();
213212
$response['code'] = StatusCodes::HTTP_BAD_REQUEST;
@@ -366,11 +365,11 @@ protected function log($name = '', $message = '', $context = array(), $inputLeve
366365
log_message($inputLevel, $name . " | Error Message: " . $message . ' | Context: ' . json_encode($context));
367366
}
368367
} catch (InvalidArgumentException $exception) {
369-
log_message('error', $exception->getMessage());
370-
log_message('error', $exception->getTraceAsString());
368+
log_message('error', __get_error_message__($exception));
369+
log_message('error', __get_error_trace__($exception));
371370
} catch (Exception $exception) {
372-
log_message('error', $exception->getMessage());
373-
log_message('error', $exception->getTraceAsString());
371+
log_message('error', __get_error_message__($exception));
372+
log_message('error', __get_error_trace__($exception));
374373
}
375374
}
376375

@@ -422,7 +421,7 @@ protected function default_base_flush_logs()
422421
$this->output->set_status_header()->set_content_type('application/json', 'utf-8')->set_output($output . PHP_EOL)->_display();
423422
exit;
424423
} catch (Exception $e) {
425-
$message = 'Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage();
424+
$message = __get_error_message__($e);
426425
log_message('error', $message);
427426
echo $message . PHP_EOL;
428427
exit;

system/core/Common.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
/**
5858
* Determines if the current version of PHP is equal to or greater than the supplied value
5959
*
60-
* @param string
60+
* @param string $version
6161
* @return bool TRUE if the current version is $version or higher
6262
*/
6363
function is_php($version)
@@ -112,7 +112,7 @@ function is_linux()
112112
* on Unix servers if safe_mode is on.
113113
*
114114
* @link https://bugs.php.net/bug.php?id=54709
115-
* @param string
115+
* @param string $file
116116
* @return bool
117117
*/
118118
function is_really_writable($file)
@@ -160,9 +160,9 @@ function is_really_writable($file)
160160
* exist it is instantiated and set to a static variable. If it has
161161
* previously been instantiated the variable is returned.
162162
*
163-
* @param string the class name being requested
164-
* @param string the directory where the class should be found
165-
* @param mixed an optional argument to pass to the class constructor
163+
* @param string $class the class name being requested
164+
* @param string $directory the directory where the class should be found
165+
* @param mixed $param an optional argument to pass to the class constructor
166166
* @return object
167167
*/
168168
function &load_class($class, $directory = 'libraries', $param = NULL)
@@ -233,7 +233,7 @@ function &load_class($class, $directory = 'libraries', $param = NULL)
233233
* Keeps track of which libraries have been loaded. This function is
234234
* called by the load_class() function above
235235
*
236-
* @param string
236+
* @param string $class
237237
* @return array
238238
*/
239239
function &is_loaded($class = '')
@@ -259,10 +259,10 @@ function &is_loaded($class = '')
259259
* This function lets us grab the config file even if the Config class
260260
* hasn't been instantiated yet
261261
*
262-
* @param array
262+
* @param array $replace
263263
* @return array
264264
*/
265-
function &get_config(Array $replace = array())
265+
function &get_config(array $replace = array())
266266
{
267267
static $config;
268268

@@ -314,7 +314,7 @@ function &get_config(Array $replace = array())
314314
/**
315315
* Returns the specified config item
316316
*
317-
* @param string
317+
* @param string $item
318318
* @return mixed
319319
*/
320320
function config_item($item)
@@ -427,9 +427,9 @@ function is_cli()
427427
* This function will send the error page directly to the
428428
* browser and exit.
429429
*
430-
* @param string
431-
* @param int
432-
* @param string
430+
* @param string $message
431+
* @param int|float $status_code
432+
* @param string $heading
433433
* @return void
434434
*/
435435
function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
@@ -462,8 +462,8 @@ function show_error($message, $status_code = 500, $heading = 'An Error Was Encou
462462
* However, instead of the standard error template it displays
463463
* 404 errors.
464464
*
465-
* @param string
466-
* @param bool
465+
* @param string $page
466+
* @param bool $log_error
467467
* @return void
468468
*/
469469
function show_404($page = '', $log_error = TRUE)
@@ -484,8 +484,8 @@ function show_404($page = '', $log_error = TRUE)
484484
* We use this as a simple mechanism to access the logging
485485
* class and send messages to be logged.
486486
*
487-
* @param string the error level: 'error', 'debug' or 'info'
488-
* @param string the error message
487+
* @param string $level the error level: 'error', 'debug' or 'info'
488+
* @param string $message the error message
489489
* @return void
490490
*/
491491
function log_message($level, $message)
@@ -498,6 +498,11 @@ function log_message($level, $message)
498498
$_log[0] =& load_class('Log', 'core');
499499
}
500500

501+
// 2023-03-29: In log_message - If message not string, force string with json_encode
502+
if (!is_string($message)) {
503+
$message = json_encode($message);
504+
}
505+
501506
$_log[0]->write_log($level, $message);
502507
}
503508
}
@@ -509,8 +514,8 @@ function log_message($level, $message)
509514
/**
510515
* Set HTTP Status Header
511516
*
512-
* @param int the status code
513-
* @param string
517+
* @param int $code the status code
518+
* @param string $text
514519
* @return void
515520
*/
516521
function set_status_header($code = 200, $text = '')
@@ -804,8 +809,8 @@ function html_escape($var, $double_encode = TRUE)
804809
* Helper function used to convert a string, array, or object
805810
* of attributes to a string.
806811
*
807-
* @param mixed string, array, object
808-
* @param bool
812+
* @param mixed $attributes string, array, object
813+
* @param bool $js
809814
* @return string
810815
*/
811816
function _stringify_attributes($attributes, $js = FALSE)

0 commit comments

Comments
 (0)