@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @throws ReflectionExceptionAlias |
| 49 | 49 | */ |
| 50 | - public function __construct($clientData=null) |
|
| 50 | + public function __construct($clientData = null) |
|
| 51 | 51 | {
|
| 52 | 52 | //reflection process |
| 53 | 53 | $this->reflection = app()['reflection']($this); |
@@ -70,25 +70,25 @@ discard block |
||
| 70 | 70 | private function autoValidate($validate) |
| 71 | 71 | {
|
| 72 | 72 | //we get the values to auto-validate. |
| 73 | - foreach ($this->{$validate} as $object=>$datas){
|
|
| 73 | + foreach ($this->{$validate} as $object=>$datas) {
|
|
| 74 | 74 | |
| 75 | 75 | // the auto-validate value must necessarily represent a class. |
| 76 | 76 | // otherwise auto-validate is not used. |
| 77 | - if(Utils::isNamespaceExists($object)){
|
|
| 77 | + if (Utils::isNamespaceExists($object)) {
|
|
| 78 | 78 | $getObjectInstance = app()->resolve($object); |
| 79 | 79 | |
| 80 | 80 | // we get the index values, |
| 81 | 81 | // which are called methods of the auto-validate value that represents the class. |
| 82 | - foreach ($datas as $dataKey=>$data){
|
|
| 82 | + foreach ($datas as $dataKey=>$data) {
|
|
| 83 | 83 | |
| 84 | 84 | // if the methods of the auto-validate class resolved by the container resolve method apply, |
| 85 | 85 | // the process of auto-validate automatic implementation will be completed. |
| 86 | - if(is_numeric($dataKey) && method_exists($getObjectInstance,$data)){
|
|
| 87 | - if(isset($this->origin[$data])){
|
|
| 88 | - if(!is_array($this->origin[$data])){
|
|
| 86 | + if (is_numeric($dataKey) && method_exists($getObjectInstance, $data)) {
|
|
| 87 | + if (isset($this->origin[$data])) {
|
|
| 88 | + if (!is_array($this->origin[$data])) {
|
|
| 89 | 89 | $this->origin[$data] = array($this->origin[$data]); |
| 90 | 90 | } |
| 91 | - foreach ($this->origin[$data] as $originData){
|
|
| 91 | + foreach ($this->origin[$data] as $originData) {
|
|
| 92 | 92 | $getObjectInstance->{$data}($originData);
|
| 93 | 93 | } |
| 94 | 94 | } |
@@ -107,15 +107,15 @@ discard block |
||
| 107 | 107 | {
|
| 108 | 108 | // expected method is executed. |
| 109 | 109 | // this method is a must for http method values to be found in this property. |
| 110 | - if($this->checkProperties('capsule')){
|
|
| 110 | + if ($this->checkProperties('capsule')) {
|
|
| 111 | 111 | |
| 112 | 112 | $caret = $this->capsuleCaret(); |
| 113 | 113 | |
| 114 | - foreach($this->inputs as $input=>$value){
|
|
| 114 | + foreach ($this->inputs as $input=>$value) {
|
|
| 115 | 115 | |
| 116 | - if(isset($caret[$input]) || ( |
|
| 117 | - $this->checkProperties('capsule') && !in_array($input,$this->capsule)
|
|
| 118 | - )){
|
|
| 116 | + if (isset($caret[$input]) || ( |
|
| 117 | + $this->checkProperties('capsule') && !in_array($input, $this->capsule)
|
|
| 118 | + )) {
|
|
| 119 | 119 | exception('capsuleRequestException')
|
| 120 | 120 | ->overflow('The '.$input.' value cannot be sent.');
|
| 121 | 121 | } |
@@ -132,15 +132,15 @@ discard block |
||
| 132 | 132 | {
|
| 133 | 133 | $caret = []; |
| 134 | 134 | |
| 135 | - foreach($this->inputs as $input=>$item){
|
|
| 136 | - if(in_array('@'.$input,$this->capsule)){
|
|
| 135 | + foreach ($this->inputs as $input=>$item) {
|
|
| 136 | + if (in_array('@'.$input, $this->capsule)) {
|
|
| 137 | 137 | $caret[$input] = $item; |
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | foreach ($this->capsule as $item) {
|
| 142 | - if(preg_match('#@.*#is',$item)){
|
|
| 143 | - $this->capsule = array_diff($this->capsule,[$item]); |
|
| 142 | + if (preg_match('#@.*#is', $item)) {
|
|
| 143 | + $this->capsule = array_diff($this->capsule, [$item]); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
@@ -159,15 +159,15 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | // Determines which HTTP method |
| 161 | 161 | // the request object will be exposed to. |
| 162 | - if($this->checkProperties('http')){
|
|
| 162 | + if ($this->checkProperties('http')) {
|
|
| 163 | 163 | |
| 164 | 164 | // if the current http method does not exist |
| 165 | 165 | // in the http object, the exception will be thrown. |
| 166 | - if(!in_array($method,$this->http)){
|
|
| 166 | + if (!in_array($method, $this->http)) {
|
|
| 167 | 167 | |
| 168 | 168 | //exception batMethodCall |
| 169 | 169 | exception()->badMethodCall( |
| 170 | - 'Invalid http method process for '.class_basename($this).'.That is accepted http methods ['.implode(",",$this->http).'] ');
|
|
| 170 | + 'Invalid http method process for '.class_basename($this).'.That is accepted http methods ['.implode(",", $this->http).'] ');
|
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | } |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | {
|
| 183 | 183 | // from the properties of the object properties to |
| 184 | 184 | // the existing variables, control the array and at least one element. |
| 185 | - return (property_exists($this,$properties) |
|
| 185 | + return (property_exists($this, $properties) |
|
| 186 | 186 | && is_array($this->{$properties}) && count($this->{$properties})) ? true : false;
|
| 187 | 187 | } |
| 188 | 188 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | {
|
| 196 | 196 | // we are saving the expected values for the request in container. |
| 197 | 197 | // this record can be returned in exception information. |
| 198 | - app()->register('requestExpected',$this->expected);
|
|
| 198 | + app()->register('requestExpected', $this->expected);
|
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -207,15 +207,15 @@ discard block |
||
| 207 | 207 | public function except($except) |
| 208 | 208 | {
|
| 209 | 209 | // the except parameter is a callable value. |
| 210 | - if(is_callable($except)){
|
|
| 211 | - $call = call_user_func_array($except,[$this]); |
|
| 210 | + if (is_callable($except)) {
|
|
| 211 | + $call = call_user_func_array($except, [$this]); |
|
| 212 | 212 | $except = $call; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | // except with the except exceptions property |
| 216 | 216 | // and then assigning them to the inputs property. |
| 217 | - $this->except = array_merge($this->except,$except); |
|
| 218 | - $this->inputs = array_diff_key($this->inputs,array_flip($this->except)); |
|
| 217 | + $this->except = array_merge($this->except, $except); |
|
| 218 | + $this->inputs = array_diff_key($this->inputs, array_flip($this->except)); |
|
| 219 | 219 | |
| 220 | 220 | return $this; |
| 221 | 221 | } |
@@ -229,27 +229,27 @@ discard block |
||
| 229 | 229 | {
|
| 230 | 230 | // expected method is executed. |
| 231 | 231 | // this method is a must for http method values to be found in this property. |
| 232 | - if($this->checkProperties('expected')){
|
|
| 232 | + if ($this->checkProperties('expected')) {
|
|
| 233 | 233 | |
| 234 | 234 | // if the expected values are not found in the inputs array, |
| 235 | 235 | // the exception will be thrown. |
| 236 | - foreach ($this->expected as $expected){
|
|
| 236 | + foreach ($this->expected as $expected) {
|
|
| 237 | 237 | |
| 238 | 238 | $expectedValues = []; |
| 239 | 239 | |
| 240 | 240 | // mandatory expected data for each key can be separated by | operator. |
| 241 | 241 | // this is evaluated as "or". |
| 242 | - foreach($expectedData = explode("|",$expected) as $inputs){
|
|
| 243 | - if(!isset($this->inputs[$inputs])){
|
|
| 242 | + foreach ($expectedData = explode("|", $expected) as $inputs) {
|
|
| 243 | + if (!isset($this->inputs[$inputs])) {
|
|
| 244 | 244 | $expectedValues[] = $inputs; |
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // if the expectedData and expectedValues |
| 249 | 249 | // array are numerically equal to the expected key, the exception is thrown. |
| 250 | - if(count($expectedData)===count($expectedValues)){
|
|
| 250 | + if (count($expectedData)===count($expectedValues)) {
|
|
| 251 | 251 | exception($expected) |
| 252 | - ->unexpectedValue('You absolutely have to send the value '.implode(" or ",$expectedValues).' for request object');
|
|
| 252 | + ->unexpectedValue('You absolutely have to send the value '.implode(" or ", $expectedValues).' for request object');
|
|
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | } |
@@ -264,17 +264,17 @@ discard block |
||
| 264 | 264 | {
|
| 265 | 265 | // check the presence of the generator object |
| 266 | 266 | // and operate the generator over this object. |
| 267 | - if($this->checkProperties('auto_generators')){
|
|
| 267 | + if ($this->checkProperties('auto_generators')) {
|
|
| 268 | 268 | $generators = $this->getAutoGenerators(); |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | // check the presence of the generator object |
| 272 | 272 | // and operate the generator over this object. |
| 273 | - if($this->checkProperties('generators')){
|
|
| 274 | - $generators = array_merge(isset($generators) ? $generators: [],$this->getGenerators()); |
|
| 273 | + if ($this->checkProperties('generators')) {
|
|
| 274 | + $generators = array_merge(isset($generators) ? $generators : [], $this->getGenerators()); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - if(isset($generators)){
|
|
| 277 | + if (isset($generators)) {
|
|
| 278 | 278 | $this->generatorMethod($generators); |
| 279 | 279 | } |
| 280 | 280 | } |
@@ -289,30 +289,30 @@ discard block |
||
| 289 | 289 | private function generatorMethod($generators) |
| 290 | 290 | {
|
| 291 | 291 | //generator array object |
| 292 | - foreach ($generators as $generator){
|
|
| 292 | + foreach ($generators as $generator) {
|
|
| 293 | 293 | |
| 294 | 294 | //generator method name |
| 295 | 295 | $generatorMethodName = $generator.'Generator'; |
| 296 | 296 | |
| 297 | 297 | // if the generator method is present, |
| 298 | 298 | // the fake value is assigned. |
| 299 | - if(method_exists($this,$generatorMethodName)){
|
|
| 299 | + if (method_exists($this, $generatorMethodName)) {
|
|
| 300 | 300 | |
| 301 | 301 | //fake registration |
| 302 | - if(!isset($this->inputs[$generator])){
|
|
| 302 | + if (!isset($this->inputs[$generator])) {
|
|
| 303 | 303 | $this->{$generator} = $this->{$generatorMethodName}();
|
| 304 | 304 | $this->inputs[$generator] = $this->{$generatorMethodName}();
|
| 305 | 305 | } |
| 306 | 306 | else {
|
| 307 | 307 | |
| 308 | - if($this->checkProperties('auto_generators_dont_overwrite')
|
|
| 309 | - && in_array($generator,$this->getAutoGeneratorsDontOverwrite())){
|
|
| 308 | + if ($this->checkProperties('auto_generators_dont_overwrite')
|
|
| 309 | + && in_array($generator, $this->getAutoGeneratorsDontOverwrite())) {
|
|
| 310 | 310 | $this->{$generator} = $this->{$generatorMethodName}();
|
| 311 | 311 | $this->inputs[$generator] = $this->{$generatorMethodName}();
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - if($this->checkProperties('generators_dont_overwrite')
|
|
| 315 | - && in_array($generator,$this->getGeneratorsDontOverwrite())){
|
|
| 314 | + if ($this->checkProperties('generators_dont_overwrite')
|
|
| 315 | + && in_array($generator, $this->getGeneratorsDontOverwrite())) {
|
|
| 316 | 316 | $this->{$generator} = $this->{$generatorMethodName}();
|
| 317 | 317 | $this->inputs[$generator] = $this->{$generatorMethodName}();
|
| 318 | 318 | } |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | {
|
| 360 | 360 | // we use the http method to write |
| 361 | 361 | // the values to the inputs and origin properties. |
| 362 | - foreach($this->clientData as $key=>$value){
|
|
| 362 | + foreach ($this->clientData as $key=>$value) {
|
|
| 363 | 363 | |
| 364 | 364 | //inputs and origin properties |
| 365 | 365 | $this->inputs[$key] = $value; |
@@ -406,9 +406,9 @@ discard block |
||
| 406 | 406 | |
| 407 | 407 | // we update the input values after |
| 408 | 408 | // we receive and check the saved objects. |
| 409 | - foreach ($clientObjects as $key=>$value){
|
|
| 409 | + foreach ($clientObjects as $key=>$value) {
|
|
| 410 | 410 | |
| 411 | - if(isset($clientObjects['origin'][$key])){
|
|
| 411 | + if (isset($clientObjects['origin'][$key])) {
|
|
| 412 | 412 | |
| 413 | 413 | $this->{$key} = $clientObjects['origin'][$key];
|
| 414 | 414 | $this->inputs[$key] = $this->{$key};
|
@@ -435,11 +435,11 @@ discard block |
||
| 435 | 435 | |
| 436 | 436 | // the request update to be performed using |
| 437 | 437 | // the method name to be used with the http method. |
| 438 | - $this->setRequestInputs($requestMethod,$key); |
|
| 438 | + $this->setRequestInputs($requestMethod, $key); |
|
| 439 | 439 | |
| 440 | 440 | // the request update to be performed using |
| 441 | 441 | // the method name to be used without the http method. |
| 442 | - $this->setRequestInputs($key,$key); |
|
| 442 | + $this->setRequestInputs($key, $key); |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -450,28 +450,28 @@ discard block |
||
| 450 | 450 | * |
| 451 | 451 | * @throws ReflectionExceptionAlias |
| 452 | 452 | */ |
| 453 | - private function setRequestInputs($method,$key) |
|
| 453 | + private function setRequestInputs($method, $key) |
|
| 454 | 454 | {
|
| 455 | - if(method_exists($this,$method) && $this->reflection->reflectionMethodParams($method)->isProtected){
|
|
| 455 | + if (method_exists($this, $method) && $this->reflection->reflectionMethodParams($method)->isProtected) {
|
|
| 456 | 456 | |
| 457 | 457 | //check annotations for method |
| 458 | - $annotation = app()->resolve(RequestAnnotationManager::class,['request'=>$this]); |
|
| 459 | - $annotation->annotation($method,$key); |
|
| 458 | + $annotation = app()->resolve(RequestAnnotationManager::class, ['request'=>$this]); |
|
| 459 | + $annotation->annotation($method, $key); |
|
| 460 | 460 | |
| 461 | - if(isset($this->inputs[$key]) && is_array($this->inputs[$key])){
|
|
| 461 | + if (isset($this->inputs[$key]) && is_array($this->inputs[$key])) {
|
|
| 462 | 462 | |
| 463 | 463 | $inputKeys = $this->inputs[$key]; |
| 464 | 464 | |
| 465 | 465 | $this->inputs[$key] = []; |
| 466 | - foreach ($inputKeys as $input){
|
|
| 466 | + foreach ($inputKeys as $input) {
|
|
| 467 | 467 | |
| 468 | 468 | $this->{$key} = $input;
|
| 469 | 469 | $keyMethod = $this->{$method}();
|
| 470 | 470 | $this->inputs[$key][] = $keyMethod; |
| 471 | 471 | } |
| 472 | 472 | } |
| 473 | - else{
|
|
| 474 | - if(isset($this->inputs[$key])){
|
|
| 473 | + else {
|
|
| 474 | + if (isset($this->inputs[$key])) {
|
|
| 475 | 475 | $keyMethod = $this->{$method}();
|
| 476 | 476 | $this->inputs[$key] = $keyMethod; |
| 477 | 477 | } |
@@ -489,8 +489,8 @@ discard block |
||
| 489 | 489 | {
|
| 490 | 490 | // the auto object validate property is the property |
| 491 | 491 | // where all of your request values are automatically validated. |
| 492 | - if(property_exists($this,'autoObjectValidate') |
|
| 493 | - && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)){
|
|
| 492 | + if (property_exists($this, 'autoObjectValidate') |
|
| 493 | + && is_array($this->autoObjectValidate) && count($this->autoObjectValidate)) {
|
|
| 494 | 494 | $this->autoValidate('autoObjectValidate');
|
| 495 | 495 | } |
| 496 | 496 | } |