Skip to content

Commit

Permalink
Update shouldTransform functionality according to latest laravel chan…
Browse files Browse the repository at this point in the history
…ges (#35)

* Update shouldTransform functionality according to latest laravel changes

* Add the source of stubs package, as it's user was renamed

* Not working with travis, remove altogether
  • Loading branch information
specialtactics authored Nov 8, 2020
1 parent e912b36 commit 28f92e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"tymon/jwt-auth": "^1.0",
"illuminate/support": "^6 || ^5.8",
"webpatser/laravel-uuid": "^3.0",
"ramsey/uuid": "^3.0",
"atehnix/laravel-stubs": "~6.0"
"ramsey/uuid": "^3.0"
},
"require-dev": {
"ext-json": "*",
Expand Down
24 changes: 20 additions & 4 deletions src/Http/Controllers/Features/RestfulControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,28 @@ protected function isRequestBodyACollection(Request $request)
*/
protected function shouldTransform()
{
// If we are not called by this function, then we are not called by the router
if (debug_backtrace()[2]['function'] != 'call_user_func_array') {
return false;
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);

// We're going to check up to the top 20 calls (first 3-5 should be more than enough for almost any situation)
$numberOfCallsToCheck = 20;
$callsToCheck = [];

for ($i = 0; $i < sizeof($trace) && $numberOfCallsToCheck > 0; ++$i) {
// We only want function calls
if (array_key_exists('file', $trace[$i])) {
$callsToCheck[] = $trace[$i];
--$numberOfCallsToCheck;
}
}

return true;
// This should work for both the new and old scenarios
if (basename($callsToCheck[1]['file']) == 'Controller.php' &&
basename($callsToCheck[2]['file']) == 'ControllerDispatcher.php' &&
$callsToCheck[2]['function'] == 'callAction') {
return true;
}

return false;
}

/**
Expand Down

0 comments on commit 28f92e8

Please sign in to comment.