@@ -69,8 +69,7 @@ discard block |
||
| 69 | 69 | //catch exception |
| 70 | 70 | exception($this->exceptionParams[$key]['name'],$keyParams) |
| 71 | 71 | ->unexpectedValue($key.' input value is not valid as format ('.$data.')');
|
| 72 | - } |
|
| 73 | - else{
|
|
| 72 | + } else{
|
|
| 74 | 73 | //catch exception |
| 75 | 74 | exception()->unexpectedValue($key.' input value is not valid as format ('.$data.')');
|
| 76 | 75 | } |
@@ -128,8 +127,7 @@ discard block |
||
| 128 | 127 | $this->catchException($key,$regex[1]); |
| 129 | 128 | } |
| 130 | 129 | } |
| 131 | - } |
|
| 132 | - else{
|
|
| 130 | + } else{
|
|
| 133 | 131 | |
| 134 | 132 | // we control the regex rule that evaluates when only string arrives. |
| 135 | 133 | if(!preg_match('@'.$regex[1].'@is',$this->inputs[$key])){
|
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * @param ApplicationContracts $app |
| 22 | 22 | * @param $request |
| 23 | 23 | */ |
| 24 | - public function __construct(ApplicationContracts $app,$request) |
|
| 24 | + public function __construct(ApplicationContracts $app, $request) |
|
| 25 | 25 | {
|
| 26 | 26 | parent::__construct($app); |
| 27 | 27 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param $key |
| 38 | 38 | * @return mixed|void |
| 39 | 39 | */ |
| 40 | - public function annotation($method,$key) |
|
| 40 | + public function annotation($method, $key) |
|
| 41 | 41 | {
|
| 42 | 42 | //set annotation value with getting reflection |
| 43 | 43 | $reflection = $this->getReflection('reflection')->reflectionMethodParams($method);
|
@@ -62,18 +62,18 @@ discard block |
||
| 62 | 62 | * @param string $key |
| 63 | 63 | * @param null|string $data |
| 64 | 64 | */ |
| 65 | - private function catchException($key,$data) |
|
| 65 | + private function catchException($key, $data) |
|
| 66 | 66 | {
|
| 67 | - if(isset($this->exceptionParams[$key])){
|
|
| 67 | + if (isset($this->exceptionParams[$key])) {
|
|
| 68 | 68 | |
| 69 | 69 | //get key params for exception params |
| 70 | 70 | $keyParams = ($this->exceptionParams[$key]['params']) ?? []; |
| 71 | 71 | |
| 72 | 72 | //catch exception |
| 73 | - exception($this->exceptionParams[$key]['name'],$keyParams) |
|
| 73 | + exception($this->exceptionParams[$key]['name'], $keyParams) |
|
| 74 | 74 | ->unexpectedValue($key.' input value is not valid as format ('.$data.')');
|
| 75 | 75 | } |
| 76 | - else{
|
|
| 76 | + else {
|
|
| 77 | 77 | //catch exception |
| 78 | 78 | exception()->unexpectedValue($key.' input value is not valid as format ('.$data.')');
|
| 79 | 79 | } |
@@ -86,23 +86,23 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | private function getException($key) |
| 88 | 88 | {
|
| 89 | - if(preg_match('@exception\((.*?)\)\r\n@is',$this->annotation,$exception)){
|
|
| 89 | + if (preg_match('@exception\((.*?)\)\r\n@is', $this->annotation, $exception)) {
|
|
| 90 | 90 | |
| 91 | - $exceptionSpaceExplode = explode(" ",$exception[1]);
|
|
| 91 | + $exceptionSpaceExplode = explode(" ", $exception[1]);
|
|
| 92 | 92 | |
| 93 | - foreach ($exceptionSpaceExplode as $exceptions){
|
|
| 94 | - $exceptionsDotExplode = explode(":",$exceptions);
|
|
| 93 | + foreach ($exceptionSpaceExplode as $exceptions) {
|
|
| 94 | + $exceptionsDotExplode = explode(":", $exceptions);
|
|
| 95 | 95 | $this->exceptionParams[$key][$exceptionsDotExplode[0]] = $exceptionsDotExplode[1]; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if(isset($this->exceptionParams[$key]['params'])){
|
|
| 98 | + if (isset($this->exceptionParams[$key]['params'])) {
|
|
| 99 | 99 | |
| 100 | - $paramsCommaExplode = explode(",",$this->exceptionParams[$key]['params']);
|
|
| 100 | + $paramsCommaExplode = explode(",", $this->exceptionParams[$key]['params']);
|
|
| 101 | 101 | unset($this->exceptionParams[$key]['params']); |
| 102 | 102 | |
| 103 | - foreach ($paramsCommaExplode as $params){
|
|
| 104 | - $paramsEqualExplode = explode("=",$params);
|
|
| 105 | - if(isset($paramsEqualExplode[0]) && isset($paramsEqualExplode[1])){
|
|
| 103 | + foreach ($paramsCommaExplode as $params) {
|
|
| 104 | + $paramsEqualExplode = explode("=", $params);
|
|
| 105 | + if (isset($paramsEqualExplode[0]) && isset($paramsEqualExplode[1])) {
|
|
| 106 | 106 | $this->exceptionParams[$key]['params'][$paramsEqualExplode[0]] = $paramsEqualExplode[1]; |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -119,24 +119,24 @@ discard block |
||
| 119 | 119 | {
|
| 120 | 120 | // with the method based regex annotation, |
| 121 | 121 | // we check the rule definition for our requests. |
| 122 | - if(preg_match('@regex\((.*?)\)\r\n@is',$this->annotation,$regex)){
|
|
| 123 | - if(isset($this->inputs[$key])){
|
|
| 122 | + if (preg_match('@regex\((.*?)\)\r\n@is', $this->annotation, $regex)) {
|
|
| 123 | + if (isset($this->inputs[$key])) {
|
|
| 124 | 124 | |
| 125 | 125 | // for the definition of rules, |
| 126 | 126 | // our inputs can be array and in this case we offer array option for user comfort. |
| 127 | - if(is_array($this->inputs[$key])){
|
|
| 127 | + if (is_array($this->inputs[$key])) {
|
|
| 128 | 128 | |
| 129 | - foreach ($this->inputs[$key] as $this->inputsKey => $this->inputsValue){
|
|
| 130 | - if(!preg_match('@'.$regex[1].'@is',$this->inputsValue)){
|
|
| 131 | - $this->catchException($key,$regex[1]); |
|
| 129 | + foreach ($this->inputs[$key] as $this->inputsKey => $this->inputsValue) {
|
|
| 130 | + if (!preg_match('@'.$regex[1].'@is', $this->inputsValue)) {
|
|
| 131 | + $this->catchException($key, $regex[1]); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | - else{
|
|
| 135 | + else {
|
|
| 136 | 136 | |
| 137 | 137 | // we control the regex rule that evaluates when only string arrives. |
| 138 | - if(!preg_match('@'.$regex[1].'@is',$this->inputs[$key])){
|
|
| 139 | - $this->catchException($key,$regex[1]); |
|
| 138 | + if (!preg_match('@'.$regex[1].'@is', $this->inputs[$key])) {
|
|
| 139 | + $this->catchException($key, $regex[1]); |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | } |
@@ -151,9 +151,9 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | private function getRemove($key) |
| 153 | 153 | {
|
| 154 | - if(preg_match('@remove\((.*?)\)\r\n@is',$this->annotation,$remove)){
|
|
| 155 | - if(isset($this->inputs[$key])){
|
|
| 156 | - if(preg_match('@'.$remove[1].'@is',$this->inputs[$key])){
|
|
| 154 | + if (preg_match('@remove\((.*?)\)\r\n@is', $this->annotation, $remove)) {
|
|
| 155 | + if (isset($this->inputs[$key])) {
|
|
| 156 | + if (preg_match('@'.$remove[1].'@is', $this->inputs[$key])) {
|
|
| 157 | 157 | unset($this->inputs[$key]); |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -167,16 +167,16 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | private function getRules($key) |
| 169 | 169 | {
|
| 170 | - if(preg_match('@rule\((.*?)\)\r\n@is',$this->annotation,$rule)){
|
|
| 170 | + if (preg_match('@rule\((.*?)\)\r\n@is', $this->annotation, $rule)) {
|
|
| 171 | 171 | |
| 172 | 172 | $requestRules = $this->getReflection('rules');
|
| 173 | 173 | |
| 174 | - $rules = explode(":",$rule[1]);
|
|
| 175 | - if(isset($this->inputs[$key])){
|
|
| 176 | - foreach($rules as $rule){
|
|
| 177 | - if(isset($requestRules[$rule])){
|
|
| 178 | - if(!preg_match('@'.$requestRules[$rule].'@',$this->inputs[$key])){
|
|
| 179 | - exception($rule,['key'=>$key]) |
|
| 174 | + $rules = explode(":", $rule[1]);
|
|
| 175 | + if (isset($this->inputs[$key])) {
|
|
| 176 | + foreach ($rules as $rule) {
|
|
| 177 | + if (isset($requestRules[$rule])) {
|
|
| 178 | + if (!preg_match('@'.$requestRules[$rule].'@', $this->inputs[$key])) {
|
|
| 179 | + exception($rule, ['key'=>$key]) |
|
| 180 | 180 | ->invalidArgument($key.' input value is not valid for '.$rule.' request rule'); |
| 181 | 181 | } |
| 182 | 182 | } |