|
3 | 3 | namespace Gregurco\Bundle\GuzzleBundleCachePlugin\Event;
|
4 | 4 |
|
5 | 5 | use Psr\Http\Message\UriInterface;
|
6 |
| -use Symfony\Component\EventDispatcher\Event as BaseEvent; |
7 |
| -use Symfony\Component\EventDispatcher\EventDispatcher; |
8 |
| -use Symfony\Contracts\EventDispatcher\Event as ContractsBaseEvent; |
9 |
| -use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
| 6 | +use Symfony\Contracts\EventDispatcher\Event; |
10 | 7 | use GuzzleHttp\Client;
|
11 | 8 | use GuzzleHttp\Psr7;
|
12 | 9 | use GuzzleHttp\Psr7\Request;
|
13 | 10 |
|
14 |
| -if (is_subclass_of(EventDispatcher::class, EventDispatcherInterface::class)) { |
15 |
| - class InvalidateRequestEvent extends ContractsBaseEvent |
16 |
| - { |
17 |
| - /** @var Client */ |
18 |
| - protected $client; |
19 |
| - |
20 |
| - /** @var string */ |
21 |
| - protected $method; |
22 |
| - |
23 |
| - /** @var string */ |
24 |
| - protected $uri; |
25 |
| - |
26 |
| - /** |
27 |
| - * @param Client $client |
28 |
| - * @param string $method |
29 |
| - * @param string $uri |
30 |
| - */ |
31 |
| - public function __construct(Client $client, string $method, string $uri) |
32 |
| - { |
33 |
| - $this->client = $client; |
34 |
| - $this->method = $method; |
35 |
| - $this->uri = $uri; |
36 |
| - } |
37 |
| - |
38 |
| - /** |
39 |
| - * @return Client |
40 |
| - */ |
41 |
| - public function getClient(): Client |
42 |
| - { |
43 |
| - return $this->client; |
44 |
| - } |
| 11 | +class InvalidateRequestEvent extends Event |
| 12 | +{ |
| 13 | + /** @var Client */ |
| 14 | + protected $client; |
45 | 15 |
|
46 |
| - /** |
47 |
| - * @return string |
48 |
| - */ |
49 |
| - public function getMethod(): string |
50 |
| - { |
51 |
| - return $this->method; |
52 |
| - } |
53 |
| - |
54 |
| - /** |
55 |
| - * @return string |
56 |
| - */ |
57 |
| - public function getUri(): string |
58 |
| - { |
59 |
| - return $this->uri; |
60 |
| - } |
61 |
| - |
62 |
| - /** |
63 |
| - * @return Request |
64 |
| - */ |
65 |
| - public function getRequest(): Request |
66 |
| - { |
67 |
| - $baseUri = $this->client->getConfig('base_uri'); |
| 16 | + /** @var string */ |
| 17 | + protected $method; |
68 | 18 |
|
69 |
| - if ($baseUri instanceof UriInterface) { |
70 |
| - $uri = Psr7\UriResolver::resolve($baseUri, Psr7\Utils::uriFor($this->uri)); |
71 |
| - } else { |
72 |
| - $uri = $this->uri; |
73 |
| - } |
| 19 | + /** @var string */ |
| 20 | + protected $uri; |
74 | 21 |
|
75 |
| - return new Request($this->method, $uri); |
76 |
| - } |
77 |
| - } |
78 |
| -} else { |
79 |
| - class InvalidateRequestEvent extends BaseEvent |
| 22 | + /** |
| 23 | + * @param Client $client |
| 24 | + * @param string $method |
| 25 | + * @param string $uri |
| 26 | + */ |
| 27 | + public function __construct(Client $client, string $method, string $uri) |
80 | 28 | {
|
81 |
| - /** @var Client */ |
82 |
| - protected $client; |
83 |
| - |
84 |
| - /** @var string */ |
85 |
| - protected $method; |
| 29 | + $this->client = $client; |
| 30 | + $this->method = $method; |
| 31 | + $this->uri = $uri; |
| 32 | + } |
86 | 33 |
|
87 |
| - /** @var string */ |
88 |
| - protected $uri; |
| 34 | + /** |
| 35 | + * @return Client |
| 36 | + */ |
| 37 | + public function getClient(): Client |
| 38 | + { |
| 39 | + return $this->client; |
| 40 | + } |
89 | 41 |
|
90 |
| - /** |
91 |
| - * @param Client $client |
92 |
| - * @param string $method |
93 |
| - * @param string $uri |
94 |
| - */ |
95 |
| - public function __construct(Client $client, string $method, string $uri) |
96 |
| - { |
97 |
| - $this->client = $client; |
98 |
| - $this->method = $method; |
99 |
| - $this->uri = $uri; |
100 |
| - } |
| 42 | + /** |
| 43 | + * @return string |
| 44 | + */ |
| 45 | + public function getMethod(): string |
| 46 | + { |
| 47 | + return $this->method; |
| 48 | + } |
101 | 49 |
|
102 |
| - /** |
103 |
| - * @return Client |
104 |
| - */ |
105 |
| - public function getClient(): Client |
106 |
| - { |
107 |
| - return $this->client; |
108 |
| - } |
| 50 | + /** |
| 51 | + * @return string |
| 52 | + */ |
| 53 | + public function getUri(): string |
| 54 | + { |
| 55 | + return $this->uri; |
| 56 | + } |
109 | 57 |
|
110 |
| - /** |
111 |
| - * @return string |
112 |
| - */ |
113 |
| - public function getMethod(): string |
114 |
| - { |
115 |
| - return $this->method; |
116 |
| - } |
| 58 | + /** |
| 59 | + * @return Request |
| 60 | + */ |
| 61 | + public function getRequest(): Request |
| 62 | + { |
| 63 | + $baseUri = $this->client->getConfig('base_uri'); |
117 | 64 |
|
118 |
| - /** |
119 |
| - * @return string |
120 |
| - */ |
121 |
| - public function getUri(): string |
122 |
| - { |
123 |
| - return $this->uri; |
| 65 | + if ($baseUri instanceof UriInterface) { |
| 66 | + $uri = Psr7\UriResolver::resolve($baseUri, Psr7\Utils::uriFor($this->uri)); |
| 67 | + } else { |
| 68 | + $uri = $this->uri; |
124 | 69 | }
|
125 | 70 |
|
126 |
| - /** |
127 |
| - * @return Request |
128 |
| - */ |
129 |
| - public function getRequest(): Request |
130 |
| - { |
131 |
| - $baseUri = $this->client->getConfig('base_uri'); |
132 |
| - |
133 |
| - if ($baseUri instanceof UriInterface) { |
134 |
| - $uri = Psr7\UriResolver::resolve($baseUri, Psr7\Utils::uriFor($this->uri)); |
135 |
| - } else { |
136 |
| - $uri = $this->uri; |
137 |
| - } |
138 |
| - |
139 |
| - return new Request($this->method, $uri); |
140 |
| - } |
| 71 | + return new Request($this->method, $uri); |
141 | 72 | }
|
142 | 73 | }
|
0 commit comments