| 1 |
<?php |
| 2 |
|
| 3 |
namespace Illuminate\Support\Defer; |
| 4 |
|
| 5 |
use Illuminate\Support\Str; |
| 6 |
|
| 7 |
class DeferredCallback |
| 8 |
{ |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
public function __construct(public $callback, public ?string $name = null, public bool $always = false) |
| 15 |
{ |
| 16 |
$this->name = $name ?? (string) Str::uuid(); |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public function name(string $name): static |
| 26 |
{ |
| 27 |
$this->name = $name; |
| 28 |
|
| 29 |
return $this; |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public function always(bool $always = true): static |
| 39 |
{ |
| 40 |
$this->always = $always; |
| 41 |
|
| 42 |
return $this; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function __invoke(): void |
| 51 |
{ |
| 52 |
call_user_func($this->callback); |
| 53 |
} |
| 54 |
} |