@@ -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,42 +184,42 @@ 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){
|
|
| 194 | - if(isset($requestRules[$rule])){
|
|
| 195 | - if(!preg_match('@'.$requestRules[$rule].'@',$this->inputs[$key])){
|
|
| 196 | - exception($rule,['key'=>$key.':'.$this->inputs[$key]]) |
|
| 191 | + $rules = explode(":", $rule[1]);
|
|
| 192 | + if (isset($this->inputs[$key]) && !is_array($this->inputs[$key])) {
|
|
| 193 | + foreach ($rules as $rule) {
|
|
| 194 | + if (isset($requestRules[$rule])) {
|
|
| 195 | + if (!preg_match('@'.$requestRules[$rule].'@', $this->inputs[$key])) {
|
|
| 196 | + exception($rule, ['key'=>$key.':'.$this->inputs[$key]]) |
|
| 197 | 197 | ->invalidArgument($key.':'.$this->inputs[$key].' input value is not valid for '.$rule.' request rule'); |
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | - else{
|
|
| 202 | + else {
|
|
| 203 | 203 | |
| 204 | - foreach ($this->inputs[$key] as $ikey=>$input){
|
|
| 204 | + foreach ($this->inputs[$key] as $ikey=>$input) {
|
|
| 205 | 205 | |
| 206 | - if(!is_array($input)){
|
|
| 207 | - foreach($rules as $rule){
|
|
| 208 | - if(isset($requestRules[$rule])){
|
|
| 209 | - if(!preg_match('@'.$requestRules[$rule].'@',$input)){
|
|
| 210 | - exception($rule,['key'=>''.$key.':'.$input]) |
|
| 206 | + if (!is_array($input)) {
|
|
| 207 | + foreach ($rules as $rule) {
|
|
| 208 | + if (isset($requestRules[$rule])) {
|
|
| 209 | + if (!preg_match('@'.$requestRules[$rule].'@', $input)) {
|
|
| 210 | + exception($rule, ['key'=>''.$key.':'.$input]) |
|
| 211 | 211 | ->invalidArgument($key.':'.$input.' input value is not valid for '.$rule.' request rule'); |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | - else{
|
|
| 216 | + else {
|
|
| 217 | 217 | |
| 218 | - foreach ($input as $ikey=>$item){
|
|
| 219 | - foreach($rules as $rule){
|
|
| 220 | - if(isset($requestRules[$rule])){
|
|
| 221 | - if(!preg_match('@'.$requestRules[$rule].'@',$item)){
|
|
| 222 | - exception($rule,['key'=>''.$key.':'.$item]) |
|
| 218 | + foreach ($input as $ikey=>$item) {
|
|
| 219 | + foreach ($rules as $rule) {
|
|
| 220 | + if (isset($requestRules[$rule])) {
|
|
| 221 | + if (!preg_match('@'.$requestRules[$rule].'@', $item)) {
|
|
| 222 | + exception($rule, ['key'=>''.$key.':'.$item]) |
|
| 223 | 223 | ->invalidArgument($key.':'.$item.' input value is not valid for '.$rule.' request rule'); |
| 224 | 224 | } |
| 225 | 225 | } |