1
|
|
|
<?php |
2
|
|
|
namespace agoalofalife\bpm\Actions; |
3
|
|
|
|
4
|
|
|
use agoalofalife\bpm\Assistants\ConstructorUrl; |
5
|
|
|
use agoalofalife\bpm\Assistants\QueryBuilder; |
6
|
|
|
use agoalofalife\bpm\Contracts\Action; |
7
|
|
|
use agoalofalife\bpm\Contracts\ActionGet; |
8
|
|
|
use agoalofalife\bpm\KernelBpm; |
9
|
|
|
use Assert\Assert; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Read |
14
|
|
|
* @property KernelBpm $kernel |
15
|
|
|
* @property string $HTTP_TYPE GET | POST | PUT | DELETE |
16
|
|
|
* @property string $url |
17
|
|
|
* @uses ConstructorUrl trait |
18
|
|
|
* @package agoalofalife\bpm\Actions |
19
|
|
|
*/ |
20
|
|
|
class Read implements Action, ActionGet |
21
|
|
|
{ |
22
|
|
|
use ConstructorUrl, QueryBuilder; |
23
|
|
|
|
24
|
|
|
protected $kernel; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Type HTTP_TYPE select |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $HTTP_TYPE = 'GET'; |
31
|
|
|
|
32
|
|
|
protected $url = '?'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param KernelBpm $bpm |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
1 |
|
public function injectionKernel(KernelBpm $bpm) |
39
|
|
|
{ |
40
|
1 |
|
$this->kernel = $bpm; |
41
|
1 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return string url |
45
|
|
|
*/ |
46
|
6 |
|
public function getUrl() |
47
|
|
|
{ |
48
|
6 |
|
return $this->url; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return array url -> string , http_type -> string |
53
|
|
|
*/ |
54
|
|
|
public function processData() |
55
|
|
|
{ |
56
|
|
|
$this->getData(); |
57
|
|
|
return $this->kernel->getHandler(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getData() |
61
|
|
|
{ |
62
|
|
|
$this->query(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Request the type of filter |
67
|
|
|
* Design filterConstructor allows you to build logical expressions the conditions selecting the desired object . |
68
|
|
|
* Expressions filterConstructor can be used to reference the properties and literals , |
69
|
|
|
* as well as strings, numbers and Boolean expressions (true, false). |
70
|
|
|
* Expressions $ filter supports arithmetic , logical operations , and operations groups , |
71
|
|
|
* strings , date and time of the operation. |
72
|
|
|
* @documentation |
73
|
|
|
* @param $strRequest |
74
|
|
|
* @return $this |
75
|
|
|
*/ |
76
|
1 |
|
public function filterConstructor($strRequest) |
77
|
|
|
{ |
78
|
1 |
|
$ParameterQuery = '$filter='; |
79
|
1 |
|
$ParameterQuery.= $strRequest; |
80
|
1 |
|
$this->concatenationUrlCurl($ParameterQuery); |
81
|
1 |
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Service resources can be obtained in the form of sort . |
86
|
|
|
* asc ascending |
87
|
|
|
* desc descending |
88
|
|
|
* @param string $whatSort |
89
|
|
|
* @param string $param asc | desc |
90
|
|
|
* @return $this |
91
|
|
|
* @throws \Exception |
92
|
|
|
*/ |
93
|
2 |
|
public function orderBy($whatSort, $param = 'asc') |
94
|
|
|
{ |
95
|
2 |
|
$ParameterQuery = '$orderby='; |
96
|
2 |
|
$ParameterQuery.= ucfirst($whatSort); |
97
|
|
|
|
98
|
2 |
|
if ( empty($param) === false ) { |
99
|
2 |
|
if ($param != 'desc' && $param != 'asc') { |
100
|
1 |
|
throw new \Exception('no valid orderby parameters'); |
101
|
|
|
} |
102
|
1 |
|
$ParameterQuery.= " ".$param; |
103
|
1 |
|
} |
104
|
1 |
|
$this->concatenationUrlCurl($ParameterQuery); |
105
|
|
|
|
106
|
1 |
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* In bpm'online support the use of parameter $ the skip , |
111
|
|
|
* which allows you to query the service resources , |
112
|
|
|
* skipping the specified number of entries. |
113
|
|
|
* @param $skip |
114
|
|
|
* @return $this |
115
|
|
|
*/ |
116
|
2 |
|
public function skip($skip) |
117
|
|
|
{ |
118
|
2 |
|
Assert::that($skip, 'You must specify a numeric parameter for the amount of the method')->integer(); |
119
|
1 |
|
$ParameterQuery = '$skip='.$skip; |
120
|
1 |
|
$this->concatenationUrlCurl($ParameterQuery); |
121
|
|
|
|
122
|
1 |
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Restrictions in the sample query |
127
|
|
|
* If you want the request to return more than 40 records at a time, it can be implemented using the parameter $ top |
128
|
|
|
* @param $amountMax |
129
|
|
|
* @return $this |
130
|
|
|
*/ |
131
|
2 |
|
public function amount($amountMax = null) |
132
|
|
|
{ |
133
|
2 |
|
Assert::that($amountMax,'You must specify a numeric parameter for the amount of the method')->integer(); |
134
|
1 |
|
$ParameterQuery = '$top='.$amountMax; |
135
|
1 |
|
$this->concatenationUrlCurl($ParameterQuery); |
136
|
1 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* TODO Requires refactoring of this method |
141
|
|
|
* @return void |
142
|
|
|
*/ |
143
|
|
|
private function query() |
144
|
|
|
{ |
145
|
|
|
$parameters = str_replace(' ', '%20', $this->url); |
146
|
|
|
$url = $this->kernel->getCollection() . $parameters; |
147
|
|
|
$urlHome = config($this->kernel->getPrefixConfig() . '.UrlHome'); |
148
|
|
|
|
149
|
|
|
$response = $this->kernel->getCurl()->request($this->HTTP_TYPE, $urlHome . $url, |
150
|
|
|
$this->debug()->headers()->getCookie()->httpErrorsFalse()->get() |
151
|
|
|
); |
152
|
|
|
$body = $response->getBody(); |
153
|
|
|
|
154
|
|
|
$this->kernel->getHandler()->parse($body->getContents()); |
|
|
|
|
155
|
|
|
|
156
|
|
|
if ( $response->getStatusCode() == 401 && $response->getReasonPhrase() == 'Unauthorized' ) |
157
|
|
|
{ |
158
|
|
|
$this->kernel->authentication(); |
159
|
|
|
$this->query(); |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.