@@ -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($this->exceptionParams[$key]['name'].' 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,37 +119,37 @@ 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){
|
|
| 129 | + foreach ($this->inputs[$key] as $this->inputsKey => $this->inputsValue) {
|
|
| 130 | 130 | |
| 131 | - if(is_array($this->inputsValue)){
|
|
| 131 | + if (is_array($this->inputsValue)) {
|
|
| 132 | 132 | |
| 133 | - foreach ($this->inputsValue as $inputsValueKey => $inputsValueItem){
|
|
| 134 | - if(!preg_match('@'.$regex[1].'@is',$inputsValueItem)){
|
|
| 135 | - $this->catchException($key,$regex[1]); |
|
| 133 | + foreach ($this->inputsValue as $inputsValueKey => $inputsValueItem) {
|
|
| 134 | + if (!preg_match('@'.$regex[1].'@is', $inputsValueItem)) {
|
|
| 135 | + $this->catchException($key, $regex[1]); |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | } |
| 140 | - else{
|
|
| 141 | - if(!preg_match('@'.$regex[1].'@is',$this->inputsValue)){
|
|
| 142 | - $this->catchException($key,$regex[1]); |
|
| 140 | + else {
|
|
| 141 | + if (!preg_match('@'.$regex[1].'@is', $this->inputsValue)) {
|
|
| 142 | + $this->catchException($key, $regex[1]); |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | - else{
|
|
| 148 | + else {
|
|
| 149 | 149 | |
| 150 | 150 | // we control the regex rule that evaluates when only string arrives. |
| 151 | - if(!preg_match('@'.$regex[1].'@is',$this->inputs[$key])){
|
|
| 152 | - $this->catchException($key,$regex[1]); |
|
| 151 | + if (!preg_match('@'.$regex[1].'@is', $this->inputs[$key])) {
|
|
| 152 | + $this->catchException($key, $regex[1]); |
|
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | } |
@@ -164,9 +164,9 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | private function getRemove($key) |
| 166 | 166 | {
|
| 167 | - if(preg_match('@remove\((.*?)\)\r\n@is',$this->annotation,$remove)){
|
|
| 168 | - if(isset($this->inputs[$key])){
|
|
| 169 | - if(preg_match('@'.$remove[1].'@is',$this->inputs[$key])){
|
|
| 167 | + if (preg_match('@remove\((.*?)\)\r\n@is', $this->annotation, $remove)) {
|
|
| 168 | + if (isset($this->inputs[$key])) {
|
|
| 169 | + if (preg_match('@'.$remove[1].'@is', $this->inputs[$key])) {
|
|
| 170 | 170 | unset($this->inputs[$key]); |
| 171 | 171 | } |
| 172 | 172 | } |
@@ -180,42 +180,42 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | private function getRules($key) |
| 182 | 182 | {
|
| 183 | - if(preg_match('@rule\((.*?)\)\r\n@is',$this->annotation,$rule)){
|
|
| 183 | + if (preg_match('@rule\((.*?)\)\r\n@is', $this->annotation, $rule)) {
|
|
| 184 | 184 | |
| 185 | 185 | $requestRules = $this->getReflection('rules');
|
| 186 | 186 | |
| 187 | - $rules = explode(":",$rule[1]);
|
|
| 188 | - if(isset($this->inputs[$key]) && !is_array($this->inputs[$key])){
|
|
| 189 | - foreach($rules as $rule){
|
|
| 190 | - if(isset($requestRules[$rule])){
|
|
| 191 | - if(!preg_match('@'.$requestRules[$rule].'@',$this->inputs[$key])){
|
|
| 192 | - exception($rule,['key'=>$key]) |
|
| 187 | + $rules = explode(":", $rule[1]);
|
|
| 188 | + if (isset($this->inputs[$key]) && !is_array($this->inputs[$key])) {
|
|
| 189 | + foreach ($rules as $rule) {
|
|
| 190 | + if (isset($requestRules[$rule])) {
|
|
| 191 | + if (!preg_match('@'.$requestRules[$rule].'@', $this->inputs[$key])) {
|
|
| 192 | + exception($rule, ['key'=>$key]) |
|
| 193 | 193 | ->invalidArgument($this->inputs[$key].' input value is not valid for '.$rule.' request rule'); |
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | - else{
|
|
| 198 | + else {
|
|
| 199 | 199 | |
| 200 | - foreach ($this->inputs[$key] as $key=>$input){
|
|
| 200 | + foreach ($this->inputs[$key] as $key=>$input) {
|
|
| 201 | 201 | |
| 202 | - if(!is_array($input)){
|
|
| 203 | - foreach($rules as $rule){
|
|
| 204 | - if(isset($requestRules[$rule])){
|
|
| 205 | - if(!preg_match('@'.$requestRules[$rule].'@',$input)){
|
|
| 206 | - exception($rule,['key'=>$key]) |
|
| 202 | + if (!is_array($input)) {
|
|
| 203 | + foreach ($rules as $rule) {
|
|
| 204 | + if (isset($requestRules[$rule])) {
|
|
| 205 | + if (!preg_match('@'.$requestRules[$rule].'@', $input)) {
|
|
| 206 | + exception($rule, ['key'=>$key]) |
|
| 207 | 207 | ->invalidArgument($input.' input value is not valid for '.$rule.' request rule'); |
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | - else{
|
|
| 212 | + else {
|
|
| 213 | 213 | |
| 214 | - foreach ($input as $ikey=>$item){
|
|
| 215 | - foreach($rules as $rule){
|
|
| 216 | - if(isset($requestRules[$rule])){
|
|
| 217 | - if(!preg_match('@'.$requestRules[$rule].'@',$item)){
|
|
| 218 | - exception($rule,['key'=>$ikey]) |
|
| 214 | + foreach ($input as $ikey=>$item) {
|
|
| 215 | + foreach ($rules as $rule) {
|
|
| 216 | + if (isset($requestRules[$rule])) {
|
|
| 217 | + if (!preg_match('@'.$requestRules[$rule].'@', $item)) {
|
|
| 218 | + exception($rule, ['key'=>$ikey]) |
|
| 219 | 219 | ->invalidArgument($item.' input value is not valid for '.$rule.' request rule'); |
| 220 | 220 | } |
| 221 | 221 | } |