Skip to content

Commit 8d8d620

Browse files
committed
refactoring closure reflection
1 parent 35a7883 commit 8d8d620

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/Illuminate/Console/Scheduling/Event.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
use Illuminate\Support\Carbon;
1414
use Illuminate\Support\Facades\Date;
1515
use Illuminate\Support\Traits\Macroable;
16+
use Illuminate\Support\Traits\ReflectsClosures;
1617
use Psr\Http\Client\ClientExceptionInterface;
1718
use Symfony\Component\Process\Process;
1819

1920
class Event
2021
{
21-
use Macroable, ManagesFrequencies;
22+
use Macroable, ManagesFrequencies, ReflectsClosures;
2223

2324
/**
2425
* The command string.
@@ -812,12 +813,12 @@ public function onFailureWithOutput(Closure $callback, $onlyIfOutputExists = fal
812813
*/
813814
protected function withOutputCallback(Closure $callback, $onlyIfOutputExists = false)
814815
{
815-
return function () use ($callback, $onlyIfOutputExists) {
816+
return function (Container $container) use ($callback, $onlyIfOutputExists) {
816817
$output = $this->output && file_exists($this->output) ? file_get_contents($this->output) : '';
817818

818819
return $onlyIfOutputExists && empty($output)
819820
? null
820-
: $callback($output);
821+
: $container->call($callback, ['output' => $output]);
821822
};
822823
}
823824

src/Illuminate/Support/Traits/ReflectsClosures.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ protected function closureParameterTypes(Closure $closure)
2121
{
2222
$reflection = new ReflectionFunction($closure);
2323

24-
return array_map(function (ReflectionParameter $parameter) {
24+
return collect($reflection->getParameters())->mapWithKeys(function ($parameter) {
2525
if ($parameter->isVariadic()) {
26-
return;
26+
return [$parameter->getName() => null];
2727
}
2828

29-
return $parameter->getClass()->name ?? null;
30-
}, $reflection->getParameters());
29+
return [$parameter->getName() => $parameter->getClass()->name ?? null];
30+
})->all();
3131
}
3232

3333
/**
@@ -40,7 +40,7 @@ protected function closureParameterTypes(Closure $closure)
4040
*/
4141
protected function firstClosureParameterType(Closure $closure)
4242
{
43-
$types = $this->closureParameterTypes($closure);
43+
$types = array_values($this->closureParameterTypes($closure));
4444

4545
if (! $types) {
4646
throw new RuntimeException('The given Closure has no parameters.');

tests/Support/SupportReflectsClosuresTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ReflectsClosuresClass
7878

7979
public static function reflect($closure)
8080
{
81-
return (new static)->closureParameterTypes($closure);
81+
return array_values((new static)->closureParameterTypes($closure));
8282
}
8383

8484
public static function reflectFirst($closure)

0 commit comments

Comments
 (0)