@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @param ApplicationContracts $app |
| 26 | 26 | * @param $request |
| 27 | 27 | */ |
| 28 | - public function __construct(ApplicationContracts $app,$request) |
|
| 28 | + public function __construct(ApplicationContracts $app, $request) |
|
| 29 | 29 | {
|
| 30 | 30 | parent::__construct($app); |
| 31 | 31 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param $key |
| 42 | 42 | * @return mixed|void |
| 43 | 43 | */ |
| 44 | - public function annotation($method,$key) |
|
| 44 | + public function annotation($method, $key) |
|
| 45 | 45 | {
|
| 46 | 46 | //set annotation value with getting reflection |
| 47 | 47 | $reflection = $this->getReflection('reflection')->reflectionMethodParams($method);
|
@@ -66,18 +66,18 @@ discard block |
||
| 66 | 66 | * @param string $key |
| 67 | 67 | * @param null|string $data |
| 68 | 68 | */ |
| 69 | - private function catchException($key,$data) |
|
| 69 | + private function catchException($key, $data) |
|
| 70 | 70 | {
|
| 71 | - if(isset($this->exceptionParams[$key])){
|
|
| 71 | + if (isset($this->exceptionParams[$key])) {
|
|
| 72 | 72 | |
| 73 | 73 | //get key params for exception params |
| 74 | 74 | $keyParams = ($this->exceptionParams[$key]['params']) ?? []; |
| 75 | 75 | |
| 76 | 76 | //catch exception |
| 77 | - exception($this->exceptionParams[$key]['name'],$keyParams) |
|
| 77 | + exception($this->exceptionParams[$key]['name'], $keyParams) |
|
| 78 | 78 | ->unexpectedValue($this->exceptionParams[$key]['name'].' input value is not valid as format ('.$data.')');
|
| 79 | 79 | } |
| 80 | - else{
|
|
| 80 | + else {
|
|
| 81 | 81 | //catch exception |
| 82 | 82 | exception()->unexpectedValue($key.' input value is not valid as format ('.$data.')');
|
| 83 | 83 | } |
@@ -90,23 +90,23 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | private function getException($key) |
| 92 | 92 | {
|
| 93 | - if(preg_match('@exception\((.*?)\)|exception\((.*?)\)\r\n@is',$this->annotation,$exception)){
|
|
| 93 | + if (preg_match('@exception\((.*?)\)|exception\((.*?)\)\r\n@is', $this->annotation, $exception)) {
|
|
| 94 | 94 | |
| 95 | - $exceptionSpaceExplode = explode(" ",$exception[1]);
|
|
| 95 | + $exceptionSpaceExplode = explode(" ", $exception[1]);
|
|
| 96 | 96 | |
| 97 | - foreach ($exceptionSpaceExplode as $exceptions){
|
|
| 98 | - $exceptionsDotExplode = explode(":",$exceptions);
|
|
| 97 | + foreach ($exceptionSpaceExplode as $exceptions) {
|
|
| 98 | + $exceptionsDotExplode = explode(":", $exceptions);
|
|
| 99 | 99 | $this->exceptionParams[$key][$exceptionsDotExplode[0]] = $exceptionsDotExplode[1]; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if(isset($this->exceptionParams[$key]['params'])){
|
|
| 102 | + if (isset($this->exceptionParams[$key]['params'])) {
|
|
| 103 | 103 | |
| 104 | - $paramsCommaExplode = explode(",",$this->exceptionParams[$key]['params']);
|
|
| 104 | + $paramsCommaExplode = explode(",", $this->exceptionParams[$key]['params']);
|
|
| 105 | 105 | unset($this->exceptionParams[$key]['params']); |
| 106 | 106 | |
| 107 | - foreach ($paramsCommaExplode as $params){
|
|
| 108 | - $paramsEqualExplode = explode("=",$params);
|
|
| 109 | - if(isset($paramsEqualExplode[0]) && isset($paramsEqualExplode[1])){
|
|
| 107 | + foreach ($paramsCommaExplode as $params) {
|
|
| 108 | + $paramsEqualExplode = explode("=", $params);
|
|
| 109 | + if (isset($paramsEqualExplode[0]) && isset($paramsEqualExplode[1])) {
|
|
| 110 | 110 | $this->exceptionParams[$key]['params'][$paramsEqualExplode[0]] = $paramsEqualExplode[1]; |
| 111 | 111 | } |
| 112 | 112 | } |
@@ -123,37 +123,37 @@ discard block |
||
| 123 | 123 | {
|
| 124 | 124 | // with the method based regex annotation, |
| 125 | 125 | // we check the rule definition for our requests. |
| 126 | - if(preg_match('@regex\((.*?)\)|regex\((.*?)\)\r\n@is',$this->annotation,$regex)){
|
|
| 127 | - if(isset($this->inputs[$key])){
|
|
| 126 | + if (preg_match('@regex\((.*?)\)|regex\((.*?)\)\r\n@is', $this->annotation, $regex)) {
|
|
| 127 | + if (isset($this->inputs[$key])) {
|
|
| 128 | 128 | |
| 129 | 129 | // for the definition of rules, |
| 130 | 130 | // our inputs can be array and in this case we offer array option for user comfort. |
| 131 | - if(is_array($this->inputs[$key])){
|
|
| 131 | + if (is_array($this->inputs[$key])) {
|
|
| 132 | 132 | |
| 133 | - foreach ($this->inputs[$key] as $this->inputsKey => $this->inputsValue){
|
|
| 133 | + foreach ($this->inputs[$key] as $this->inputsKey => $this->inputsValue) {
|
|
| 134 | 134 | |
| 135 | - if(is_array($this->inputsValue)){
|
|
| 135 | + if (is_array($this->inputsValue)) {
|
|
| 136 | 136 | |
| 137 | - foreach ($this->inputsValue as $inputsValueKey => $inputsValueItem){
|
|
| 138 | - if(!preg_match('@'.$regex[1].'@is',$inputsValueItem)){
|
|
| 139 | - $this->catchException($key,$regex[1]); |
|
| 137 | + foreach ($this->inputsValue as $inputsValueKey => $inputsValueItem) {
|
|
| 138 | + if (!preg_match('@'.$regex[1].'@is', $inputsValueItem)) {
|
|
| 139 | + $this->catchException($key, $regex[1]); |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | } |
| 144 | - else{
|
|
| 145 | - if(!preg_match('@'.$regex[1].'@is',$this->inputsValue)){
|
|
| 146 | - $this->catchException($key,$regex[1]); |
|
| 144 | + else {
|
|
| 145 | + if (!preg_match('@'.$regex[1].'@is', $this->inputsValue)) {
|
|
| 146 | + $this->catchException($key, $regex[1]); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | - else{
|
|
| 152 | + else {
|
|
| 153 | 153 | |
| 154 | 154 | // we control the regex rule that evaluates when only string arrives. |
| 155 | - if(!preg_match('@'.$regex[1].'@is',$this->inputs[$key])){
|
|
| 156 | - $this->catchException($key,$regex[1]); |
|
| 155 | + if (!preg_match('@'.$regex[1].'@is', $this->inputs[$key])) {
|
|
| 156 | + $this->catchException($key, $regex[1]); |
|
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -168,9 +168,9 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | private function getRemove($key) |
| 170 | 170 | {
|
| 171 | - if(preg_match('@remove\((.*?)\)\r\n@is',$this->annotation,$remove)){
|
|
| 172 | - if(isset($this->inputs[$key])){
|
|
| 173 | - if(preg_match('@'.$remove[1].'@is',$this->inputs[$key])){
|
|
| 171 | + if (preg_match('@remove\((.*?)\)\r\n@is', $this->annotation, $remove)) {
|
|
| 172 | + if (isset($this->inputs[$key])) {
|
|
| 173 | + if (preg_match('@'.$remove[1].'@is', $this->inputs[$key])) {
|
|
| 174 | 174 | unset($this->inputs[$key]); |
| 175 | 175 | } |
| 176 | 176 | } |
@@ -184,33 +184,33 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | private function getRules($key) |
| 186 | 186 | {
|
| 187 | - if(preg_match('@rule\((.*?)\)|rule\((.*?)\)\r\n@is',$this->annotation,$rule)){
|
|
| 187 | + if (preg_match('@rule\((.*?)\)|rule\((.*?)\)\r\n@is', $this->annotation, $rule)) {
|
|
| 188 | 188 | |
| 189 | 189 | $requestRules = $this->getReflection('rules');
|
| 190 | 190 | |
| 191 | - $rules = explode(":",$rule[1]);
|
|
| 192 | - if(isset($this->inputs[$key]) && !is_array($this->inputs[$key])){
|
|
| 193 | - foreach($rules as $rule){
|
|
| 191 | + $rules = explode(":", $rule[1]);
|
|
| 192 | + if (isset($this->inputs[$key]) && !is_array($this->inputs[$key])) {
|
|
| 193 | + foreach ($rules as $rule) {
|
|
| 194 | 194 | |
| 195 | - $ruleExplode = explode('#',$rule);
|
|
| 195 | + $ruleExplode = explode('#', $rule);
|
|
| 196 | 196 | $rule = $ruleExplode[0]; |
| 197 | 197 | |
| 198 | - if(isset($requestRules[$rule])){
|
|
| 199 | - if(!preg_match('@'.$requestRules[$rule].'@',$this->inputs[$key])){
|
|
| 200 | - exception($rule,['key'=>$key.':'.$this->inputs[$key]]) |
|
| 198 | + if (isset($requestRules[$rule])) {
|
|
| 199 | + if (!preg_match('@'.$requestRules[$rule].'@', $this->inputs[$key])) {
|
|
| 200 | + exception($rule, ['key'=>$key.':'.$this->inputs[$key]]) |
|
| 201 | 201 | ->invalidArgument($key.':'.$this->inputs[$key].' input value is not valid for '.$rule.' request rule'); |
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | //rule method |
| 206 | - if(!isset($requestRules[$rule])){
|
|
| 207 | - $this->request->call(function() use($rule,$key,$ruleExplode){
|
|
| 208 | - if(method_exists($this,$ruleMethod = '__rule'.ucfirst($rule))){
|
|
| 209 | - if(isset($ruleExplode[1])){
|
|
| 206 | + if (!isset($requestRules[$rule])) {
|
|
| 207 | + $this->request->call(function() use($rule, $key, $ruleExplode){
|
|
| 208 | + if (method_exists($this, $ruleMethod = '__rule'.ucfirst($rule))) {
|
|
| 209 | + if (isset($ruleExplode[1])) {
|
|
| 210 | 210 | |
| 211 | 211 | $reValueList = []; |
| 212 | - foreach (explode(',',$ruleExplode[1]) as $reValue){
|
|
| 213 | - $reValueExplode = explode('=',$reValue);
|
|
| 212 | + foreach (explode(',', $ruleExplode[1]) as $reValue) {
|
|
| 213 | + $reValueExplode = explode('=', $reValue);
|
|
| 214 | 214 | $reValueListKey = $reValueExplode[0]; |
| 215 | 215 | $reValueListValue = (isset($reValueExplode[1])) ? $reValueExplode[1] : null; |
| 216 | 216 | |
@@ -218,10 +218,10 @@ discard block |
||
| 218 | 218 | |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $this->{$ruleMethod}($key,$this->inputs[$key],$reValueList);
|
|
| 221 | + $this->{$ruleMethod}($key, $this->inputs[$key], $reValueList);
|
|
| 222 | 222 | } |
| 223 | - else{
|
|
| 224 | - $this->{$ruleMethod}($key,$this->inputs[$key]);
|
|
| 223 | + else {
|
|
| 224 | + $this->{$ruleMethod}($key, $this->inputs[$key]);
|
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | } |
@@ -229,27 +229,27 @@ discard block |
||
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | - else{
|
|
| 232 | + else {
|
|
| 233 | 233 | |
| 234 | - foreach ($this->inputs[$key] as $ikey=>$input){
|
|
| 234 | + foreach ($this->inputs[$key] as $ikey=>$input) {
|
|
| 235 | 235 | |
| 236 | - if(!is_array($input)){
|
|
| 237 | - foreach($rules as $rule){
|
|
| 238 | - if(isset($requestRules[$rule])){
|
|
| 239 | - if(!preg_match('@'.$requestRules[$rule].'@',$input)){
|
|
| 240 | - exception($rule,['key'=>''.$key.':'.$input]) |
|
| 236 | + if (!is_array($input)) {
|
|
| 237 | + foreach ($rules as $rule) {
|
|
| 238 | + if (isset($requestRules[$rule])) {
|
|
| 239 | + if (!preg_match('@'.$requestRules[$rule].'@', $input)) {
|
|
| 240 | + exception($rule, ['key'=>''.$key.':'.$input]) |
|
| 241 | 241 | ->invalidArgument($key.':'.$input.' input value is not valid for '.$rule.' request rule'); |
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | - else{
|
|
| 246 | + else {
|
|
| 247 | 247 | |
| 248 | - foreach ($input as $ikey=>$item){
|
|
| 249 | - foreach($rules as $rule){
|
|
| 250 | - if(isset($requestRules[$rule])){
|
|
| 251 | - if(!preg_match('@'.$requestRules[$rule].'@',$item)){
|
|
| 252 | - exception($rule,['key'=>''.$key.':'.$item]) |
|
| 248 | + foreach ($input as $ikey=>$item) {
|
|
| 249 | + foreach ($rules as $rule) {
|
|
| 250 | + if (isset($requestRules[$rule])) {
|
|
| 251 | + if (!preg_match('@'.$requestRules[$rule].'@', $item)) {
|
|
| 252 | + exception($rule, ['key'=>''.$key.':'.$item]) |
|
| 253 | 253 | ->invalidArgument($key.':'.$item.' input value is not valid for '.$rule.' request rule'); |
| 254 | 254 | } |
| 255 | 255 | } |
@@ -76,8 +76,7 @@ discard block |
||
| 76 | 76 | //catch exception |
| 77 | 77 | exception($this->exceptionParams[$key]['name'],$keyParams) |
| 78 | 78 | ->unexpectedValue($this->exceptionParams[$key]['name'].' input value is not valid as format ('.$data.')');
|
| 79 | - } |
|
| 80 | - else{
|
|
| 79 | + } else{
|
|
| 81 | 80 | //catch exception |
| 82 | 81 | exception()->unexpectedValue($key.' input value is not valid as format ('.$data.')');
|
| 83 | 82 | } |
@@ -140,16 +139,14 @@ discard block |
||
| 140 | 139 | } |
| 141 | 140 | } |
| 142 | 141 | |
| 143 | - } |
|
| 144 | - else{
|
|
| 142 | + } else{
|
|
| 145 | 143 | if(!preg_match('@'.$regex[1].'@is',$this->inputsValue)){
|
| 146 | 144 | $this->catchException($key,$regex[1]); |
| 147 | 145 | } |
| 148 | 146 | } |
| 149 | 147 | |
| 150 | 148 | } |
| 151 | - } |
|
| 152 | - else{
|
|
| 149 | + } else{
|
|
| 153 | 150 | |
| 154 | 151 | // we control the regex rule that evaluates when only string arrives. |
| 155 | 152 | if(!preg_match('@'.$regex[1].'@is',$this->inputs[$key])){
|
@@ -219,8 +216,7 @@ discard block |
||
| 219 | 216 | } |
| 220 | 217 | |
| 221 | 218 | $this->{$ruleMethod}($key,$this->inputs[$key],$reValueList);
|
| 222 | - } |
|
| 223 | - else{
|
|
| 219 | + } else{
|
|
| 224 | 220 | $this->{$ruleMethod}($key,$this->inputs[$key]);
|
| 225 | 221 | } |
| 226 | 222 | |
@@ -228,8 +224,7 @@ discard block |
||
| 228 | 224 | }); |
| 229 | 225 | } |
| 230 | 226 | } |
| 231 | - } |
|
| 232 | - else{
|
|
| 227 | + } else{
|
|
| 233 | 228 | |
| 234 | 229 | foreach ($this->inputs[$key] as $ikey=>$input){
|
| 235 | 230 | |
@@ -242,8 +237,7 @@ discard block |
||
| 242 | 237 | } |
| 243 | 238 | } |
| 244 | 239 | } |
| 245 | - } |
|
| 246 | - else{
|
|
| 240 | + } else{
|
|
| 247 | 241 | |
| 248 | 242 | foreach ($input as $ikey=>$item){
|
| 249 | 243 | foreach($rules as $rule){
|