File tree Expand file tree Collapse file tree 10 files changed +1217
-48
lines changed Expand file tree Collapse file tree 10 files changed +1217
-48
lines changed Original file line number Diff line number Diff line change 33namespace tobimori \DreamForm \Guards ;
44
55use Kirby \Cms \App ;
6- use Kirby \Data \Json ;
76use Kirby \Http \Remote ;
87use Kirby \Toolkit \A ;
98use tobimori \DreamForm \DreamForm ;
@@ -13,13 +12,6 @@ class AkismetGuard extends Guard
1312{
1413 public const TYPE = 'akismet ' ;
1514
16- /**
17- * Akismet guard doesn't trigger pre-validation checks
18- */
19- public function run (): void
20- {
21- }
22-
2315 /**
2416 * Returns the content to be sent to Akismet
2517 */
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public function csrf(): string
2828 /**
2929 * Validate the CSRF token
3030 */
31- public function run (): void
31+ public function precognitiveRun (): void
3232 {
3333 $ token = $ this ->csrf ();
3434 $ submitted = SubmissionPage::valueFromBody ('dreamform-csrf ' );
Original file line number Diff line number Diff line change @@ -23,6 +23,21 @@ public function postValidation(SubmissionPage $submission): void
2323 {
2424 }
2525
26+ /**
27+ * Run the guard
28+ */
29+ public function run (): void
30+ {
31+ $ this ->precognitiveRun ();
32+ }
33+
34+ /**
35+ * Precognitive run
36+ */
37+ public function precognitiveRun (): void
38+ {
39+ }
40+
2641 /**
2742 * Reports the submission as spam to a third-party service
2843 */
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ public function fieldName(): string
2323 return 'dreamform-guard ' ;
2424 }
2525
26- public function run (): void
26+ public function precognitiveRun (): void
2727 {
2828 $ value = SubmissionPage::valueFromBody ($ this ->fieldName ());
2929
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ class LicenseGuard extends Guard
99{
1010 public const TYPE = 'license ' ;
1111
12- public function run (): void
12+ public function precognitiveRun (): void
1313 {
1414 $ license = License::fromDisk ();
1515 if (!$ license ->isValid () && !App::instance ()->system ()->isLocal () && !App::instance ()->user ()?->isAdmin()) {
Original file line number Diff line number Diff line change @@ -271,16 +271,20 @@ public function submit(bool $precognition = false): SubmissionPage
271271 ->applyHook ('before ' );
272272 }
273273
274- $ submission = $ submission ->collectMetadata ()
275- ->handleGuards ()
276- ->handleFields ();
274+ $ submission = $ submission ->collectMetadata ();
277275
278276 if (!$ precognition ) {
279277 $ submission = $ submission
278+ ->handleGuards ()
279+ ->handleFields ()
280280 ->handleGuards (postValidation: true )
281281 ->handleActions ()
282282 ->finalize ()
283283 ->handleAfterSubmitFields ();
284+ } else {
285+ $ submission = $ submission
286+ ->handlePrecognitiveGuards ()
287+ ->handleFields ();
284288 }
285289 } catch (Exception $ e ) {
286290 // PerformerExceptions stop the workflow early, and not save the submission
Original file line number Diff line number Diff line change @@ -32,6 +32,19 @@ public function applyHook(string $type = 'before'): SubmissionPage
3232 );
3333 }
3434
35+ /**
36+ * Handles the form submission precognitive guards
37+ * @internal
38+ */
39+ public function handlePrecognitiveGuards (): SubmissionPage
40+ {
41+ foreach ($ this ->form ()->guards () as $ guard ) {
42+ $ guard ->precognitiveRun ();
43+ }
44+
45+ return $ this ;
46+ }
47+
3548 /**
3649 * Handles the form submission guards
3750 * @internal
Original file line number Diff line number Diff line change 1515 "tobimori\\ DreamForm\\ " : " classes"
1616 }
1717 },
18+ "minimum-stability" : " RC" ,
1819 "require" : {
1920 "php" : " >=8.3.0" ,
2021 "getkirby/composer-installer" : " ^1.2.1"
3132 },
3233 "extra" : {
3334 "kirby-cms-path" : false
35+ },
36+ "require-dev" : {
37+ "getkirby/cms" : " ^5"
3438 }
3539}
You can’t perform that action at this time.
0 commit comments