|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Port\Request\Abstracts; |
|
4
|
|
|
|
|
5
|
|
|
use App\Containers\Authorization\Traits\AuthorizationTrait; |
|
6
|
|
|
use App\Port\Exception\Exceptions\ValidationFailedException; |
|
7
|
|
|
use App\Port\HashId\Traits\HashIdTrait; |
|
8
|
|
|
use Illuminate\Contracts\Validation\Validator; |
|
9
|
|
|
use Illuminate\Foundation\Http\FormRequest as LaravelFrameworkRequest; |
|
10
|
|
|
use Illuminate\Support\Facades\Config; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class Request |
|
14
|
|
|
* |
|
15
|
|
|
* A.K.A (app/Http/Requests/Request.php) |
|
16
|
|
|
* |
|
17
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class Request extends LaravelFrameworkRequest |
|
20
|
|
|
{ |
|
21
|
|
|
|
|
22
|
|
|
use HashIdTrait; |
|
23
|
|
|
use AuthorizationTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Overriding this function to modify the any user input before |
|
27
|
|
|
* applying the validation rules. |
|
28
|
|
|
* |
|
29
|
|
|
* @return array |
|
30
|
|
|
*/ |
|
31
|
|
|
public function all() |
|
32
|
|
|
{ |
|
33
|
|
|
$requestData = parent::all(); |
|
34
|
|
|
|
|
35
|
|
|
// the hash ID feature must be enabled to use this decoder feature. |
|
36
|
|
|
if (Config::get('hello.hash-id') && isset($this->decode) && !empty($this->decode)) { |
|
|
|
|
|
|
37
|
|
|
$requestData = $this->decodeHashedIdsBeforeValidatingThem($requestData); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
if (isset($this->urlParameters) && !empty($this->urlParameters)) { |
|
|
|
|
|
|
41
|
|
|
$requestData = $this->applyValidationRulesToUrlParams($requestData); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return $requestData; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* apply validation rules to the ID's in the URL, since Laravel |
|
49
|
|
|
* doesn't validate them by default! |
|
50
|
|
|
* |
|
51
|
|
|
* Now you can use validation riles like this: `'id' => 'required|integer|exists:items,id'` |
|
52
|
|
|
* |
|
53
|
|
|
* @param array $requestData |
|
54
|
|
|
* |
|
55
|
|
|
* @return array |
|
56
|
|
|
*/ |
|
57
|
|
|
private function applyValidationRulesToUrlParams(Array $requestData) |
|
58
|
|
|
{ |
|
59
|
|
|
foreach ($this->urlParameters as $param) { |
|
|
|
|
|
|
60
|
|
|
$requestData[$param] = $this->route($param); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $requestData; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Overriding this function to throw a custom |
|
68
|
|
|
* exception instead of the default Laravel exception. |
|
69
|
|
|
* |
|
70
|
|
|
* @param \Illuminate\Contracts\Validation\Validator $validator |
|
71
|
|
|
* |
|
72
|
|
|
* @return mixed|void |
|
73
|
|
|
*/ |
|
74
|
|
|
public function failedValidation(Validator $validator) |
|
75
|
|
|
{ |
|
76
|
|
|
throw new ValidationFailedException($validator->getMessageBag()); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.