@@ -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,19 +116,19 @@ 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 | - if(property_exists($this,'auto_capsule') && is_array($this->auto_capsule)){
|
|
| 122 | - $this->capsule = array_merge($this->capsule,$this->auto_capsule); |
|
| 121 | + if (property_exists($this, 'auto_capsule') && is_array($this->auto_capsule)) {
|
|
| 122 | + $this->capsule = array_merge($this->capsule, $this->auto_capsule); |
|
| 123 | 123 | } |
| 124 | 124 | $caret = $this->capsuleCaret(); |
| 125 | 125 | |
| 126 | - foreach($this->inputs as $input=>$value){
|
|
| 126 | + foreach ($this->inputs as $input=>$value) {
|
|
| 127 | 127 | |
| 128 | - if(isset($caret[$input]) || ( |
|
| 129 | - $this->checkProperties('capsule') && !in_array($input,$this->capsule)
|
|
| 130 | - )){
|
|
| 131 | - exception('clientCapsule',['key'=>$input])
|
|
| 128 | + if (isset($caret[$input]) || ( |
|
| 129 | + $this->checkProperties('capsule') && !in_array($input, $this->capsule)
|
|
| 130 | + )) {
|
|
| 131 | + exception('clientCapsule', ['key'=>$input])
|
|
| 132 | 132 | ->overflow('The '.$input.' value cannot be sent.');
|
| 133 | 133 | } |
| 134 | 134 | } |
@@ -144,15 +144,15 @@ discard block |
||
| 144 | 144 | {
|
| 145 | 145 | $caret = []; |
| 146 | 146 | |
| 147 | - foreach($this->inputs as $input=>$item){
|
|
| 148 | - if(in_array('@'.$input,$this->capsule)){
|
|
| 147 | + foreach ($this->inputs as $input=>$item) {
|
|
| 148 | + if (in_array('@'.$input, $this->capsule)) {
|
|
| 149 | 149 | $caret[$input] = $item; |
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | foreach ($this->capsule as $item) {
|
| 154 | - if(preg_match('#@.*#is',$item)){
|
|
| 155 | - $this->capsule = array_diff($this->capsule,[$item]); |
|
| 154 | + if (preg_match('#@.*#is', $item)) {
|
|
| 155 | + $this->capsule = array_diff($this->capsule, [$item]); |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |
@@ -171,15 +171,15 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | // Determines which HTTP method |
| 173 | 173 | // the request object will be exposed to. |
| 174 | - if($this->checkProperties('http')){
|
|
| 174 | + if ($this->checkProperties('http')) {
|
|
| 175 | 175 | |
| 176 | 176 | // if the current http method does not exist |
| 177 | 177 | // in the http object, the exception will be thrown. |
| 178 | - if(!in_array($method,$this->http)){
|
|
| 178 | + if (!in_array($method, $this->http)) {
|
|
| 179 | 179 | |
| 180 | 180 | //exception batMethodCall |
| 181 | 181 | exception()->badMethodCall( |
| 182 | - 'Invalid http method process for '.class_basename($this).'.That is accepted http methods ['.implode(",",$this->http).'] ');
|
|
| 182 | + 'Invalid http method process for '.class_basename($this).'.That is accepted http methods ['.implode(",", $this->http).'] ');
|
|
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | } |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | {
|
| 195 | 195 | // from the properties of the object properties to |
| 196 | 196 | // the existing variables, control the array and at least one element. |
| 197 | - return (property_exists($this,$properties) |
|
| 197 | + return (property_exists($this, $properties) |
|
| 198 | 198 | && is_array($this->{$properties}) && count($this->{$properties})) ? true : false;
|
| 199 | 199 | } |
| 200 | 200 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | {
|
| 208 | 208 | // we are saving the expected values for the request in container. |
| 209 | 209 | // this record can be returned in exception information. |
| 210 | - app()->register('requestExpected',$this->expected);
|
|
| 210 | + app()->register('requestExpected', $this->expected);
|
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -219,15 +219,15 @@ discard block |
||
| 219 | 219 | public function except($except) |
| 220 | 220 | {
|
| 221 | 221 | // the except parameter is a callable value. |
| 222 | - if(is_callable($except)){
|
|
| 223 | - $call = call_user_func_array($except,[$this]); |
|
| 222 | + if (is_callable($except)) {
|
|
| 223 | + $call = call_user_func_array($except, [$this]); |
|
| 224 | 224 | $except = $call; |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | // except with the except exceptions property |
| 228 | 228 | // and then assigning them to the inputs property. |
| 229 | - $this->except = array_merge($this->except,$except); |
|
| 230 | - $this->inputs = array_diff_key($this->inputs,array_flip($this->except)); |
|
| 229 | + $this->except = array_merge($this->except, $except); |
|
| 230 | + $this->inputs = array_diff_key($this->inputs, array_flip($this->except)); |
|
| 231 | 231 | |
| 232 | 232 | return $this; |
| 233 | 233 | } |
@@ -241,27 +241,27 @@ discard block |
||
| 241 | 241 | {
|
| 242 | 242 | // expected method is executed. |
| 243 | 243 | // this method is a must for http method values to be found in this property. |
| 244 | - if($this->checkProperties('expected')){
|
|
| 244 | + if ($this->checkProperties('expected')) {
|
|
| 245 | 245 | |
| 246 | 246 | // if the expected values are not found in the inputs array, |
| 247 | 247 | // the exception will be thrown. |
| 248 | - foreach ($this->expected as $expected){
|
|
| 248 | + foreach ($this->expected as $expected) {
|
|
| 249 | 249 | |
| 250 | 250 | $expectedValues = []; |
| 251 | 251 | |
| 252 | 252 | // mandatory expected data for each key can be separated by | operator. |
| 253 | 253 | // this is evaluated as "or". |
| 254 | - foreach($expectedData = explode("|",$expected) as $inputs){
|
|
| 255 | - if(!isset($this->inputs[$inputs])){
|
|
| 254 | + foreach ($expectedData = explode("|", $expected) as $inputs) {
|
|
| 255 | + if (!isset($this->inputs[$inputs])) {
|
|
| 256 | 256 | $expectedValues[] = $inputs; |
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | // if the expectedData and expectedValues |
| 261 | 261 | // array are numerically equal to the expected key, the exception is thrown. |
| 262 | - if(count($expectedData)===count($expectedValues)){
|
|
| 263 | - exception('clientExpected',['key'=>$expected])
|
|
| 264 | - ->unexpectedValue('You absolutely have to send the value '.implode(" or ",$expectedValues).' for request object');
|
|
| 262 | + if (count($expectedData)===count($expectedValues)) {
|
|
| 263 | + exception('clientExpected', ['key'=>$expected])
|
|
| 264 | + ->unexpectedValue('You absolutely have to send the value '.implode(" or ", $expectedValues).' for request object');
|
|
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | } |
@@ -276,17 +276,17 @@ discard block |
||
| 276 | 276 | {
|
| 277 | 277 | // check the presence of the generator object |
| 278 | 278 | // and operate the generator over this object. |
| 279 | - if($this->checkProperties('auto_generators')){
|
|
| 279 | + if ($this->checkProperties('auto_generators')) {
|
|
| 280 | 280 | $generators = $this->getAutoGenerators(); |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // check the presence of the generator object |
| 284 | 284 | // and operate the generator over this object. |
| 285 | - if($this->checkProperties('generators')){
|
|
| 286 | - $generators = array_merge(isset($generators) ? $generators: [],$this->getGenerators()); |
|
| 285 | + if ($this->checkProperties('generators')) {
|
|
| 286 | + $generators = array_merge(isset($generators) ? $generators : [], $this->getGenerators()); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - if(isset($generators)){
|
|
| 289 | + if (isset($generators)) {
|
|
| 290 | 290 | $this->generatorMethod($generators); |
| 291 | 291 | } |
| 292 | 292 | } |
@@ -301,21 +301,21 @@ discard block |
||
| 301 | 301 | private function generatorMethod($generators) |
| 302 | 302 | {
|
| 303 | 303 | //generator array object |
| 304 | - foreach ($generators as $generator){
|
|
| 304 | + foreach ($generators as $generator) {
|
|
| 305 | 305 | |
| 306 | 306 | //generator method name |
| 307 | 307 | $generatorMethodName = $generator.'Generator'; |
| 308 | 308 | |
| 309 | 309 | // if the generator method is present, |
| 310 | 310 | // the fake value is assigned. |
| 311 | - if(method_exists($this,$generatorMethodName)){
|
|
| 311 | + if (method_exists($this, $generatorMethodName)) {
|
|
| 312 | 312 | |
| 313 | 313 | //fake registration |
| 314 | - if(!isset($this->inputs[$generator])){
|
|
| 314 | + if (!isset($this->inputs[$generator])) {
|
|
| 315 | 315 | |
| 316 | 316 | $generatorMethodNameResult = $this->{$generatorMethodName}();
|
| 317 | 317 | |
| 318 | - if(!is_null($generatorMethodNameResult)){
|
|
| 318 | + if (!is_null($generatorMethodNameResult)) {
|
|
| 319 | 319 | $this->{$generator} = $this->{$generatorMethodName}();
|
| 320 | 320 | $this->inputs[$generator] = $this->{$generatorMethodName}();
|
| 321 | 321 | $this->requestData[$generator] = $this->inputs[$generator]; |
@@ -324,15 +324,15 @@ discard block |
||
| 324 | 324 | } |
| 325 | 325 | else {
|
| 326 | 326 | |
| 327 | - if($this->checkProperties('auto_generators_dont_overwrite')
|
|
| 328 | - && in_array($generator,$this->getAutoGeneratorsDontOverwrite())){
|
|
| 327 | + if ($this->checkProperties('auto_generators_dont_overwrite')
|
|
| 328 | + && in_array($generator, $this->getAutoGeneratorsDontOverwrite())) {
|
|
| 329 | 329 | $this->{$generator} = $this->{$generatorMethodName}();
|
| 330 | 330 | $this->inputs[$generator] = $this->{$generatorMethodName}();
|
| 331 | 331 | $this->generatorList[] = $generator; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - if($this->checkProperties('generators_dont_overwrite')
|
|
| 335 | - && in_array($generator,$this->getGeneratorsDontOverwrite())){
|
|
| 334 | + if ($this->checkProperties('generators_dont_overwrite')
|
|
| 335 | + && in_array($generator, $this->getGeneratorsDontOverwrite())) {
|
|
| 336 | 336 | $this->{$generator} = $this->{$generatorMethodName}();
|
| 337 | 337 | $this->inputs[$generator] = $this->{$generatorMethodName}();
|
| 338 | 338 | $this->generatorList[] = $generator; |
@@ -355,11 +355,11 @@ discard block |
||
| 355 | 355 | $list = []; |
| 356 | 356 | |
| 357 | 357 | foreach ($this->requestData as $key=>$item) {
|
| 358 | - if(property_exists($this,'requestExcept') && !in_array($key,$this->requestExcept)){
|
|
| 358 | + if (property_exists($this, 'requestExcept') && !in_array($key, $this->requestExcept)) {
|
|
| 359 | 359 | $list[$key] = $item; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - if(!property_exists($this,'requestExcept')){
|
|
| 362 | + if (!property_exists($this, 'requestExcept')) {
|
|
| 363 | 363 | $list[$key] = $item; |
| 364 | 364 | } |
| 365 | 365 | } |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | {
|
| 408 | 408 | // we use the http method to write |
| 409 | 409 | // the values to the inputs and origin properties. |
| 410 | - foreach($this->clientData as $key=>$value){
|
|
| 410 | + foreach ($this->clientData as $key=>$value) {
|
|
| 411 | 411 | |
| 412 | 412 | //inputs and origin properties |
| 413 | 413 | $this->inputs[$key] = $value; |
@@ -449,9 +449,9 @@ discard block |
||
| 449 | 449 | |
| 450 | 450 | // we update the input values after |
| 451 | 451 | // we receive and check the saved objects. |
| 452 | - foreach ($clientObjects as $key=>$value){
|
|
| 452 | + foreach ($clientObjects as $key=>$value) {
|
|
| 453 | 453 | |
| 454 | - if(!in_array($key,$this->generatorList) && isset($clientObjects['origin'][$key])){
|
|
| 454 | + if (!in_array($key, $this->generatorList) && isset($clientObjects['origin'][$key])) {
|
|
| 455 | 455 | |
| 456 | 456 | $this->{$key} = $clientObjects['origin'][$key];
|
| 457 | 457 | $this->inputs[$key] = $this->{$key};
|
@@ -479,11 +479,11 @@ discard block |
||
| 479 | 479 | |
| 480 | 480 | // the request update to be performed using |
| 481 | 481 | // the method name to be used with the http method. |
| 482 | - $this->setRequestInputs($requestMethod,$key); |
|
| 482 | + $this->setRequestInputs($requestMethod, $key); |
|
| 483 | 483 | |
| 484 | 484 | // the request update to be performed using |
| 485 | 485 | // the method name to be used without the http method. |
| 486 | - $this->setRequestInputs($key,$key); |
|
| 486 | + $this->setRequestInputs($key, $key); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -494,20 +494,20 @@ discard block |
||
| 494 | 494 | * |
| 495 | 495 | * @throws ReflectionExceptionAlias |
| 496 | 496 | */ |
| 497 | - private function setRequestInputs($method,$key) |
|
| 497 | + private function setRequestInputs($method, $key) |
|
| 498 | 498 | {
|
| 499 | - if(!in_array($key,$this->generatorList) && method_exists($this,$method) && $this->reflection->reflectionMethodParams($method)->isProtected){
|
|
| 499 | + if (!in_array($key, $this->generatorList) && method_exists($this, $method) && $this->reflection->reflectionMethodParams($method)->isProtected) {
|
|
| 500 | 500 | |
| 501 | 501 | //check annotations for method |
| 502 | - $annotation = app()->resolve(ClientAnnotationManager::class,['request'=>$this]); |
|
| 503 | - $annotation->annotation($method,$key); |
|
| 502 | + $annotation = app()->resolve(ClientAnnotationManager::class, ['request'=>$this]); |
|
| 503 | + $annotation->annotation($method, $key); |
|
| 504 | 504 | |
| 505 | - if(isset($this->inputs[$key]) && is_array($this->inputs[$key])){
|
|
| 505 | + if (isset($this->inputs[$key]) && is_array($this->inputs[$key])) {
|
|
| 506 | 506 | |
| 507 | 507 | $inputKeys = $this->inputs[$key]; |
| 508 | 508 | |
| 509 | 509 | $this->inputs[$key] = []; |
| 510 | - foreach ($inputKeys as $input){
|
|
| 510 | + foreach ($inputKeys as $input) {
|
|
| 511 | 511 | |
| 512 | 512 | $this->{$key} = $input;
|
| 513 | 513 | $keyMethod = $this->{$method}();
|
@@ -515,8 +515,8 @@ discard block |
||
| 515 | 515 | $this->requestData[$key][] = $keyMethod; |
| 516 | 516 | } |
| 517 | 517 | } |
| 518 | - else{
|
|
| 519 | - if(isset($this->inputs[$key])){
|
|
| 518 | + else {
|
|
| 519 | + if (isset($this->inputs[$key])) {
|
|
| 520 | 520 | $keyMethod = $this->{$method}();
|
| 521 | 521 | $this->inputs[$key] = $keyMethod; |
| 522 | 522 | $this->requestData[$key] = $keyMethod; |
@@ -535,8 +535,8 @@ discard block |
||
| 535 | 535 | {
|
| 536 | 536 | // the auto object validate property is the property |
| 537 | 537 | // where all of your request values are automatically validated. |
| 538 | - if(property_exists($this,'autoObjectValidate') |
|
| 539 | - && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)){
|
|
| 538 | + if (property_exists($this, 'autoObjectValidate') |
|
| 539 | + && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)) {
|
|
| 540 | 540 | $this->autoValidate('autoObjectValidate');
|
| 541 | 541 | } |
| 542 | 542 | } |