2323use Cake \Utility \Hash ;
2424use Cake \Validation \ValidatorAwareInterface ;
2525use Cake \Validation \ValidatorAwareTrait ;
26+ use ReflectionMethod ;
27+ use function Cake \Core \deprecationWarning ;
2628
2729/**
2830 * Form abstraction used to create forms not tied to ORM backed models,
3335 *
3436 * This class is most useful when subclassed. In a subclass you
3537 * should define the `_buildSchema`, `validationDefault` and optionally,
36- * the `_execute ` methods. These allow you to declare your form's
38+ * the `process ` methods. These allow you to declare your form's
3739 * fields, validation and primary action respectively.
3840 *
3941 * Forms are conventionally placed in the `App\Form` namespace.
@@ -243,7 +245,7 @@ public function setErrors(array $errors)
243245 /**
244246 * Execute the form if it is valid.
245247 *
246- * First validates the form, then calls the `_execute ()` hook method.
248+ * First validates the form, then calls the `process ()` hook method.
247249 * This hook method can be implemented in subclasses to perform
248250 * the action of the form. This may be sending email, interacting
249251 * with a remote API, or anything else you may need.
@@ -256,21 +258,45 @@ public function setErrors(array $errors)
256258 * @param array $data Form data.
257259 * @param array<string, mixed> $options List of options.
258260 * @return bool False on validation failure, otherwise returns the
259- * result of the `_execute ()` method.
261+ * result of the `process ()` method.
260262 */
261263 public function execute (array $ data , array $ options = []): bool
262264 {
263- $ this ->_data = $ data ;
265+ // check for deprecated _execute() method - https://github.com/cakephp/cakephp/pull/18725
266+ $ childClass = static ::class;
267+ $ parentClass = self ::class;
268+ $ method = new ReflectionMethod ($ childClass , '_execute ' );
269+ $ hasOverwrittenExecute = $ method ->getDeclaringClass ()->getName () !== $ parentClass ;
264270
271+ $ this ->_data = $ data ;
265272 $ options += ['validate ' => true ];
266273
267274 if ($ options ['validate ' ] === false ) {
268- return $ this ->_execute ($ data );
275+ if ($ hasOverwrittenExecute ) {
276+ deprecationWarning (
277+ '5.3.0 ' ,
278+ 'The _execute() method is deprecated. Override the process() method instead. ' ,
279+ );
280+
281+ return $ this ->_execute ($ data );
282+ }
283+
284+ return $ this ->process ($ data );
269285 }
270286
271287 $ validator = $ options ['validate ' ] === true ? static ::DEFAULT_VALIDATOR : $ options ['validate ' ];
288+ $ validateResult = $ this ->validate ($ data , $ validator );
289+
290+ if ($ hasOverwrittenExecute ) {
291+ deprecationWarning (
292+ '5.3.0 ' ,
293+ 'The _execute() method is deprecated. Override the process() method instead. ' ,
294+ );
272295
273- return $ this ->validate ($ data , $ validator ) && $ this ->_execute ($ data );
296+ return $ validateResult && $ this ->_execute ($ data );
297+ }
298+
299+ return $ validateResult && $ this ->process ($ data );
274300 }
275301
276302 /**
@@ -282,6 +308,19 @@ public function execute(array $data, array $options = []): bool
282308 * @return bool
283309 */
284310 protected function _execute (array $ data ): bool
311+ {
312+ return $ this ->process ($ data );
313+ }
314+
315+ /**
316+ * Hook method to be implemented in subclasses.
317+ *
318+ * Used by `execute()` to execute the form's action.
319+ *
320+ * @param array $data Form data.
321+ * @return bool
322+ */
323+ protected function process (array $ data ): bool
285324 {
286325 return true ;
287326 }
0 commit comments