1
|
|
|
<?php |
2
|
|
|
namespace agoalofalife\bpm\Actions; |
3
|
|
|
|
4
|
|
|
use agoalofalife\bpm\Assistants\ConstructorUrl; |
5
|
|
|
use agoalofalife\bpm\Assistants\VerifyValues; |
6
|
|
|
use agoalofalife\bpm\Contracts\Action; |
7
|
|
|
use agoalofalife\bpm\Contracts\ActionGet; |
8
|
|
|
use agoalofalife\bpm\Contracts\Authentication; |
9
|
|
|
use agoalofalife\bpm\KernelBpm; |
10
|
|
|
use GuzzleHttp\ClientInterface; |
11
|
|
|
use GuzzleHttp\Exception\ClientException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Delete |
15
|
|
|
* @property KernelBpm kernel |
16
|
|
|
* @property string HTTP_TYPE |
17
|
|
|
* @property string url |
18
|
|
|
* @property array data |
19
|
|
|
* @package agoalofalife\bpm\Actions |
20
|
|
|
*/ |
21
|
|
|
class Delete implements Action, ActionGet |
22
|
|
|
{ |
23
|
|
|
use ConstructorUrl; |
24
|
|
|
|
25
|
|
|
protected $kernel; |
26
|
|
|
protected $url = '?'; |
27
|
|
|
protected $data = []; |
28
|
|
|
/** |
29
|
|
|
* Type of Request to delete |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $HTTP_TYPE = 'DELETE'; |
33
|
|
|
|
34
|
|
|
public function injectionKernel(KernelBpm $bpm) |
35
|
|
|
{ |
36
|
|
|
$this->kernel = $bpm; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
public function getUrl() |
43
|
|
|
{ |
44
|
|
|
return $this->url; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return \agoalofalife\bpm\Contracts\Handler |
49
|
|
|
*/ |
50
|
|
|
public function processData() |
51
|
|
|
{ |
52
|
|
|
$this->query(); |
53
|
|
|
return $this->kernel->getHandler(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return array |
58
|
|
|
*/ |
59
|
|
|
public function getData() |
60
|
|
|
{ |
61
|
|
|
return $this->getData(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
private function query() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$parameters = str_replace(' ', '%20', $this->url); |
67
|
|
|
|
68
|
|
|
$url = $this->kernel->getCollection() . $parameters; |
69
|
|
|
$client = app()->make(ClientInterface::class); |
70
|
|
|
$urlHome = config($this->kernel->getPrefixConfig() . '.UrlHome'); |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
try { |
74
|
|
|
$response = $client->request($this->HTTP_TYPE, $urlHome . $url, |
75
|
|
|
[ |
76
|
|
|
'headers' => [ |
77
|
|
|
'HTTP/1.0', |
78
|
|
|
'Accept' => $this->kernel->getHandler()->getAccept(), |
79
|
|
|
'Content-type' => $this->kernel->getHandler()->getContentType(), |
80
|
|
|
// app()->make(Authentication::class)->getPrefixCSRF() => app()->make(Authentication::class)->getCsrf(), |
|
|
|
|
81
|
|
|
], |
82
|
|
|
'curl' => [ |
83
|
|
|
CURLOPT_COOKIEFILE => app()->make(Authentication::class)->getPathCookieFile(), |
84
|
|
|
] |
85
|
|
|
]); |
86
|
|
|
|
87
|
|
|
$body = $response->getBody(); |
88
|
|
|
$this->kernel->getHandler()->parse($body->getContents()); |
89
|
|
|
} catch (ClientException $e) { |
90
|
|
|
|
91
|
|
|
if ($e->getResponse()->getStatusCode() == 401 && $e->getResponse()->getReasonPhrase() == 'Unauthorized') |
92
|
|
|
{ |
93
|
|
|
$this->kernel->authentication(); |
94
|
|
|
return $this->query(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.