From 13b9dc5653754938cf220a820bd0b36f03470cdd Mon Sep 17 00:00:00 2001 From: Jose M Date: Fri, 12 Sep 2014 17:10:04 +0200 Subject: [PATCH 1/2] Check value in str_limit function Server variables integer (REQUEST_TIME_FLOAT) or arrays throw errors --- src/Modules/Request/default.blade.php | 8 ++++---- src/helpers.php | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Modules/Request/default.blade.php b/src/Modules/Request/default.blade.php index dc8afc2..0b46293 100644 --- a/src/Modules/Request/default.blade.php +++ b/src/Modules/Request/default.blade.php @@ -12,7 +12,7 @@ @foreach($request as $key => $value) {{ $key }} - {{ str_limit($value) }} + {{ anbu_str_limit($value) }} @endforeach @@ -34,7 +34,7 @@ @foreach($requestHeaders as $key => $value) {{ $key }} - {{ str_limit($value[0]) }} + {{ anbu_str_limit($value[0]) }} @endforeach @@ -56,7 +56,7 @@ @foreach($responseHeaders as $key => $value) {{ $key }} - {{ str_limit($value[0]) }} + {{ anbu_str_limit($value[0]) }} @endforeach @@ -78,7 +78,7 @@ @foreach($server as $key => $value) {{ $key }} - {{ str_limit($value) }} + {{ anbu_str_limit($value) }} @endforeach diff --git a/src/helpers.php b/src/helpers.php index 0d3db98..40f5407 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -10,3 +10,25 @@ function ad($value) { app('Anbu\\Profiler')->getModule('debug')->debug($value); } } + +if ( ! function_exists('anbu_str_limit')) +{ + // str_limit() function with some checks + function anbu_str_limit($value) + { + // when value not is null or empty + if ( ! is_null($value) && $value !== '') + { + if (is_string($value)) + { + return str_limit($value); + } + + // when is a object or array + return json_encode($value); + } + + // when no data in value + return 'No data'; + } +} From 5da53530fd74d381d6349cce8042a872c71f19dc Mon Sep 17 00:00:00 2001 From: Jose M Date: Sun, 14 Sep 2014 00:06:09 +0200 Subject: [PATCH 2/2] No convert to json int and float values --- src/helpers.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/helpers.php b/src/helpers.php index 40f5407..d2d0181 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -19,13 +19,20 @@ function anbu_str_limit($value) // when value not is null or empty if ( ! is_null($value) && $value !== '') { - if (is_string($value)) + $data = $value; + + // to json (object or array) + if (is_array($value) || is_object($value)) + { + $data = json_encode($value); + } + // to string (int, float, etc) + elseif ( ! is_string($value)) { - return str_limit($value); + $data = (string) $value; } - // when is a object or array - return json_encode($value); + return str_limit($data); } // when no data in value