1313
1414namespace CodeIgniter \HTTP ;
1515
16- use CodeIgniter \Exceptions \RuntimeException ;
1716use ReflectionNamedType ;
1817use ReflectionParameter ;
1918
@@ -36,22 +35,12 @@ abstract class FormRequest
3635
3736 /**
3837 * When called by the framework, the current IncomingRequest is injected
39- * explicitly. When instantiated manually (e.g. in tests or commands),
40- * the constructor falls back to service('request').
41- *
42- * @throws RuntimeException if used outside of an HTTP request context.
38+ * explicitly. When instantiated manually (e.g. in tests), the constructor
39+ * falls back to service('request').
4340 */
4441 final public function __construct (?IncomingRequest $ request = null )
4542 {
46- $ resolved = $ request ?? service ('request ' );
47-
48- if (! $ resolved instanceof IncomingRequest) {
49- throw new RuntimeException (
50- static ::class . ' requires an IncomingRequest instance, got ' . $ resolved ::class . '. ' ,
51- );
52- }
53-
54- $ this ->request = $ resolved ;
43+ $ this ->request = $ request ?? service ('request ' );
5544 }
5645
5746 /**
@@ -88,12 +77,12 @@ public function messages(): array
8877 *
8978 * Override in subclasses to add authorization logic:
9079 *
91- * public function authorize (): bool
80+ * public function isAuthorized (): bool
9281 * {
9382 * return auth()->user()->can('create-posts');
9483 * }
9584 */
96- public function authorize (): bool
85+ public function isAuthorized (): bool
9786 {
9887 return true ;
9988 }
@@ -164,7 +153,7 @@ protected function failedValidation(array $errors): ResponseInterface
164153 }
165154
166155 /**
167- * Called when the authorize () check returns false. Override to customize.
156+ * Called when the isAuthorized () check returns false. Override to customize.
168157 */
169158 protected function failedAuthorization (): ResponseInterface
170159 {
@@ -261,7 +250,7 @@ protected function validationData(): array
261250 */
262251 final public function resolveRequest (): ?ResponseInterface
263252 {
264- if (! $ this ->authorize ()) {
253+ if (! $ this ->isAuthorized ()) {
265254 return $ this ->failedAuthorization ();
266255 }
267256
0 commit comments