Debian Codegraph @

lib/3rdParty/composer/illuminate/support/Defer/DeferredCallback.php

raw symbols SCIP
1 <?php
2
3 namespace Illuminate\Support\Defer;
4
5 use Illuminate\Support\Str;
6
7 class DeferredCallback
8 {
9 /**
10 * Create a new deferred callback instance.
11 *
12 * @param callable $callback
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 * Specify the name of the deferred callback so it can be cancelled later.
21 *
22 * @param string $name
23 * @return $this
24 */
25 public function name(string $name): static
26 {
27 $this->name = $name;
28
29 return $this;
30 }
31
32 /**
33 * Indicate that the deferred callback should run even on unsuccessful requests and jobs.
34 *
35 * @param bool $always
36 * @return $this
37 */
38 public function always(bool $always = true): static
39 {
40 $this->always = $always;
41
42 return $this;
43 }
44
45 /**
46 * Invoke the deferred callback.
47 *
48 * @return void
49 */
50 public function __invoke(): void
51 {
52 call_user_func($this->callback);
53 }
54 }