@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | * @throws ReflectionExceptionAlias |
| 58 | 58 | */ |
| 59 | - public function __construct($clientData=null) |
|
| 59 | + public function __construct($clientData = null) |
|
| 60 | 60 | {
|
| 61 | 61 | //reflection process |
| 62 | 62 | $this->reflection = app()['reflection']($this); |
@@ -79,25 +79,25 @@ discard block |
||
| 79 | 79 | private function autoValidate($validate) |
| 80 | 80 | {
|
| 81 | 81 | //we get the values to auto-validate. |
| 82 | - foreach ($this->{$validate} as $object=>$datas){
|
|
| 82 | + foreach ($this->{$validate} as $object=>$datas) {
|
|
| 83 | 83 | |
| 84 | 84 | // the auto-validate value must necessarily represent a class. |
| 85 | 85 | // otherwise auto-validate is not used. |
| 86 | - if(Utils::isNamespaceExists($object)){
|
|
| 86 | + if (Utils::isNamespaceExists($object)) {
|
|
| 87 | 87 | $getObjectInstance = app()->resolve($object); |
| 88 | 88 | |
| 89 | 89 | // we get the index values, |
| 90 | 90 | // which are called methods of the auto-validate value that represents the class. |
| 91 | - foreach ($datas as $dataKey=>$data){
|
|
| 91 | + foreach ($datas as $dataKey=>$data) {
|
|
| 92 | 92 | |
| 93 | 93 | // if the methods of the auto-validate class resolved by the container resolve method apply, |
| 94 | 94 | // the process of auto-validate automatic implementation will be completed. |
| 95 | - if(is_numeric($dataKey) && method_exists($getObjectInstance,$data)){
|
|
| 96 | - if(isset($this->origin[$data])){
|
|
| 97 | - if(!is_array($this->origin[$data])){
|
|
| 95 | + if (is_numeric($dataKey) && method_exists($getObjectInstance, $data)) {
|
|
| 96 | + if (isset($this->origin[$data])) {
|
|
| 97 | + if (!is_array($this->origin[$data])) {
|
|
| 98 | 98 | $this->origin[$data] = array($this->origin[$data]); |
| 99 | 99 | } |
| 100 | - foreach ($this->origin[$data] as $originData){
|
|
| 100 | + foreach ($this->origin[$data] as $originData) {
|
|
| 101 | 101 | $getObjectInstance->{$data}($originData);
|
| 102 | 102 | } |
| 103 | 103 | } |
@@ -116,15 +116,15 @@ discard block |
||
| 116 | 116 | {
|
| 117 | 117 | // expected method is executed. |
| 118 | 118 | // this method is a must for http method values to be found in this property. |
| 119 | - if($this->checkProperties('capsule')){
|
|
| 119 | + if ($this->checkProperties('capsule')) {
|
|
| 120 | 120 | |
| 121 | 121 | $caret = $this->capsuleCaret(); |
| 122 | 122 | |
| 123 | - foreach($this->inputs as $input=>$value){
|
|
| 123 | + foreach ($this->inputs as $input=>$value) {
|
|
| 124 | 124 | |
| 125 | - if(isset($caret[$input]) || ( |
|
| 126 | - $this->checkProperties('capsule') && !in_array($input,$this->capsule)
|
|
| 127 | - )){
|
|
| 125 | + if (isset($caret[$input]) || ( |
|
| 126 | + $this->checkProperties('capsule') && !in_array($input, $this->capsule)
|
|
| 127 | + )) {
|
|
| 128 | 128 | exception('capsuleRequestException')
|
| 129 | 129 | ->overflow('The '.$input.' value cannot be sent.');
|
| 130 | 130 | } |
@@ -141,15 +141,15 @@ discard block |
||
| 141 | 141 | {
|
| 142 | 142 | $caret = []; |
| 143 | 143 | |
| 144 | - foreach($this->inputs as $input=>$item){
|
|
| 145 | - if(in_array('@'.$input,$this->capsule)){
|
|
| 144 | + foreach ($this->inputs as $input=>$item) {
|
|
| 145 | + if (in_array('@'.$input, $this->capsule)) {
|
|
| 146 | 146 | $caret[$input] = $item; |
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | foreach ($this->capsule as $item) {
|
| 151 | - if(preg_match('#@.*#is',$item)){
|
|
| 152 | - $this->capsule = array_diff($this->capsule,[$item]); |
|
| 151 | + if (preg_match('#@.*#is', $item)) {
|
|
| 152 | + $this->capsule = array_diff($this->capsule, [$item]); |
|
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
@@ -168,15 +168,15 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | // Determines which HTTP method |
| 170 | 170 | // the request object will be exposed to. |
| 171 | - if($this->checkProperties('http')){
|
|
| 171 | + if ($this->checkProperties('http')) {
|
|
| 172 | 172 | |
| 173 | 173 | // if the current http method does not exist |
| 174 | 174 | // in the http object, the exception will be thrown. |
| 175 | - if(!in_array($method,$this->http)){
|
|
| 175 | + if (!in_array($method, $this->http)) {
|
|
| 176 | 176 | |
| 177 | 177 | //exception batMethodCall |
| 178 | 178 | exception()->badMethodCall( |
| 179 | - 'Invalid http method process for '.class_basename($this).'.That is accepted http methods ['.implode(",",$this->http).'] ');
|
|
| 179 | + 'Invalid http method process for '.class_basename($this).'.That is accepted http methods ['.implode(",", $this->http).'] ');
|
|
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | } |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | {
|
| 192 | 192 | // from the properties of the object properties to |
| 193 | 193 | // the existing variables, control the array and at least one element. |
| 194 | - return (property_exists($this,$properties) |
|
| 194 | + return (property_exists($this, $properties) |
|
| 195 | 195 | && is_array($this->{$properties}) && count($this->{$properties})) ? true : false;
|
| 196 | 196 | } |
| 197 | 197 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | {
|
| 205 | 205 | // we are saving the expected values for the request in container. |
| 206 | 206 | // this record can be returned in exception information. |
| 207 | - app()->register('requestExpected',$this->expected);
|
|
| 207 | + app()->register('requestExpected', $this->expected);
|
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -216,15 +216,15 @@ discard block |
||
| 216 | 216 | public function except($except) |
| 217 | 217 | {
|
| 218 | 218 | // the except parameter is a callable value. |
| 219 | - if(is_callable($except)){
|
|
| 220 | - $call = call_user_func_array($except,[$this]); |
|
| 219 | + if (is_callable($except)) {
|
|
| 220 | + $call = call_user_func_array($except, [$this]); |
|
| 221 | 221 | $except = $call; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | // except with the except exceptions property |
| 225 | 225 | // and then assigning them to the inputs property. |
| 226 | - $this->except = array_merge($this->except,$except); |
|
| 227 | - $this->inputs = array_diff_key($this->inputs,array_flip($this->except)); |
|
| 226 | + $this->except = array_merge($this->except, $except); |
|
| 227 | + $this->inputs = array_diff_key($this->inputs, array_flip($this->except)); |
|
| 228 | 228 | |
| 229 | 229 | return $this; |
| 230 | 230 | } |
@@ -238,27 +238,27 @@ discard block |
||
| 238 | 238 | {
|
| 239 | 239 | // expected method is executed. |
| 240 | 240 | // this method is a must for http method values to be found in this property. |
| 241 | - if($this->checkProperties('expected')){
|
|
| 241 | + if ($this->checkProperties('expected')) {
|
|
| 242 | 242 | |
| 243 | 243 | // if the expected values are not found in the inputs array, |
| 244 | 244 | // the exception will be thrown. |
| 245 | - foreach ($this->expected as $expected){
|
|
| 245 | + foreach ($this->expected as $expected) {
|
|
| 246 | 246 | |
| 247 | 247 | $expectedValues = []; |
| 248 | 248 | |
| 249 | 249 | // mandatory expected data for each key can be separated by | operator. |
| 250 | 250 | // this is evaluated as "or". |
| 251 | - foreach($expectedData = explode("|",$expected) as $inputs){
|
|
| 252 | - if(!isset($this->inputs[$inputs])){
|
|
| 251 | + foreach ($expectedData = explode("|", $expected) as $inputs) {
|
|
| 252 | + if (!isset($this->inputs[$inputs])) {
|
|
| 253 | 253 | $expectedValues[] = $inputs; |
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // if the expectedData and expectedValues |
| 258 | 258 | // array are numerically equal to the expected key, the exception is thrown. |
| 259 | - if(count($expectedData)===count($expectedValues)){
|
|
| 260 | - exception('clientExpected',['key'=>$expected])
|
|
| 261 | - ->unexpectedValue('You absolutely have to send the value '.implode(" or ",$expectedValues).' for request object');
|
|
| 259 | + if (count($expectedData)===count($expectedValues)) {
|
|
| 260 | + exception('clientExpected', ['key'=>$expected])
|
|
| 261 | + ->unexpectedValue('You absolutely have to send the value '.implode(" or ", $expectedValues).' for request object');
|
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | } |
@@ -273,17 +273,17 @@ discard block |
||
| 273 | 273 | {
|
| 274 | 274 | // check the presence of the generator object |
| 275 | 275 | // and operate the generator over this object. |
| 276 | - if($this->checkProperties('auto_generators')){
|
|
| 276 | + if ($this->checkProperties('auto_generators')) {
|
|
| 277 | 277 | $generators = $this->getAutoGenerators(); |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | // check the presence of the generator object |
| 281 | 281 | // and operate the generator over this object. |
| 282 | - if($this->checkProperties('generators')){
|
|
| 283 | - $generators = array_merge(isset($generators) ? $generators: [],$this->getGenerators()); |
|
| 282 | + if ($this->checkProperties('generators')) {
|
|
| 283 | + $generators = array_merge(isset($generators) ? $generators : [], $this->getGenerators()); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - if(isset($generators)){
|
|
| 286 | + if (isset($generators)) {
|
|
| 287 | 287 | $this->generatorMethod($generators); |
| 288 | 288 | } |
| 289 | 289 | } |
@@ -298,21 +298,21 @@ discard block |
||
| 298 | 298 | private function generatorMethod($generators) |
| 299 | 299 | {
|
| 300 | 300 | //generator array object |
| 301 | - foreach ($generators as $generator){
|
|
| 301 | + foreach ($generators as $generator) {
|
|
| 302 | 302 | |
| 303 | 303 | //generator method name |
| 304 | 304 | $generatorMethodName = $generator.'Generator'; |
| 305 | 305 | |
| 306 | 306 | // if the generator method is present, |
| 307 | 307 | // the fake value is assigned. |
| 308 | - if(method_exists($this,$generatorMethodName)){
|
|
| 308 | + if (method_exists($this, $generatorMethodName)) {
|
|
| 309 | 309 | |
| 310 | 310 | //fake registration |
| 311 | - if(!isset($this->inputs[$generator])){
|
|
| 311 | + if (!isset($this->inputs[$generator])) {
|
|
| 312 | 312 | |
| 313 | 313 | $generatorMethodNameResult = $this->{$generatorMethodName}();
|
| 314 | 314 | |
| 315 | - if(!is_null($generatorMethodNameResult)){
|
|
| 315 | + if (!is_null($generatorMethodNameResult)) {
|
|
| 316 | 316 | $this->{$generator} = $this->{$generatorMethodName}();
|
| 317 | 317 | $this->inputs[$generator] = $this->{$generatorMethodName}();
|
| 318 | 318 | $this->requestData[$generator] = $this->inputs[$generator]; |
@@ -321,15 +321,15 @@ discard block |
||
| 321 | 321 | } |
| 322 | 322 | else {
|
| 323 | 323 | |
| 324 | - if($this->checkProperties('auto_generators_dont_overwrite')
|
|
| 325 | - && in_array($generator,$this->getAutoGeneratorsDontOverwrite())){
|
|
| 324 | + if ($this->checkProperties('auto_generators_dont_overwrite')
|
|
| 325 | + && in_array($generator, $this->getAutoGeneratorsDontOverwrite())) {
|
|
| 326 | 326 | $this->{$generator} = $this->{$generatorMethodName}();
|
| 327 | 327 | $this->inputs[$generator] = $this->{$generatorMethodName}();
|
| 328 | 328 | $this->generatorList[] = $generator; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - if($this->checkProperties('generators_dont_overwrite')
|
|
| 332 | - && in_array($generator,$this->getGeneratorsDontOverwrite())){
|
|
| 331 | + if ($this->checkProperties('generators_dont_overwrite')
|
|
| 332 | + && in_array($generator, $this->getGeneratorsDontOverwrite())) {
|
|
| 333 | 333 | $this->{$generator} = $this->{$generatorMethodName}();
|
| 334 | 334 | $this->inputs[$generator] = $this->{$generatorMethodName}();
|
| 335 | 335 | $this->generatorList[] = $generator; |
@@ -352,11 +352,11 @@ discard block |
||
| 352 | 352 | $list = []; |
| 353 | 353 | |
| 354 | 354 | foreach ($this->requestData as $key=>$item) {
|
| 355 | - if(property_exists($this,'requestExcept') && !in_array($key,$this->requestExcept)){
|
|
| 355 | + if (property_exists($this, 'requestExcept') && !in_array($key, $this->requestExcept)) {
|
|
| 356 | 356 | $list[$key] = $item; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - if(!property_exists($this,'requestExcept')){
|
|
| 359 | + if (!property_exists($this, 'requestExcept')) {
|
|
| 360 | 360 | $list[$key] = $item; |
| 361 | 361 | } |
| 362 | 362 | } |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | {
|
| 405 | 405 | // we use the http method to write |
| 406 | 406 | // the values to the inputs and origin properties. |
| 407 | - foreach($this->clientData as $key=>$value){
|
|
| 407 | + foreach ($this->clientData as $key=>$value) {
|
|
| 408 | 408 | |
| 409 | 409 | //inputs and origin properties |
| 410 | 410 | $this->inputs[$key] = $value; |
@@ -446,9 +446,9 @@ discard block |
||
| 446 | 446 | |
| 447 | 447 | // we update the input values after |
| 448 | 448 | // we receive and check the saved objects. |
| 449 | - foreach ($clientObjects as $key=>$value){
|
|
| 449 | + foreach ($clientObjects as $key=>$value) {
|
|
| 450 | 450 | |
| 451 | - if(!in_array($key,$this->generatorList) && isset($clientObjects['origin'][$key])){
|
|
| 451 | + if (!in_array($key, $this->generatorList) && isset($clientObjects['origin'][$key])) {
|
|
| 452 | 452 | |
| 453 | 453 | $this->{$key} = $clientObjects['origin'][$key];
|
| 454 | 454 | $this->inputs[$key] = $this->{$key};
|
@@ -476,11 +476,11 @@ discard block |
||
| 476 | 476 | |
| 477 | 477 | // the request update to be performed using |
| 478 | 478 | // the method name to be used with the http method. |
| 479 | - $this->setRequestInputs($requestMethod,$key); |
|
| 479 | + $this->setRequestInputs($requestMethod, $key); |
|
| 480 | 480 | |
| 481 | 481 | // the request update to be performed using |
| 482 | 482 | // the method name to be used without the http method. |
| 483 | - $this->setRequestInputs($key,$key); |
|
| 483 | + $this->setRequestInputs($key, $key); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
@@ -491,20 +491,20 @@ discard block |
||
| 491 | 491 | * |
| 492 | 492 | * @throws ReflectionExceptionAlias |
| 493 | 493 | */ |
| 494 | - private function setRequestInputs($method,$key) |
|
| 494 | + private function setRequestInputs($method, $key) |
|
| 495 | 495 | {
|
| 496 | - if(!in_array($key,$this->generatorList) && method_exists($this,$method) && $this->reflection->reflectionMethodParams($method)->isProtected){
|
|
| 496 | + if (!in_array($key, $this->generatorList) && method_exists($this, $method) && $this->reflection->reflectionMethodParams($method)->isProtected) {
|
|
| 497 | 497 | |
| 498 | 498 | //check annotations for method |
| 499 | - $annotation = app()->resolve(ClientAnnotationManager::class,['request'=>$this]); |
|
| 500 | - $annotation->annotation($method,$key); |
|
| 499 | + $annotation = app()->resolve(ClientAnnotationManager::class, ['request'=>$this]); |
|
| 500 | + $annotation->annotation($method, $key); |
|
| 501 | 501 | |
| 502 | - if(isset($this->inputs[$key]) && is_array($this->inputs[$key])){
|
|
| 502 | + if (isset($this->inputs[$key]) && is_array($this->inputs[$key])) {
|
|
| 503 | 503 | |
| 504 | 504 | $inputKeys = $this->inputs[$key]; |
| 505 | 505 | |
| 506 | 506 | $this->inputs[$key] = []; |
| 507 | - foreach ($inputKeys as $input){
|
|
| 507 | + foreach ($inputKeys as $input) {
|
|
| 508 | 508 | |
| 509 | 509 | $this->{$key} = $input;
|
| 510 | 510 | $keyMethod = $this->{$method}();
|
@@ -512,8 +512,8 @@ discard block |
||
| 512 | 512 | $this->requestData[$key][] = $keyMethod; |
| 513 | 513 | } |
| 514 | 514 | } |
| 515 | - else{
|
|
| 516 | - if(isset($this->inputs[$key])){
|
|
| 515 | + else {
|
|
| 516 | + if (isset($this->inputs[$key])) {
|
|
| 517 | 517 | $keyMethod = $this->{$method}();
|
| 518 | 518 | $this->inputs[$key] = $keyMethod; |
| 519 | 519 | $this->requestData[$key] = $keyMethod; |
@@ -532,8 +532,8 @@ discard block |
||
| 532 | 532 | {
|
| 533 | 533 | // the auto object validate property is the property |
| 534 | 534 | // where all of your request values are automatically validated. |
| 535 | - if(property_exists($this,'autoObjectValidate') |
|
| 536 | - && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)){
|
|
| 535 | + if (property_exists($this, 'autoObjectValidate') |
|
| 536 | + && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)) {
|
|
| 537 | 537 | $this->autoValidate('autoObjectValidate');
|
| 538 | 538 | } |
| 539 | 539 | } |