← All changes
|
vendor/wpfluent/framework/src/WPFluent/Http/Controller.php
+16
-4
1.41
→
2.1.0
View file →
| @@ -6,8 +6,19 @@ | ||
| 6 | 6 | use ReflectionException; |
| 7 | 7 | use FluentBoards\Framework\Foundation\App; |
| 8 | 8 | use FluentBoards\Framework\Validator\ValidationException; |
| 9 | 9 | |
| 10 | +/** | |
| 11 | + * Base controller — exposes the Application, Request, and Response | |
| 12 | + * via protected properties. The `@property` annotations below are | |
| 13 | + * intentional in addition to the protected declarations: they help | |
| 14 | + * PHPStan disambiguate when a subclass declares a method with the | |
| 15 | + * same name as one of these properties (e.g., `function app()`). | |
| 16 | + * | |
| 17 | + * @property \FluentBoards\Framework\Foundation\Application $app | |
| 18 | + * @property \FluentBoards\Framework\Http\Request\Request $request | |
| 19 | + * @property \FluentBoards\Framework\Http\Response\Response $response | |
| 20 | + */ | |
| 10 | 21 | abstract class Controller |
| 11 | 22 | { |
| 12 | 23 | /** |
| 13 | 24 | * Application Instance |
| @@ -16,15 +27,15 @@ | ||
| 16 | 27 | protected $app = null; |
| 17 | 28 | |
| 18 | 29 | /** |
| 19 | 30 | * Request Instane |
| 20 | - * @var \FluentBoards\Framework\Request\Request | |
| 31 | + * @var \FluentBoards\Framework\Http\Request\Request | |
| 21 | 32 | */ |
| 22 | 33 | protected $request = null; |
| 23 | 34 | |
| 24 | 35 | /** |
| 25 | 36 | * Response Instane |
| 26 | - * @var \FluentBoards\Framework\Response\Response | |
| 37 | + * @var \FluentBoards\Framework\Http\Response\Response | |
| 27 | 38 | */ |
| 28 | 39 | protected $response = null; |
| 29 | 40 | |
| 30 | 41 | /** |
| @@ -52,8 +63,9 @@ | ||
| 52 | 63 | */ |
| 53 | 64 | public function validate($data, $rules, $messages = []) |
| 54 | 65 | { |
| 55 | 66 | try { |
| 67 | + // @phpstan-ignore-next-line | |
| 56 | 68 | $validator = $this->app->validator->make($data, $rules, $messages); |
| 57 | 69 | |
| 58 | 70 | if ($validator->validate()->fails()) { |
| 59 | 71 | throw new ValidationException( |
| @@ -118,11 +130,11 @@ | ||
| 118 | 130 | return $this->response->send($data, $code); |
| 119 | 131 | } |
| 120 | 132 | |
| 121 | 133 | /** |
| 122 | - * Send a success json response | |
| 134 | + * Send a success json response. | |
| 135 | + * | |
| 123 | 136 | * @param array $data |
| 124 | - * @param integer $code | |
| 125 | 137 | * @return \WP_REST_Response |
| 126 | 138 | */ |
| 127 | 139 | public function sendSuccess($data = []) |
| 128 | 140 | { |