aungwinthant / apilogger

Small laravel package for viewing api logs which can be used in debugging.
MIT License
346 stars 61 forks source link

Issue 8 - Undefined Offset Bug (for Single Action Controllers/Closures). #9

Closed lloy0076 closed 4 years ago

lloy0076 commented 4 years ago

If given a single action controller of closure, the previous code would unceremoniously crash with an "Undefined offset: 1" error (see Issue #8).

This handles the $currentRouteAction differently in that:

  1. If we can split it by @ we do and it will behave as before;
  2. If we cannot, we'll check if $currentRouteAction is a string and if, and only if it is, we'll set the $controller to empty and the current action as the value of $currentAction - this is not necessarily ideal but it is better than crashing;
  3. If it's something else entirely we will use json_encode and set the current action to be that value.

We could probably tell if $currentAction is a closure and/or a single action controller BUT the main goal of this commit is to stop crashing.

I have tested it on Laravel 6.X.

Resolved #8.

lloy0076 commented 4 years ago

In the absence of automated tests, I can see (which I wouldn't be able to see if the bug was still present):

Screenshot_2019-09-30 Laravel Six

lloy0076 commented 4 years ago

@aungwinthant CONFOUND - I was cowboy coding and took out some code that should be there.