-
Notifications
You must be signed in to change notification settings - Fork 11.1k
/
InvokeSerializedClosureCommand.php
63 lines (56 loc) · 1.67 KB
/
InvokeSerializedClosureCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace Illuminate\Concurrency\Console;
use Illuminate\Console\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Throwable;
#[AsCommand(name: 'invoke-serialized-closure')]
class InvokeSerializedClosureCommand extends Command
{
/**
* The console command signature.
*
* @var string
*/
protected $signature = 'invoke-serialized-closure {code? : The serialized closure}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Invoke the given serialized closure';
/**
* Indicates whether the command should be shown in the Artisan command list.
*
* @var bool
*/
protected $hidden = true;
/**
* Execute the console command.
*
* @return void
*
* @throws \RuntimeException
*/
public function handle()
{
try {
$this->output->write(json_encode([
'successful' => true,
'result' => serialize($this->laravel->call(match (true) {
! is_null($this->argument('code')) => unserialize($this->argument('code')),
isset($_SERVER['LARAVEL_INVOKABLE_CLOSURE']) => unserialize($_SERVER['LARAVEL_INVOKABLE_CLOSURE']),
default => fn () => null,
})),
]));
} catch (Throwable $e) {
report($e);
$this->output->write(json_encode([
'successful' => false,
'exception' => get_class($e),
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
]));
}
}
}