|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Zenstruck\ScheduleBundle\Schedule\Extension; |
|
4
|
|
|
|
|
5
|
|
|
use Zenstruck\ScheduleBundle\Schedule; |
|
6
|
|
|
use Zenstruck\ScheduleBundle\Schedule\HasMissingDependencyMessage; |
|
7
|
|
|
use Zenstruck\ScheduleBundle\Schedule\Task; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @author Kevin Bond <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
final class PingExtension implements HasMissingDependencyMessage |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var string */ |
|
15
|
|
|
private $hook; |
|
16
|
|
|
|
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
private $url; |
|
19
|
|
|
|
|
20
|
|
|
/** @var string */ |
|
21
|
|
|
private $method; |
|
22
|
5 |
|
|
|
23
|
|
|
/** @var array */ |
|
24
|
5 |
|
private $options; |
|
25
|
5 |
|
|
|
26
|
5 |
|
/** |
|
27
|
5 |
|
* @param array $options See HttpClientInterface::OPTIONS_DEFAULTS |
|
28
|
5 |
|
*/ |
|
29
|
|
|
private function __construct(string $hook, string $url, string $method = 'GET', array $options = []) |
|
30
|
2 |
|
{ |
|
31
|
|
|
$this->hook = $hook; |
|
32
|
2 |
|
$this->url = $url; |
|
33
|
|
|
$this->method = $method; |
|
34
|
|
|
$this->options = $options; |
|
35
|
2 |
|
} |
|
36
|
|
|
|
|
37
|
2 |
|
public function __toString(): string |
|
38
|
|
|
{ |
|
39
|
|
|
return "{$this->hook}, ping \"{$this->url}\""; |
|
40
|
2 |
|
} |
|
41
|
|
|
|
|
42
|
2 |
|
public function getHook(): string |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->hook; |
|
45
|
2 |
|
} |
|
46
|
|
|
|
|
47
|
2 |
|
public function getUrl(): string |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->url; |
|
50
|
2 |
|
} |
|
51
|
|
|
|
|
52
|
2 |
|
public function getMethod(): string |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->method; |
|
55
|
2 |
|
} |
|
56
|
|
|
|
|
57
|
2 |
|
public function getOptions(): array |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->options; |
|
60
|
3 |
|
} |
|
61
|
|
|
|
|
62
|
3 |
|
public static function getMissingDependencyMessage(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return 'Symfony HttpClient is required to use the ping extension. Install with "composer require symfony/http-client".'; |
|
65
|
3 |
|
} |
|
66
|
|
|
|
|
67
|
3 |
|
public static function taskBefore(string $url, string $method = 'GET', array $options = []): self |
|
68
|
|
|
{ |
|
69
|
|
|
return new self(Task::BEFORE, $url, $method, $options); |
|
70
|
3 |
|
} |
|
71
|
|
|
|
|
72
|
3 |
|
public static function taskAfter(string $url, string $method = 'GET', array $options = []): self |
|
73
|
|
|
{ |
|
74
|
|
|
return new self(Task::AFTER, $url, $method, $options); |
|
75
|
5 |
|
} |
|
76
|
|
|
|
|
77
|
5 |
|
public static function taskSuccess(string $url, string $method = 'GET', array $options = []): self |
|
78
|
|
|
{ |
|
79
|
|
|
return new self(Task::SUCCESS, $url, $method, $options); |
|
80
|
2 |
|
} |
|
81
|
|
|
|
|
82
|
2 |
|
public static function taskFailure(string $url, string $method = 'GET', array $options = []): self |
|
83
|
|
|
{ |
|
84
|
|
|
return new self(Task::FAILURE, $url, $method, $options); |
|
85
|
2 |
|
} |
|
86
|
|
|
|
|
87
|
2 |
|
public static function scheduleBefore(string $url, string $method = 'GET', array $options = []): self |
|
88
|
|
|
{ |
|
89
|
|
|
return new self(Schedule::BEFORE, $url, $method, $options); |
|
90
|
2 |
|
} |
|
91
|
|
|
|
|
92
|
2 |
|
public static function scheduleAfter(string $url, string $method = 'GET', array $options = []): self |
|
93
|
|
|
{ |
|
94
|
|
|
return new self(Schedule::AFTER, $url, $method, $options); |
|
95
|
2 |
|
} |
|
96
|
|
|
|
|
97
|
2 |
|
public static function scheduleSuccess(string $url, string $method = 'GET', array $options = []): self |
|
98
|
|
|
{ |
|
99
|
|
|
return new self(Schedule::SUCCESS, $url, $method, $options); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public static function scheduleFailure(string $url, string $method = 'GET', array $options = []): self |
|
103
|
|
|
{ |
|
104
|
|
|
return new self(Schedule::FAILURE, $url, $method, $options); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|