-
Notifications
You must be signed in to change notification settings - Fork 4
/
TaskIdentifier.php
52 lines (40 loc) · 1.3 KB
/
TaskIdentifier.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
<?php
namespace Thenpingme;
use Illuminate\Console\Scheduling\CallbackEvent;
use Illuminate\Console\Scheduling\Event;
use Illuminate\Support\Str;
class TaskIdentifier
{
const TYPE_CLOSURE = 'closure';
const TYPE_COMMAND = 'command';
const TYPE_JOB = 'job';
const TYPE_SHELL = 'shell';
public function __invoke($task)
{
if ($task instanceof CallbackEvent) {
if (Str::of($task->command)->isEmpty() && $task->description && class_exists($task->description)) {
return static::TYPE_JOB;
}
if (Str::of($task->command)->isEmpty() && Str::is($task->description, $task->getSummaryForDisplay())) {
return static::TYPE_CLOSURE;
}
if (in_array($task->getSummaryForDisplay(), ['Closure', 'Callback'])) {
return static::TYPE_CLOSURE;
}
}
if ($task instanceof Event) {
if (Str::contains($this->sanitisedCommand($task->command), 'artisan')) {
return static::TYPE_COMMAND;
}
return static::TYPE_SHELL;
}
}
private function sanitisedCommand(?string $command): string
{
return trim(str_replace([
"'",
'"',
PHP_BINARY,
], '', $command));
}
}