@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | * @throws ReflectionExceptionAlias |
| 70 | 70 | */ |
| 71 | - public function __construct($clientData=null) |
|
| 71 | + public function __construct($clientData = null) |
|
| 72 | 72 | {
|
| 73 | 73 | //reflection process |
| 74 | 74 | $this->reflection = app()['reflection']($this); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | $this->setClientName(); |
| 78 | 78 | |
| 79 | 79 | //get http method via request http manager class |
| 80 | - $this->requestHttp = app()->resolve(ClientHttpManager::class,['client'=>$this]); |
|
| 80 | + $this->requestHttp = app()->resolve(ClientHttpManager::class, ['client'=>$this]); |
|
| 81 | 81 | |
| 82 | 82 | //get request client data |
| 83 | 83 | $this->clientData = ($clientData===null) ? $this->requestHttp->resolve() : $clientData; |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | private function autoValidate($validate) |
| 95 | 95 | {
|
| 96 | 96 | //we get the values to auto-validate. |
| 97 | - foreach ($this->{$validate} as $object=>$datas){
|
|
| 97 | + foreach ($this->{$validate} as $object=>$datas) {
|
|
| 98 | 98 | |
| 99 | - if(false===Utils::isNamespaceExists($object)){
|
|
| 99 | + if (false===Utils::isNamespaceExists($object)) {
|
|
| 100 | 100 | return; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -106,15 +106,15 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | // we get the index values, |
| 108 | 108 | // which are called methods of the auto-validate value that represents the class. |
| 109 | - foreach ($datas as $dataKey=>$data){
|
|
| 109 | + foreach ($datas as $dataKey=>$data) {
|
|
| 110 | 110 | |
| 111 | 111 | // if the methods of the auto-validate class resolved by the container resolve method apply, |
| 112 | 112 | // the process of auto-validate automatic implementation will be completed. |
| 113 | - if(is_numeric($dataKey) && method_exists($getObjectInstance,$data) && isset($this->origin[$data])){
|
|
| 114 | - if(!is_array($this->origin[$data])){
|
|
| 113 | + if (is_numeric($dataKey) && method_exists($getObjectInstance, $data) && isset($this->origin[$data])) {
|
|
| 114 | + if (!is_array($this->origin[$data])) {
|
|
| 115 | 115 | $this->origin[$data] = array($this->origin[$data]); |
| 116 | 116 | } |
| 117 | - foreach ($this->origin[$data] as $originData){
|
|
| 117 | + foreach ($this->origin[$data] as $originData) {
|
|
| 118 | 118 | $getObjectInstance->{$data}($originData);
|
| 119 | 119 | } |
| 120 | 120 | } |
@@ -130,22 +130,22 @@ discard block |
||
| 130 | 130 | private function capsule() |
| 131 | 131 | {
|
| 132 | 132 | //a process can be added to the capsule array using the method. |
| 133 | - if(method_exists($this,'capsuleMethod')){
|
|
| 134 | - $this->capsule = array_merge($this->capsule,$this->capsuleMethod()); |
|
| 133 | + if (method_exists($this, 'capsuleMethod')) {
|
|
| 134 | + $this->capsule = array_merge($this->capsule, $this->capsuleMethod()); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // expected method is executed. |
| 138 | 138 | // this method is a must for http method values to be found in this property. |
| 139 | - if($this->checkProperties('capsule')){
|
|
| 139 | + if ($this->checkProperties('capsule')) {
|
|
| 140 | 140 | |
| 141 | - if(property_exists($this,'auto_capsule') && is_array($this->auto_capsule)){
|
|
| 142 | - $this->capsule = array_merge($this->capsule,$this->auto_capsule); |
|
| 141 | + if (property_exists($this, 'auto_capsule') && is_array($this->auto_capsule)) {
|
|
| 142 | + $this->capsule = array_merge($this->capsule, $this->auto_capsule); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - foreach($this->inputs as $input=>$value){
|
|
| 145 | + foreach ($this->inputs as $input=>$value) {
|
|
| 146 | 146 | |
| 147 | - if($this->checkProperties('capsule') && !in_array($input,$this->capsule)){
|
|
| 148 | - exception('clientCapsule',['key'=>$input])
|
|
| 147 | + if ($this->checkProperties('capsule') && !in_array($input, $this->capsule)) {
|
|
| 148 | + exception('clientCapsule', ['key'=>$input])
|
|
| 149 | 149 | ->overflow('The '.$input.' value cannot be sent.');
|
| 150 | 150 | } |
| 151 | 151 | } |
@@ -164,15 +164,15 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | // Determines which HTTP method |
| 166 | 166 | // the request object will be exposed to. |
| 167 | - if($this->checkProperties('http')){
|
|
| 167 | + if ($this->checkProperties('http')) {
|
|
| 168 | 168 | |
| 169 | 169 | // if the current http method does not exist |
| 170 | 170 | // in the http object, the exception will be thrown. |
| 171 | - if(!in_array($method,$this->http)){
|
|
| 171 | + if (!in_array($method, $this->http)) {
|
|
| 172 | 172 | |
| 173 | 173 | //exception batMethodCall |
| 174 | 174 | exception()->badMethodCall( |
| 175 | - 'Invalid http method process for '.basename($this).'.That is accepted http methods ['.implode(",",$this->http).'] ');
|
|
| 175 | + 'Invalid http method process for '.basename($this).'.That is accepted http methods ['.implode(",", $this->http).'] ');
|
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | {
|
| 188 | 188 | // from the properties of the object properties to |
| 189 | 189 | // the existing variables, control the array and at least one element. |
| 190 | - return (property_exists($this,$properties) |
|
| 190 | + return (property_exists($this, $properties) |
|
| 191 | 191 | && is_array($this->{$properties}) && count($this->{$properties})) ? true : false;
|
| 192 | 192 | } |
| 193 | 193 | |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | {
|
| 201 | 201 | // we are saving the expected values for the request in container. |
| 202 | 202 | // this record can be returned in exception information. |
| 203 | - app()->register('requestExpected',$this->expected);
|
|
| 203 | + app()->register('requestExpected', $this->expected);
|
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -212,15 +212,15 @@ discard block |
||
| 212 | 212 | public function except($except) |
| 213 | 213 | {
|
| 214 | 214 | // the except parameter is a callable value. |
| 215 | - if(is_callable($except)){
|
|
| 216 | - $call = call_user_func_array($except,[$this]); |
|
| 215 | + if (is_callable($except)) {
|
|
| 216 | + $call = call_user_func_array($except, [$this]); |
|
| 217 | 217 | $except = $call; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | // except with the except exceptions property |
| 221 | 221 | // and then assigning them to the inputs property. |
| 222 | - $this->except = array_merge($this->except,$except); |
|
| 223 | - $this->inputs = array_diff_key($this->inputs,array_flip($this->except)); |
|
| 222 | + $this->except = array_merge($this->except, $except); |
|
| 223 | + $this->inputs = array_diff_key($this->inputs, array_flip($this->except)); |
|
| 224 | 224 | |
| 225 | 225 | return $this; |
| 226 | 226 | } |
@@ -234,27 +234,27 @@ discard block |
||
| 234 | 234 | {
|
| 235 | 235 | // expected method is executed. |
| 236 | 236 | // this method is a must for http method values to be found in this property. |
| 237 | - if($this->checkProperties('expected')){
|
|
| 237 | + if ($this->checkProperties('expected')) {
|
|
| 238 | 238 | |
| 239 | 239 | // if the expected values are not found in the inputs array, |
| 240 | 240 | // the exception will be thrown. |
| 241 | - foreach ($this->expected as $expected){
|
|
| 241 | + foreach ($this->expected as $expected) {
|
|
| 242 | 242 | |
| 243 | 243 | $expectedValues = []; |
| 244 | 244 | |
| 245 | 245 | // mandatory expected data for each key can be separated by | operator. |
| 246 | 246 | // this is evaluated as "or". |
| 247 | - foreach($expectedData = explode("|",$expected) as $inputs){
|
|
| 248 | - if(!isset($this->inputs[$inputs])){
|
|
| 247 | + foreach ($expectedData = explode("|", $expected) as $inputs) {
|
|
| 248 | + if (!isset($this->inputs[$inputs])) {
|
|
| 249 | 249 | $expectedValues[$inputs] = $inputs; |
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | // if the expectedData and expectedValues |
| 254 | 254 | // array are numerically equal to the expected key, the exception is thrown. |
| 255 | - if(count($expectedData)===count($expectedValues)){
|
|
| 256 | - exception('clientExpected',(count($expectedValues)) ? $expectedValues : ['key'=>$expected])
|
|
| 257 | - ->unexpectedValue('You absolutely have to send the value '.implode(" or ",$expectedValues).' for request object');
|
|
| 255 | + if (count($expectedData)===count($expectedValues)) {
|
|
| 256 | + exception('clientExpected', (count($expectedValues)) ? $expectedValues : ['key'=>$expected])
|
|
| 257 | + ->unexpectedValue('You absolutely have to send the value '.implode(" or ", $expectedValues).' for request object');
|
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | } |
@@ -269,17 +269,17 @@ discard block |
||
| 269 | 269 | {
|
| 270 | 270 | // check the presence of the generator object |
| 271 | 271 | // and operate the generator over this object. |
| 272 | - if($this->checkProperties('auto_generators')){
|
|
| 272 | + if ($this->checkProperties('auto_generators')) {
|
|
| 273 | 273 | $generators = $this->getAutoGenerators(); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // check the presence of the generator object |
| 277 | 277 | // and operate the generator over this object. |
| 278 | - if($this->checkProperties('generators')){
|
|
| 279 | - $generators = array_merge(isset($generators) ? $generators: [],$this->getGenerators()); |
|
| 278 | + if ($this->checkProperties('generators')) {
|
|
| 279 | + $generators = array_merge(isset($generators) ? $generators : [], $this->getGenerators()); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - if(isset($generators)){
|
|
| 282 | + if (isset($generators)) {
|
|
| 283 | 283 | $this->generatorMethod($generators); |
| 284 | 284 | } |
| 285 | 285 | } |
@@ -294,21 +294,21 @@ discard block |
||
| 294 | 294 | private function generatorMethod($generators) |
| 295 | 295 | {
|
| 296 | 296 | //generator array object |
| 297 | - foreach ($generators as $generator){
|
|
| 297 | + foreach ($generators as $generator) {
|
|
| 298 | 298 | |
| 299 | 299 | //generator method name |
| 300 | 300 | $generatorMethodName = $generator.'Generator'; |
| 301 | 301 | |
| 302 | 302 | // if the generator method is present, |
| 303 | 303 | // the fake value is assigned. |
| 304 | - if(method_exists($this,$generatorMethodName)){
|
|
| 304 | + if (method_exists($this, $generatorMethodName)) {
|
|
| 305 | 305 | |
| 306 | 306 | //fake registration |
| 307 | - if(!isset($this->inputs[$generator])){
|
|
| 307 | + if (!isset($this->inputs[$generator])) {
|
|
| 308 | 308 | |
| 309 | 309 | $generatorMethodNameResult = $this->{$generatorMethodName}();
|
| 310 | 310 | |
| 311 | - if(!is_null($generatorMethodNameResult)){
|
|
| 311 | + if (!is_null($generatorMethodNameResult)) {
|
|
| 312 | 312 | $this->{$generator} = $this->{$generatorMethodName}();
|
| 313 | 313 | $this->inputs[$generator] = $this->{$generatorMethodName}();
|
| 314 | 314 | $this->generatorList[] = $generator; |
@@ -316,15 +316,15 @@ discard block |
||
| 316 | 316 | } |
| 317 | 317 | else {
|
| 318 | 318 | |
| 319 | - if($this->checkProperties('auto_generators_dont_overwrite')
|
|
| 320 | - && in_array($generator,$this->getAutoGeneratorsDontOverwrite())){
|
|
| 319 | + if ($this->checkProperties('auto_generators_dont_overwrite')
|
|
| 320 | + && in_array($generator, $this->getAutoGeneratorsDontOverwrite())) {
|
|
| 321 | 321 | $this->{$generator} = $this->{$generatorMethodName}();
|
| 322 | 322 | $this->inputs[$generator] = $this->{$generatorMethodName}();
|
| 323 | 323 | $this->generatorList[] = $generator; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - if($this->checkProperties('generators_dont_overwrite')
|
|
| 327 | - && in_array($generator,$this->getGeneratorsDontOverwrite())){
|
|
| 326 | + if ($this->checkProperties('generators_dont_overwrite')
|
|
| 327 | + && in_array($generator, $this->getGeneratorsDontOverwrite())) {
|
|
| 328 | 328 | $this->{$generator} = $this->{$generatorMethodName}();
|
| 329 | 329 | $this->inputs[$generator] = $this->{$generatorMethodName}();
|
| 330 | 330 | $this->generatorList[] = $generator; |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | {
|
| 388 | 388 | // we use the http method to write |
| 389 | 389 | // the values to the inputs and origin properties. |
| 390 | - foreach($this->clientData as $key=>$value){
|
|
| 390 | + foreach ($this->clientData as $key=>$value) {
|
|
| 391 | 391 | |
| 392 | 392 | //inputs and origin properties |
| 393 | 393 | $this->inputs[$key] = $value; |
@@ -403,9 +403,9 @@ discard block |
||
| 403 | 403 | */ |
| 404 | 404 | private function requestExcept() |
| 405 | 405 | {
|
| 406 | - if(property_exists($this,'requestExcept') && is_array($this->requestExcept)){
|
|
| 407 | - foreach ($this->requestExcept as $item){
|
|
| 408 | - if(isset($this->inputs[$item])){
|
|
| 406 | + if (property_exists($this, 'requestExcept') && is_array($this->requestExcept)) {
|
|
| 407 | + foreach ($this->requestExcept as $item) {
|
|
| 408 | + if (isset($this->inputs[$item])) {
|
|
| 409 | 409 | unset($this->inputs[$item]); |
| 410 | 410 | } |
| 411 | 411 | } |
@@ -445,16 +445,16 @@ discard block |
||
| 445 | 445 | * @param null|string $clientName |
| 446 | 446 | * @return void|mixed |
| 447 | 447 | */ |
| 448 | - public function setClientName($clientName=null) |
|
| 448 | + public function setClientName($clientName = null) |
|
| 449 | 449 | {
|
| 450 | - if(!is_null($clientName) && is_string($clientName)){
|
|
| 450 | + if (!is_null($clientName) && is_string($clientName)) {
|
|
| 451 | 451 | return $this->clientName = $clientName; |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | - if(!is_null(Utils::trace(0)) && isset(Utils::trace(0)['object'])){
|
|
| 454 | + if (!is_null(Utils::trace(0)) && isset(Utils::trace(0)['object'])) {
|
|
| 455 | 455 | $backTrace = Utils::trace(0)['object']; |
| 456 | 456 | |
| 457 | - if(property_exists($backTrace,'clientName')){
|
|
| 457 | + if (property_exists($backTrace, 'clientName')) {
|
|
| 458 | 458 | $this->clientName = $backTrace->clientName; |
| 459 | 459 | } |
| 460 | 460 | } |
@@ -471,9 +471,9 @@ discard block |
||
| 471 | 471 | |
| 472 | 472 | // we update the input values after |
| 473 | 473 | // we receive and check the saved objects. |
| 474 | - foreach ($clientObjects as $key=>$value){
|
|
| 474 | + foreach ($clientObjects as $key=>$value) {
|
|
| 475 | 475 | |
| 476 | - if(!in_array($key,$this->generatorList) && isset($clientObjects['origin'][$key])){
|
|
| 476 | + if (!in_array($key, $this->generatorList) && isset($clientObjects['origin'][$key])) {
|
|
| 477 | 477 | |
| 478 | 478 | $this->{$key} = $clientObjects['origin'][$key];
|
| 479 | 479 | $this->inputs[$key] = $this->{$key};
|
@@ -501,11 +501,11 @@ discard block |
||
| 501 | 501 | |
| 502 | 502 | // the request update to be performed using |
| 503 | 503 | // the method name to be used with the http method. |
| 504 | - $this->setRequestInputs($requestMethod,$key); |
|
| 504 | + $this->setRequestInputs($requestMethod, $key); |
|
| 505 | 505 | |
| 506 | 506 | // the request update to be performed using |
| 507 | 507 | // the method name to be used without the http method. |
| 508 | - $this->setRequestInputs($key,$key); |
|
| 508 | + $this->setRequestInputs($key, $key); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | /** |
@@ -516,28 +516,28 @@ discard block |
||
| 516 | 516 | * |
| 517 | 517 | * @throws ReflectionExceptionAlias |
| 518 | 518 | */ |
| 519 | - private function setRequestInputs($method,$key) |
|
| 519 | + private function setRequestInputs($method, $key) |
|
| 520 | 520 | {
|
| 521 | - if(!in_array($key,$this->generatorList) && method_exists($this,$method) && $this->reflection->reflectionMethodParams($method)->isProtected){
|
|
| 521 | + if (!in_array($key, $this->generatorList) && method_exists($this, $method) && $this->reflection->reflectionMethodParams($method)->isProtected) {
|
|
| 522 | 522 | |
| 523 | 523 | //check annotations for method |
| 524 | - $annotation = app()->resolve(ClientAnnotationManager::class,['request'=>$this]); |
|
| 525 | - $annotation->annotation($method,$key); |
|
| 524 | + $annotation = app()->resolve(ClientAnnotationManager::class, ['request'=>$this]); |
|
| 525 | + $annotation->annotation($method, $key); |
|
| 526 | 526 | |
| 527 | - if(isset($this->inputs[$key]) && is_array($this->inputs[$key])){
|
|
| 527 | + if (isset($this->inputs[$key]) && is_array($this->inputs[$key])) {
|
|
| 528 | 528 | |
| 529 | 529 | $inputKeys = $this->inputs[$key]; |
| 530 | 530 | |
| 531 | 531 | $this->inputs[$key] = []; |
| 532 | - foreach ($inputKeys as $input){
|
|
| 532 | + foreach ($inputKeys as $input) {
|
|
| 533 | 533 | |
| 534 | 534 | $this->{$key} = $input;
|
| 535 | 535 | $keyMethod = $this->{$method}();
|
| 536 | 536 | $this->inputs[$key][] = $keyMethod; |
| 537 | 537 | } |
| 538 | 538 | } |
| 539 | - else{
|
|
| 540 | - if(isset($this->inputs[$key])){
|
|
| 539 | + else {
|
|
| 540 | + if (isset($this->inputs[$key])) {
|
|
| 541 | 541 | $keyMethod = $this->{$method}();
|
| 542 | 542 | $this->inputs[$key] = $keyMethod; |
| 543 | 543 | } |
@@ -556,8 +556,8 @@ discard block |
||
| 556 | 556 | // the auto object validate property is the property |
| 557 | 557 | // where all of your request values are automatically validated. |
| 558 | 558 | /** @noinspection PhpParamsInspection */ |
| 559 | - if(property_exists($this,'autoObjectValidate') |
|
| 560 | - && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)){
|
|
| 559 | + if (property_exists($this, 'autoObjectValidate') |
|
| 560 | + && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)) {
|
|
| 561 | 561 | $this->autoValidate('autoObjectValidate');
|
| 562 | 562 | } |
| 563 | 563 | } |