-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforge-wire.html
More file actions
2339 lines (2197 loc) · 110 KB
/
Copy pathforge-wire.html
File metadata and controls
2339 lines (2197 loc) · 110 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en" class="scroll-smooth">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Forge Kernel - ForgeWire</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js"></script>
<link
href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css"
rel="stylesheet"
/>
<link
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
rel="stylesheet"
/>
<link rel="stylesheet" href="assets/css/docs.css" />
</head>
<body class="bg-gray-50 text-gray-900">
<!-- Navigation -->
<nav class="bg-white shadow-sm border-b">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16">
<div class="flex items-center">
<div class="flex-shrink-0">
<h1 class="text-xl font-bold text-gray-900">
Forge Kernel
</h1>
</div>
<div class="hidden sm:ml-6 sm:flex sm:space-x-8">
<a
href="index.html"
class="text-gray-900 inline-flex items-center px-1 pt-1 text-sm font-medium hover:text-blue-600"
>
Home
</a>
<a
href="getting-started.html"
class="text-gray-900 inline-flex items-center px-1 pt-1 text-sm font-medium hover:text-blue-600"
>
Getting Started
</a>
<a
href="core-concepts.html"
class="text-gray-900 inline-flex items-center px-1 pt-1 text-sm font-medium hover:text-blue-600"
>
Core Concepts
</a>
<a
href="modules.html"
class="text-blue-600 inline-flex items-center px-1 pt-1 text-sm font-medium border-b-2 border-blue-600"
>
Capabilities
</a>
<a
href="api-reference.html"
class="text-gray-900 inline-flex items-center px-1 pt-1 text-sm font-medium hover:text-blue-600"
>
API Reference
</a>
<a
href="tutorial.html"
class="text-gray-900 inline-flex items-center px-1 pt-1 text-sm font-medium hover:text-blue-600"
>
Tutorials
</a>
</div>
</div>
<div class="flex items-center sm:hidden">
<button
id="mobile-menu-button"
class="text-gray-700 hover:text-blue-600 p-2"
>
<i class="fas fa-bars text-xl"></i>
</button>
</div>
</div>
</div>
<div
id="mobile-menu"
class="sm:hidden hidden bg-white border-t border-gray-200"
>
<div class="px-2 pt-2 pb-3 space-y-1">
<a
href="index.html"
class="block px-3 py-2 text-gray-900 hover:text-blue-600"
>Home</a
>
<a
href="getting-started.html"
class="block px-3 py-2 text-gray-900 hover:text-blue-600"
>Getting Started</a
>
<a
href="core-concepts.html"
class="block px-3 py-2 text-gray-900 hover:text-blue-600"
>Core Concepts</a
>
<a
href="modules.html"
class="block px-3 py-2 text-blue-600 font-medium"
>Capabilities</a
>
<a
href="api-reference.html"
class="block px-3 py-2 text-gray-900 hover:text-blue-600"
>API Reference</a
>
<a
href="tutorial.html"
class="block px-3 py-2 text-gray-900 hover:text-blue-600"
>Tutorials</a
>
</div>
</div>
</nav>
<!-- Main Content -->
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<div class="flex flex-col lg:flex-row gap-8">
<!-- Sidebar Navigation -->
<div id="sidebar-nav" class="lg:w-1/4">
<div class="bg-white rounded-lg shadow-sm p-6 sticky top-8">
<h3 class="text-lg font-semibold text-gray-900 mb-4">
ForgeWire
</h3>
<nav class="space-y-2">
<a
href="#overview"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Overview</a
>
<a
href="#architecture"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Architecture & Design</a
>
<a
href="#installation"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Installation</a
>
<a
href="#asset-management"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Asset Management</a
>
<a
href="#basic-usage"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Basic Usage</a
>
<a
href="#component-structure"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Component Structure</a
>
<a
href="#attributes"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Attributes System</a
>
<a
href="#security"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Security Features</a
>
<a
href="#state-management"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>State Management</a
>
<a
href="#actions"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Actions & Methods</a
>
<a
href="#validation"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Validation</a
>
<a
href="#frontend"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Frontend Integration</a
>
<a
href="#architecture-features"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Architecture & Features</a
>
<a
href="#wire-protocol"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Wire Protocol</a
>
<a
href="#performance"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Performance Optimizations</a
>
<a
href="#cli-commands"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>CLI Commands</a
>
<a
href="#wire-protocol"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Wire Protocol</a
>
<a
href="#performance"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Performance</a
>
<a
href="#design-philosophy"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Design Philosophy</a
>
<a
href="#examples"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Usage Examples</a
>
<a
href="#suggestions"
class="nav-link block px-3 py-2 text-sm text-gray-700 rounded-md hover:text-blue-600"
>Suggestions</a
>
</nav>
</div>
</div>
<!-- Main Content -->
<div class="lg:w-3/4">
<div class="bg-white rounded-lg shadow-sm p-8">
<h1 class="text-4xl font-bold text-gray-900 mb-6">
ForgeWire
</h1>
<p class="text-xl text-gray-600 mb-8">
Lightweight Livewire-like reactive components for
Forge Kernel. Build dynamic interfaces with
server-side interactivity, security by default, and
support for complex data types.
</p>
<!-- Overview -->
<section id="overview" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">
Overview
</h2>
<p class="text-gray-600 mb-6">
ForgeWire provides Livewire-like reactivity for
<strong>standard Controllers</strong>. It
enables server-side interactivity without
WebSockets, JavaScript frameworks, or complex
client-side state management. Unlike other
frameworks, you don't need to create separate
"component classes" — any controller can become
reactive with simple attributes.
</p>
<div
class="bg-blue-50 border border-blue-200 rounded-lg p-6 mb-6"
>
<h2
class="font-semibold text-lg mb-4 text-blue-900"
>
ForgeWire Power, Standard Controller
Simplicity
</h2>
<div class="grid md:grid-cols-2 gap-4">
<div class="space-y-2">
<div
class="flex items-center text-blue-800"
>
<i
class="fas fa-check-circle mr-2"
></i
><span
>No separate component classes
needed</span
>
</div>
<div
class="flex items-center text-blue-800"
>
<i
class="fas fa-check-circle mr-2"
></i
><span
>Reactive standard Controllers
(#[Reactive])</span
>
</div>
<div
class="flex items-center text-blue-800"
>
<i
class="fas fa-check-circle mr-2"
></i
><span
>Security by default (explicit
attributes)</span
>
</div>
</div>
<div class="space-y-2">
<div
class="flex items-center text-blue-800"
>
<i
class="fas fa-check-circle mr-2"
></i
><span
>Session-based state with signed
checksums</span
>
</div>
<div
class="flex items-center text-blue-800"
>
<i
class="fas fa-check-circle mr-2"
></i
><span
>Native support for DTOs and
Models</span
>
</div>
<div
class="flex items-center text-blue-800"
>
<i
class="fas fa-check-circle mr-2"
></i
><span
>Ultra-lightweight JS
client</span
>
</div>
</div>
</div>
</div>
</section>
<!-- Architecture & Design -->
<section id="architecture" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">
Architecture & Design Philosophy
</h2>
<p class="text-gray-600 mb-6">
ForgeWire transforms the standard
request-response cycle into a persistent,
reactive loop. It achieves this by intercepting
requests and re-rendering specific view
fragments based on the updated state of your
controller.
</p>
<h3 class="text-lg font-semibold mb-3">
The Anatomy of a Reactive Controller
</h3>
<p class="text-gray-600 mb-4">
When a controller is marked with
<code class="bg-gray-100 px-2 py-1 rounded"
>#[Reactive]</code
>, ForgeWire manages its lifecycle:
</p>
<ul
class="list-disc list-inside space-y-2 text-gray-600 mb-4"
>
<li>
<strong>State Hydration:</strong> Upon an
action, ForgeWire restores the controller's
properties from the session state.
</li>
<li>
<strong>Action Execution:</strong> The
requested method is called with arguments
provided by the frontend.
</li>
<li>
<strong>View Re-rendering:</strong> After
the action, the controller's primary view is
re-rendered with the updated state and sent
back to the client.
</li>
<li>
<strong>Checksum Security:</strong> Every
state transfer is signed. Tampering with
state or calling unauthorized methods is
impossible.
</li>
</ul>
</section>
<!-- Basic Usage -->
<section id="basic-usage" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">
Basic Usage
</h2>
<p class="text-gray-600 mb-6">
Creating a reactive feature requires three
steps: mark the controller, mark the state, and
wrap the view with island identifiers.
</p>
<h3 class="text-lg font-semibold mb-3">
1. The Controller
</h3>
<div
class="code-block p-6 text-white rounded-lg mb-6"
>
<pre><code class="language-php">#[Middleware("web")]
#[Reactive]
final class CounterController
{
use ControllerHelper;
#[State]
public int $count = 0;
#[Route("/counter")]
public function index(): Response
{
return $this->view("pages/counter", ['count' => $this->count]);
}
#[Action]
public function increment(): void
{
$this->count++;
}
}</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3">
2. The View with Islands
</h3>
<p class="text-gray-600 mb-4">
Use
<code class="bg-gray-100 px-2 py-1 rounded"
>fw_id()</code
>
helper to create reactive islands.
<strong
>Without this helper, there is no reactivity
- the island boundary is required for
ForgeWire to work.</strong
>
You can have multiple islands per page, each
with its own reactive state.
</p>
<div
class="code-block p-6 text-white rounded-lg mb-6"
>
<pre><code class="language-php"><!-- resources/views/pages/counter.php -->
<div <?= fw_id('main-counter') ?> class="counter-box">
<h1>Count: <?= $count ?></h1>
<button fw:click="increment">Add One</button>
<div fw:target>Result: <?= $count ?></div>
</div>
<!-- Another island on same page -->
<div <?= fw_id('info-panel') ?> class="info-box">
<p fw:poll.5s>Updated at: <?= date('H:i:s') ?></p>
</div></code></pre>
</div>
<h3 class="text-lg font-semibold mb-3">
3. Island Architecture Benefits
</h3>
<ul
class="list-disc list-inside space-y-2 text-gray-600 mb-4"
>
<li>
<strong>Required Boundaries:</strong>
<code class="bg-gray-100 px-2 py-1 rounded"
>fw_id()</code
>
creates the reactive boundary - no
reactivity without it
</li>
<li>
<strong>Multiple Islands:</strong> Create
independent reactive areas on same page
</li>
<li>
<strong>Targeted Updates:</strong> Use
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:target</code
>
for efficient partial updates
</li>
<li>
<strong>Shared State:</strong> Islands can
share state using
<code class="bg-gray-100 px-2 py-1 rounded"
>#[State(shared: true)]</code
>
with
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:depends</code
>
</li>
<li>
<strong>Independent Polling:</strong> Each
island can have its own polling interval
</li>
</ul>
</section>
<!-- Attributes System -->
<section id="attributes" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">
Attributes System
</h2>
<p class="text-gray-600 mb-6">
ForgeWire attributes function as
<strong
>permissions and behavior modifiers</strong
>, not data exposure. No data is automatically
exposed to views - you explicitly pass data in
your controller methods.
</p>
<h3 class="text-lg font-semibold mb-3">
#[Reactive]
</h3>
<p class="text-gray-600 mb-4">
Applied to the class.
<strong>Permission gate</strong> - enables
ForgeWire to monitor this controller.
Controllers without this attribute are
completely ignored by the reactive kernel for
security.
</p>
<h3 class="text-lg font-semibold mb-3">
#[State(shared: bool)]
</h3>
<p class="text-gray-600 mb-4">
Applied to properties.
<strong>Permission to persist</strong> - marks
properties that should be tracked between
requests. The
<code class="bg-gray-100 px-2 py-1 rounded"
>shared: true</code
>
option allows multiple islands to access the
same state value.
</p>
<h3 class="text-lg font-semibold mb-3">
#[Action(submit: bool)]
</h3>
<p class="text-gray-600 mb-4">
Applied to methods.
<strong>Permission to call</strong> - marks the
method as callable from browser. Without this
attribute, methods cannot be invoked from
frontend. The optional
<code class="bg-gray-100 px-2 py-1 rounded"
>submit</code
>
parameter indicates this action handles form
submissions.
</p>
<h3 class="text-lg font-semibold mb-3">
#[Validate]
</h3>
<p class="text-gray-600 mb-4">
Applied to properties.
<strong>Validation rules</strong> - defines
validation rules and custom error messages for
properties that receive user input.
</p>
</section>
<section
id="state-management"
class="section-anchor mb-12"
>
<h2 class="text-2xl font-bold text-gray-900 mb-4">
State Management
</h2>
<h3 class="text-lg font-semibold mb-3">
#[State(shared: bool)]
</h3>
<p class="text-gray-600 mb-4">
Applied to public properties.
<strong>Permission to persist</strong> - marks
properties that should be tracked between
requests. Supports scalars (int, string, bool),
arrays, and objects. The
<code class="bg-gray-100 px-2 py-1 rounded"
>shared: true</code
>
option allows multiple islands to access the
same state value.
</p>
<h3 class="text-lg font-semibold mb-3">
Shared State Across Islands
</h3>
<p class="text-gray-600 mb-4">
Use
<code class="bg-gray-100 px-2 py-1 rounded"
>#[State(shared: true)]</code
>
to share state across multiple islands on the
same page. Islands must opt-in to shared
dependencies using
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:depends</code
>
to receive updates when shared state changes.
</p>
<div
class="bg-yellow-50 border border-yellow-200 rounded-lg p-4 mb-4"
>
<p class="text-sm text-yellow-800 mb-2">
<strong>⚠️ Important:</strong> Islands
<strong>must</strong> opt-in to shared state
dependencies using
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:depends</code
>. Without this directive, islands will not
receive shared state updates even if marked
with #[State(shared: true)].
</p>
</div>
<h4 class="text-md font-semibold mb-3 mt-4">
Shared State Implementation
</h4>
<div
class="code-block p-6 text-white rounded-lg mb-4"
>
<pre><code class="language-php">// Controller
#[State(shared: true)]
public int $counter = 0;
#[State(shared: true)]
public array $jobs = [];</code></pre>
</div>
<div
class="code-block p-6 text-white rounded-lg mb-6"
>
<pre><code class="language-html"><!-- View - Islands opt-in to specific shared state properties -->
<div <?= fw_id('todo-app') ?> fw:depends="counter">
<h1>Reactive Todo List counter: <?= $counter ?></h1>
<!-- Content that uses $counter -->
</div>
<div <?= fw_id('counter-app') ?> fw:depends="counter">
<h1>Counter</h1>
<button fw:click="increment">Increment</button>
<div fw:target><?= $counter ?></div>
</div>
<!-- Multiple dependencies separated by comma -->
<div <?= fw_id('queue-stats') ?> fw:depends="jobs,stats">
<h2>Statistics</h2>
<p fw:target>Total Jobs: <?= count($jobs) ?></p>
</div></code></pre>
</div>
<h4 class="text-md font-semibold mb-3">
How Shared State Works
</h4>
<ul
class="list-disc list-inside space-y-2 text-gray-600 mb-4"
>
<li>
<strong>Mark Shared:</strong> Add
<code class="bg-gray-100 px-2 py-1 rounded"
>#[State(shared: true)</code
>
to properties that should be shared
</li>
<li>
<strong>Opt-In Dependencies:</strong>
Islands use
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:depends="prop1,prop2"</code
>
to specify which shared properties they need
</li>
<li>
<strong>Automatic Updates:</strong> When
shared state changes, only islands that
depend on that property are re-rendered
</li>
<li>
<strong>Multiple Dependencies:</strong>
Islands can depend on multiple shared
properties separated by commas
</li>
</ul>
<div
class="bg-blue-50 border border-blue-200 rounded-lg p-4 mb-4"
>
<p class="text-sm text-blue-800">
<strong>Use Cases:</strong> Perfect for
shopping carts, user notifications, queue
dashboards, or any data that needs to stay
synchronized across different components on
same page.
</p>
</div>
<div
class="bg-blue-50 border border-blue-200 rounded-lg p-4 mb-4"
>
<p class="text-sm text-blue-800">
<strong>Use Case:</strong> Perfect for
shopping carts, user notifications, or any
data that needs to stay synchronized across
different components on the same page.
</p>
</div>
</section>
<!-- Frontend Directives -->
<section id="directives" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">
Frontend Directives
</h2>
<p class="text-gray-600 mb-6">
ForgeWire uses HTML attributes (directives) to
bind your UI to your controller.
</p>
<h3 class="text-lg font-semibold mb-3">
Binding Data: fw:model
</h3>
<ul
class="list-disc list-inside space-y-2 text-gray-600 mb-4"
>
<li>
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:model="name"</code
>
- Immediate binding (updates on every
keystroke)
</li>
<li>
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:model.debounce="name"</code
>
- Updates after 600ms of inactivity
</li>
<li>
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:model.defer="name"</code
>
- Updates only when an action is triggered
</li>
</ul>
<h3 class="text-lg font-semibold mb-3">
Handling Events
</h3>
<ul
class="list-disc list-inside space-y-2 text-gray-600 mb-4"
>
<li>
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:click="save"</code
>
- Call action on click
</li>
<li>
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:submit="create"</code
>
- Call action on form submit (auto-prevents
refresh)
</li>
<li>
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:keydown.enter="search"</code
>
- Call action on Enter key
</li>
</ul>
<h3 class="text-lg font-semibold mb-3">
Passing Arguments: fw:param-*
</h3>
<p class="text-gray-600 mb-4">
To pass data to an action, use the
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:param-</code
>
prefix.
</p>
<div
class="code-block p-6 text-white rounded-lg mb-6"
>
<pre><code class="language-html"><!-- Controller: public function delete(int $id) -->
<button fw:click="delete" fw:param-id="123">Delete Post</button></code></pre>
</div>
</section>
<!-- Security -->
<section id="security" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">
Security: The Sandbox
</h2>
<p class="text-gray-600 mb-4">
ForgeWire operates on a "deny-by-default"
principle:
</p>
<ul
class="list-disc list-inside space-y-2 text-gray-600 mb-4"
>
<li>
<strong>Checksum signing:</strong> All state
sent to the browser is HMAC-signed with your
<code class="bg-gray-100 px-2 py-1 rounded"
>APP_KEY</code
>. If a user modifies the state in the
console, the server rejects the request.
</li>
<li>
<strong>Method Whitelisting:</strong> Only
<code class="bg-gray-100 px-2 py-1 rounded"
>#[Action]</code
>
methods can be invoked. Even
protected/private methods are strictly
blocked.
</li>
<li>
<strong>Fingerprinting:</strong> ForgeWire
tracks the controller class and current URL
path to prevent "component injection" or
cross-page state reuse.
</li>
</ul>
</section>
<section id="actions" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">
Actions & Methods
</h2>
<h3 class="text-lg font-semibold mb-3">
The #[Action] Attribute
</h3>
<p class="text-gray-600 mb-4">
Applied to methods. Marks the method as "safe"
to be called from the browser. ForgeWire will
refuse to call any method not explicitly marked
as an action.
</p>
<p class="text-gray-600 mb-4">
The
<code class="bg-gray-100 px-2 py-1 rounded"
>input()</code
>
action is built-in and handles
<code>fw:model</code> updates:
</p>
<div
class="code-block p-6 text-white rounded-lg mb-6"
>
<pre><code class="language-php">// Automatically called for fw:model
#[Action]
public function input(...$keys): void
{
// Called when fw:model values change
// $keys contains which properties changed
}</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3">
Calling Actions from Frontend
</h3>
<div
class="code-block p-6 text-white rounded-lg mb-6"
>
<pre><code class="language-html"><!-- fw:click -->
<button fw:click="increment">+</button>
<button fw:click="update" fw:param-id="5" fw:param-name="New Name">Update</button>
<!-- fw:submit -->
<form fw:submit="save">
<input fw:model="name" type="text">
<button type="submit">Save</button>
</form></code></pre>
</div>
</section>
<!-- Validation -->
<section id="validation" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">
Validation
</h2>
<p class="text-gray-600 mb-6">
Add validation rules to properties using
#[Validate] attribute. Validation supports both
array and JSON message formats for backward
compatibility.
</p>
<div
class="code-block p-6 text-white rounded-lg mb-6"
>
<pre><code class="language-php">#[State]
#[Validate('required|min:3', messages: ['required' => 'Name is required', 'min' => 'Name must be at least :value characters'])]
public string $formName = '';
#[State]
#[Validate('required|email', messages: ['required' => 'Email is required', 'email' => 'Please enter a valid email address'])]
public string $formEmail = '';</code></pre>
</div>
<h3 class="text-lg font-semibold mb-3">
Validation Features
</h3>
<ul
class="list-disc list-inside space-y-2 text-gray-600 mb-4"
>
<li>
<strong>Automatic Validation:</strong> Runs
when properties marked with #[Validate] are
updated
</li>
<li>
<strong>Custom Messages:</strong> Provide
user-friendly error messages for each rule
</li>
<li>
<strong>Parameter Replacement:</strong> Use
<code class="bg-gray-100 px-2 py-1 rounded"
>:value</code
>
placeholders in messages
</li>
<li>
<strong>Form Submission:</strong> Use
<code class="bg-gray-100 px-2 py-1 rounded"
>#[Action(submit: true)]</code
>
for form handling
</li>
</ul>
<p class="text-gray-600 mb-4">
Validation runs automatically when dirty state
includes the property.
</p>
</section>
<section id="frontend" class="section-anchor mb-12">
<h2 class="text-2xl font-bold text-gray-900 mb-4">
Frontend Integration
</h2>
<p class="text-gray-600 mb-6">
ForgeWire's JavaScript client handles all
frontend interactions automatically.
</p>
<h3 class="text-lg font-semibold mb-3">
Directives Reference
</h3>
<h4 class="text-md font-semibold mb-2">
Event Handling
</h4>
<ul
class="list-disc list-inside space-y-2 text-gray-600 mb-4"
>
<li>
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:click="save"</code
>
— Call action on click (use
<code>fw:param-*</code> for arguments)
</li>
<li>
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:submit="save"</code
>
— Form submission (auto-prevents refresh)
</li>
<li>
<code class="bg-gray-100 px-2 py-1 rounded"
>fw:keydown.enter="submit"</code