Skip to content

Commit 706192d

Browse files
Douglasdc3barryvdh
authored andcommitted
Fix call GateCollector using callback instead of array (barryvdh#867)
This fixes barryvdh#862 & barryvdh#863 Pre Laravel 5.7 the the `$gate->after` would not explicity check for optional / null. Laravel 5.7 the Gate class in Laravel will explicity check the callback signature this does not work with array arguments. Gate Class (Laravel 5.7) ```php protected function callbackAllowsGuests($callback) { $parameters = (new ReflectionFunction($callback))->getParameters(); return isset($parameters[0]) && $this->parameterAllowsGuests($parameters[0]); } ``` The `$callable` will be array as argument, The `ReflectionFunction` can only take callable argument. The reason we get this far into the code and is not cuaght by the Gate contract is the fact that the contract expects a `callable` type since an array is considered callable if you use a object reference as the first argument and string argument as second argument as method name. This is a bit of breaking change between Laravel 5.6 - Laravel 5.6. My fix is backwards compatible with Laravel 5.6.
1 parent 5b68f39 commit 706192d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/DataCollector/GateCollector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public function __construct(Gate $gate)
2020
{
2121
parent::__construct('gate');
2222
$this->setDataFormatter(new SimpleFormatter());
23-
$gate->after([$this, 'addCheck']);
23+
$gate->after(function (Authenticatable $user = null, $ability, $result, $arguments = []) {
24+
$this->addCheck($user, $ability, $result, $arguments);
25+
});
2426
}
2527

2628
public function addCheck(Authenticatable $user = null, $ability, $result, $arguments = [])

0 commit comments

Comments
 (0)